diff options
Diffstat (limited to 'layerindex/update.py')
-rwxr-xr-x | layerindex/update.py | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/layerindex/update.py b/layerindex/update.py index d5c56cd266..1a0bbd0c62 100755 --- a/layerindex/update.py +++ b/layerindex/update.py @@ -85,6 +85,43 @@ def prepare_update_layer_command(options, branch, layer, updatedeps=False): cmd += ' -q' return cmd +def update_actual_branch(layerquery, fetchdir, branch, options, update_bitbake, bitbakepath): + """Update actual branch for layers and bitbake in database""" + to_save = set() + actual_branch = options.actual_branch + if update_bitbake: + branchobj = utils.get_branch(branch) + if actual_branch != branchobj.bitbake_branch: + if utils.is_branch_valid(bitbakepath, actual_branch): + logger.info("bitbake: %s.bitbake_branch: %s -> %s" % (branch, branchobj.bitbake_branch, actual_branch)) + branchobj.bitbake_branch = actual_branch + to_save.add(branchobj) + else: + logger.info("Skipping update bitbake_branch for bitbake - branch %s doesn't exist" % actual_branch) + else: + logger.info("bitbake: %s.bitbake_branch is already %s, so no change" % (branch, actual_branch)) + + for layer in layerquery: + urldir = layer.get_fetch_dir() + repodir = os.path.join(fetchdir, urldir) + if not utils.is_branch_valid(repodir, actual_branch): + logger.info("Skipping update actual_branch for %s - branch %s doesn't exist" % (layer.name, actual_branch)) + continue + layerbranch = layer.get_layerbranch(branch) + if not layerbranch: + logger.info("Skipping update actual_branch for %s - layerbranch %s doesn't exist" % (layer.name, branch)) + continue + if actual_branch != layerbranch.actual_branch: + logger.info("%s: %s.actual_branch: %s -> %s" % (layer.name, branch, layerbranch.actual_branch, actual_branch)) + layerbranch.actual_branch = actual_branch + to_save.add(layerbranch) + else: + logger.info("%s: %s.actual_branch is already %s, so no change" % (layer.name, branch, actual_branch)) + + # At last, do the save + if not options.dryrun: + for s in to_save: + s.save() def main(): if LooseVersion(git.__version__) < '0.3.1': @@ -117,6 +154,9 @@ def main(): parser.add_option("", "--nocheckout", help = "Don't check out branches", action="store_true", dest="nocheckout") + parser.add_option("-a", "--actual-branch", + help = "Update actual branch for layer and bitbake", + action="store", dest="actual_branch", default='') parser.add_option("-d", "--debug", help = "Enable debug output", action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO) @@ -151,17 +191,34 @@ def main(): logger.error("Please set LAYER_FETCH_DIR in settings.py") sys.exit(1) + # For -a option to update bitbake branch + update_bitbake = False if options.layers: - layerquery = LayerItem.objects.filter(classic=False).filter(name__in=options.layers.split(',')) - if layerquery.count() == 0: - logger.error('No layers matching specified query "%s"' % options.layers) - sys.exit(1) + layers = options.layers.split(',') + if 'bitbake' in layers: + update_bitbake = True + layers.remove('bitbake') + for layer in layers: + layerquery = LayerItem.objects.filter(classic=False).filter(name=layer) + if layerquery.count() == 0: + logger.error('No layers matching specified query "%s"' % layer) + sys.exit(1) + layerquery = LayerItem.objects.filter(classic=False).filter(name__in=layers) else: # We deliberately exclude status == 'X' ("no update") here layerquery = LayerItem.objects.filter(classic=False).filter(status='P') if layerquery.count() == 0: logger.info("No published layers to update") sys.exit(1) + update_bitbake = True + + if options.actual_branch: + if not options.branch: + logger.error("-a option requires -b") + sys.exit(1) + elif len(branches) != 1: + logger.error("Only one branch should be used with -a") + sys.exit(1) if not os.path.exists(fetchdir): os.makedirs(fetchdir) @@ -209,7 +266,7 @@ def main(): continue fetchedrepos.append(layer.vcs_url) - if not fetchedrepos: + if not (fetchedrepos or update_bitbake): logger.error("No repositories could be fetched, exiting") sys.exit(1) @@ -219,6 +276,10 @@ def main(): else: out = utils.runcmd("git fetch", bitbakepath, logger=logger) + if options.actual_branch: + update_actual_branch(layerquery, fetchdir, branches[0], options, update_bitbake, bitbakepath) + return + # Process and extract data from each layer # We now do this by calling out to a separate script; doing otherwise turned out to be # unreliable due to leaking memory (we're using bitbake internals in a manner in which |