From d8011bc30589f77a023eae8bc3c44a2a121d5dee Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Tue, 20 Aug 2019 10:28:23 +1200 Subject: [PATCH] rrs_upgrade_history: implement file path filtering Make it possible to re-collect all the history for a given path. (Typically this would only be used for debugging, as it saves time if you are trying to correct an issue with upgrade data collection for a single recipe.) Signed-off-by: Paul Eggleton --- rrs/tools/rrs_upgrade_history.py | 21 +++++++++++++++++++-- rrs/tools/upgrade_history_internal.py | 10 +++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/rrs/tools/rrs_upgrade_history.py b/rrs/tools/rrs_upgrade_history.py index 2c228dd..b154443 100755 --- a/rrs/tools/rrs_upgrade_history.py +++ b/rrs/tools/rrs_upgrade_history.py @@ -71,6 +71,8 @@ def run_internal(maintplanlayerbranch, commit, commitdate, options, logger, bitb cmd += ' --initial="%s"' % comment if bitbake_rev: cmd += ' --bitbake-rev %s' % bitbake_rev + if options.filter_files: + cmd += ' --filter-files %s' % options.filter_files if options.dry_run: cmd += ' --dry-run' if options.loglevel == logging.DEBUG: @@ -131,7 +133,11 @@ def upgrade_history(options, logger): for maintplanbranch in maintplan.maintenanceplanlayerbranch_set.all(): layerbranch = maintplanbranch.layerbranch if options.fullreload and not options.dry_run: - RecipeUpgrade.objects.filter(recipesymbol__layerbranch=layerbranch).delete() + logger.debug('fullreload: deleting upgrade objects') + if options.filter_files: + RecipeUpgrade.objects.filter(recipesymbol__layerbranch=layerbranch, filepath__startswith=options.filter_files).delete() + else: + RecipeUpgrade.objects.filter(recipesymbol__layerbranch=layerbranch).delete() layer = layerbranch.layer urldir = layer.get_fetch_dir() repodir = os.path.join(fetchdir, urldir) @@ -195,6 +201,9 @@ def upgrade_history(options, logger): if layersubdir_start and not (diffitem.a_path.startswith(layersubdir_start) or diffitem.b_path.startswith(layersubdir_start)): # Not in this layer, skip it continue + if options.filter_files and not (diffitem.a_path.startswith(options.filter_files) or diffitem.b_path.startswith(options.filter_files)): + # Doesn't match path filter + continue if diffitem.a_path.endswith(('.bb', '.inc')) or diffitem.b_path.endswith(('.bb', '.inc')): # We need to look at this commit touches_recipe = True @@ -211,7 +220,7 @@ def upgrade_history(options, logger): continue logger.debug("Analysing commit %s ..." % ct) run_internal(maintplanbranch, ct, ctdate, options, logger, bitbake_map) - if not options.dry_run: + if not (options.dry_run or options.filter_files): maintplanbranch.upgrade_rev = ct maintplanbranch.upgrade_date = ctdate maintplanbranch.save() @@ -247,6 +256,10 @@ if __name__=="__main__": help="Specify maintenance plan to operate on (default is all plans that have updates enabled)", action="store", dest="plan", default=None) + parser.add_option("-F", "--filter-files", + help="Only operate on a specified subset of files (filepath 'startswith')", + action="store", dest="filter_files", default='') + parser.add_option("--regroup", help="Re-group records only", action="store_true", dest="regroup", default=False) @@ -254,4 +267,8 @@ if __name__=="__main__": options, args = parser.parse_args(sys.argv) logger.setLevel(options.loglevel) + if options.filter_files and not options.plan: + logger.error('-F/--filter-files must be specified in conjunction with -p/--plan and --fullreload') + sys.exit(1) + upgrade_history(options, logger) diff --git a/rrs/tools/upgrade_history_internal.py b/rrs/tools/upgrade_history_internal.py index 33cf656..e1198a7 100644 --- a/rrs/tools/upgrade_history_internal.py +++ b/rrs/tools/upgrade_history_internal.py @@ -349,7 +349,11 @@ def generate_history(options, layerbranch_id, commit, logger): deleted = [] moved = [] else: - fns, deleted, moved = _get_recipes_filenames(commit, repo, repodir, layersubdir_start, logger) + if options.filter_files: + filepath_start = options.filter_files + else: + filepath_start = layersubdir_start + fns, deleted, moved = _get_recipes_filenames(commit, repo, repodir, filepath_start, logger) if not (fns or deleted or moved): return @@ -501,6 +505,10 @@ if __name__=="__main__": help = "Do not write any data back to the database", action="store_true", dest="dry_run", default=False) + parser.add_option("-F", "--filter-files", + help="Only operate on a specified subset of files (wildcards allowed)", + action="store", dest="filter_files", default='') + options, args = parser.parse_args(sys.argv) logger.setLevel(options.loglevel)