Re: [yocto] [layerindex-web][PATCH 06/10] layerindex/tools/import_project: Add import_project

2016-10-03 Thread Paul Eggleton
On Mon, 26 Sep 2016 14:25:34 Liam R. Howlett wrote:
> import_project will scan through a project and find any layer and add it
> to the database by calling import_layer on each layer.  This differs
> from import_layer as it tires to figure out the remote url and uses the
> subdirectory (if one exists) as the name.

Looks good, but the two dryrun blocks have incorrect indenting.

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre
-- 
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


[yocto] [layerindex-web][PATCH 06/10] layerindex/tools/import_project: Add import_project

2016-09-26 Thread Liam R. Howlett
import_project will scan through a project and find any layer and add it
to the database by calling import_layer on each layer.  This differs
from import_layer as it tires to figure out the remote url and uses the
subdirectory (if one exists) as the name.

Signed-off-by: Liam R. Howlett 
---
 layerindex/tools/import_layer.py   |   7 ++
 layerindex/tools/import_project.py | 176 +
 2 files changed, 183 insertions(+)
 create mode 100755 layerindex/tools/import_project.py

diff --git a/layerindex/tools/import_layer.py b/layerindex/tools/import_layer.py
index 21b31f5..f84fd85 100755
--- a/layerindex/tools/import_layer.py
+++ b/layerindex/tools/import_layer.py
@@ -360,6 +360,13 @@ def main():
 layerbranch = LayerBranch()
 layerbranch.layer = layer
 layerbranch.branch = master_branch
+layerbranch.save()
+
+if layer.name != settings.CORE_LAYER_NAME:
+layerconfparser = LayerConfParse(logger=logger)
+config_data = layerconfparser.parse_layer(layerdir)
+layerconfparser.shutdown()
+utils.set_layerbranch_collection_version(layerbranch, 
config_data, logger=logger)
 if layerdir != repodir:
 layerbranch.vcs_subdir = subdir
 if actual_branch:
diff --git a/layerindex/tools/import_project.py 
b/layerindex/tools/import_project.py
new file mode 100755
index 000..0b91c08
--- /dev/null
+++ b/layerindex/tools/import_project.py
@@ -0,0 +1,176 @@
+#!/usr/bin/python3
+
+# Import a project into the database.
+#  This will scan through the directories in a project and find any layer and
+#  call import_layer.
+#
+#
+# Copyright (C) 2016 Wind River Systems
+# Author: Liam R. Howlett 
+#
+# Licensed under the MIT license, see COPYING.MIT for details
+
+from git import Repo
+from urllib.parse import urlparse
+import logging
+import optparse
+import os, fnmatch
+import sys
+
+sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
'..')))
+
+import import_layer
+import update
+
+import utils
+
+
+
+
+class ImportProject:
+logger = utils.logger_create('ProjectIndexImport')
+
+def find_layers(self, path):
+self.logger.debug("finding layer..");
+result = []
+for root, dirs, files in os.walk(path, followlinks=True):
+for name in fnmatch.filter(files, 'layer.conf'):
+if not root.endswith('conf'):
+continue
+
+self.logger.debug("Found %s" % root)
+result.append(root)
+return result
+
+
+def main(self):
+parser = optparse.OptionParser(
+usage = """
+%prog [options] [directory]""")
+
+parser.add_option("-d", "--debug",
+help = "Enable debug output",
+action="store_const", const=logging.DEBUG, dest="loglevel", 
default=logging.INFO)
+parser.add_option("-n", "--dry-run",
+help = "Don't write any data back to the database",
+action="store_true", dest="dryrun")
+
+self.options, args = parser.parse_args(sys.argv)
+
+self.logger.setLevel(self.options.loglevel)
+
+if len(args) == 1:
+print("Please provide a directory.");
+sys.exit(1)
+
+install_dir = args[1]
+lc_list = self.find_layers(install_dir)
+self.add_core(lc_list)
+
+for layer in lc_list:
+self.add_layer(layer)
+
+def add_layer(self, layer):
+self.logger.debug("Processing layer %s" % layer);
+try:
+git_dir = utils.runcmd("git rev-parse --show-toplevel", 
destdir=layer, logger=self.logger)
+except Exception as e:
+self.logger.error("Cannot get root dir for layer %s: %s - 
Skipping." % (layer, str(e)))
+return 1
+
+self.logger.error("git_dir = %s" % git_dir);
+repo = Repo(git_dir)
+actual_branch = repo.active_branch.name
+
+
+layer_name = layer.split('/')[-2]
+
+layer_subdir = None
+if os.path.basename(git_dir) != layer_name:
+layer_subdir = layer_name
+
+layer_name = self.get_layer_name(layer)
+
+for i in [1, 2, 3]:
+try:
+git_url = utils.runcmd("git config --get remote.origin.url", 
destdir=git_dir, logger=self.logger)
+except Exception as e:
+self.logger.info("Cannot get remote.origin.url for git dir %s: 
%s" % (git_dir, str(e)))
+
+if not os.path.exists(git_url):
+# Assume this is remote.
+self.logger.debug("Found git url = %s" % git_url)
+break;
+self.logger.debug("Iterating to find git url into %s" % git_dir)
+git_dir = git_url
+
+cmd =