[yocto] [layerindex-web] [PATCH] update.py: update actual branch for layer and bitbake

Robert Yang liezhi.yang at windriver.com
Tue May 16 00:26:51 PDT 2017


Add an option "-a" to update actual branch for layer and bitbake, it is
useful when there are many layers and need update actual branches
frequantly. We only can update them via website without this patch,
which is not funny and easy to make mistakes.

Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
---
 layerindex/update.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/layerindex/update.py b/layerindex/update.py
index d5c56cd..aa2fb38 100755
--- a/layerindex/update.py
+++ b/layerindex/update.py
@@ -85,6 +85,51 @@ def prepare_update_layer_command(options, branch, layer, updatedeps=False):
         cmd += ' -q'
     return cmd
 
+def get_actual_branch_format():
+    return "<layer_name>:<branch>:<actual_branch>"
+
+def update_actual_branches(options):
+    """Update actual branch for layers and bitbake in database"""
+    to_save = set()
+    for opt in options.actual_branches.split(','):
+        opt_list = opt.split(':')
+        if len(opt_list) != 3:
+            logger.error("Bad format: %s, use %s" % (opt, get_actual_branch_format()))
+            sys.exit(1)
+        layer_name = opt_list[0]
+        branch = opt_list[1]
+        actual_branch_new = opt_list[2]
+        if not (layer_name and branch and actual_branch_new):
+            logger.error("Bad format: %s, one of %s is null" % (opt, get_actual_branch_new_format()))
+            sys.exit(1)
+
+        if layer_name == 'bitbake':
+            branchobj = utils.get_branch(branch)
+            if actual_branch_new != branchobj.bitbake_branch:
+                logger.info("bitbake: %s.bitbake_branch: %s -> %s" % (branch, branchobj.bitbake_branch, actual_branch_new))
+                branchobj.bitbake_branch = actual_branch_new
+                to_save.add(branchobj)
+            else:
+                logger.warn("bitbake: %s.bitbake_branch is already %s, so no change" % (branch, actual_branch_new))
+        else:
+            layer = utils.get_layer(layer_name)
+            if not layer:
+                logger.error("Layer name '%s' not found in database" % layer_name)
+                sys.exit(1)
+            layerbranch = layer.get_layerbranch(branch)
+            if not layerbranch:
+                logger.error("Branch '%s' not found in database" % branch)
+                sys.exit(1)
+            if actual_branch_new != layerbranch.actual_branch:
+                logger.info("%s: %s.actual_branch: %s -> %s" % (layer_name, branch, layerbranch.actual_branch, actual_branch_new))
+                layerbranch.actual_branch = actual_branch_new
+                to_save.add(layerbranch)
+            else:
+                logger.warn("%s: %s.actual_branch is already %s, so no change" % (layer_name, branch, actual_branch_new))
+
+        # At last, do the save
+        for s in to_save:
+            s.save()
 
 def main():
     if LooseVersion(git.__version__) < '0.3.1':
@@ -102,6 +147,11 @@ def main():
     parser.add_option("-l", "--layer",
             help = "Specify layers to update (use commas to separate multiple). Default is all published layers.",
             action="store", dest="layers")
+    parser.add_option("-a", "--actual-branch",
+            help = "Update actual branch for layer and bitbake, \
+                    the format is: %s (use commas to separate multiple), \
+                    use 'bitbake' as <layer_name> to update bitbake branch" % get_actual_branch_format(),
+            action="store", dest="actual_branches", default='')
     parser.add_option("-r", "--reload",
             help = "Reload recipe data instead of updating since last update",
             action="store_true", dest="reload")
@@ -187,6 +237,10 @@ def main():
             logger.error("Layer index lock timeout expired")
             sys.exit(1)
         try:
+            if options.actual_branches:
+                update_actual_branches(options)
+                return
+
             bitbakepath = os.path.join(fetchdir, 'bitbake')
 
             if not options.nofetch:
-- 
2.10.2




More information about the yocto mailing list