aboutsummaryrefslogtreecommitdiffstats
path: root/layerindex/update.py
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2017-05-16 00:15:16 -0700
committerPaul Eggleton <paul.eggleton@linux.intel.com>2017-07-21 08:14:34 +0200
commit2735d9590a0b84addc044013e2f51d3feac210d5 (patch)
tree3f38584478eedf9fd4c6c6dcc17fe1901e200024 /layerindex/update.py
parentb958a991caa947fde2ccb073e3cb7924e162562d (diff)
downloadopenembedded-core-contrib-2735d9590a0b84addc044013e2f51d3feac210d5.tar.gz
openembedded-core-contrib-2735d9590a0b84addc044013e2f51d3feac210d5.tar.bz2
openembedded-core-contrib-2735d9590a0b84addc044013e2f51d3feac210d5.zip
update.py: update actual branch for layer and bitbake
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 frequently. We only can update them via website without this patch, which is not fun and easy to make mistakes. * It works with "-l", and "-l bitbake" means update bitbake branch. * It requires "-b" to work, and only one branch is supported in a run. For example: $ update.py -b master -a branch_20170526 All the layers which have branch master and actual_branch branch_20170526 will be updated to branch_20170526. $ update.py -b master -l meta-oe -a branch_20170526 Only meta-oe layer will be updated. $ update.py -b master -l bitbake -a branch_20170526 The bitbake's bitbake_branch will be updated. Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'layerindex/update.py')
-rwxr-xr-xlayerindex/update.py71
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