-
Notifications
You must be signed in to change notification settings - Fork 158
Script to remove version not matching periods #2516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
knopers8
merged 2 commits into
AliceO2Group:master
from
Barthelemy:repo-delete-versions-not-in-periods
Mar 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
Framework/script/RepoCleaner/qcrepocleaner/o2-qc-repo-delete-versions-not-in-periods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/usr/bin/env python3 | ||
| from collections import defaultdict | ||
| import logging | ||
| import argparse | ||
|
|
||
| from qcrepocleaner import binUtils | ||
| from qcrepocleaner.Ccdb import Ccdb | ||
| import dryable | ||
|
|
||
| def parse_args(): | ||
| """Parse the arguments passed to the script.""" | ||
| logging.info("Parsing arguments") | ||
| parser = argparse.ArgumentParser(description='Remove all the versions in the given path that don\'t match the given list of periodNames ') | ||
| parser.add_argument('--url', dest='url', action='store', help='URL of the CCDB, with http[s]://', required=True) | ||
| parser.add_argument('--log-level', dest='log_level', action='store', default="20", | ||
| help='Log level (CRITICAL->50, ERROR->40, WARNING->30, INFO->20,DEBUG->10)') | ||
| parser.add_argument('--dry-run', action='store_true', | ||
| help='Dry run, no actual deletion nor modification to the CCDB.') | ||
| parser.add_argument('--path', dest='path', action='store', default="", | ||
| help='The path to work with (without initial slash and without .* at the end, e.g. qc/TST/MO/Bob).', required=True) | ||
| parser.add_argument('--one-by-one', action='store_true', help='Ask confirmation for each deletion') | ||
| parser.add_argument('--yes', action='store_true', help='Answers yes to all. You should really not use that.') | ||
| parser.add_argument('--periods-list', dest='periods_list', action='store', default="", | ||
| help='The list of periods that will be spared, comma separated, no space.', required=True) | ||
|
|
||
| args = parser.parse_args() | ||
| dryable.set(args.dry_run) | ||
| logging.info(args) | ||
| return args | ||
|
|
||
|
|
||
| def run(args): | ||
| ccdb = Ccdb(args.url) | ||
| ccdb.logger = logging.getLogger | ||
| global_deleted = 0 | ||
| global_skipped = 0 | ||
| global_spared = 0 | ||
| global_spared_dict = defaultdict(int) | ||
| periods_list = args.periods_list.split(',') | ||
|
|
||
| # retrieve all the objects | ||
| path = args.path + ".*" | ||
| objects = ccdb.getFullObjectsDetails(path=path) | ||
| logging.debug(f"objects: {objects}") | ||
|
|
||
| for o in objects: | ||
| deleted = 0 | ||
| skipped = 0 | ||
| spared = 0 | ||
| spared_dict = defaultdict(int) | ||
| logging.info(f"object: {o}") | ||
| # Retrieve the list of versions for this object | ||
| versions = ccdb.getVersionsList(o['path']) | ||
| logging.info(f" Number of versions: {len(versions)} - {periods_list}") | ||
| for v in versions: | ||
| if "PeriodName" not in v.metadata: | ||
| ccdb.deleteVersion(v) | ||
| deleted += 1 | ||
| # logging.debug(f"{v} -> {v.metadata['PeriodName']}") | ||
| elif v.metadata["PeriodName"] not in periods_list: | ||
| # logging.info(f"Ready to delete {v}") | ||
| if args.one_by_one: | ||
| answer = input(" Continue? y/n\n ") | ||
| if answer.lower() in ["y", "yes"]: | ||
| ccdb.deleteVersion(v) | ||
| deleted += 1 | ||
| elif answer.lower() in ["n", "no"]: | ||
| logging.info(" skipping") | ||
| skipped += 1 | ||
| else: | ||
| logging.error(" wrong input, skipping") | ||
| skipped += 1 | ||
| else: | ||
| ccdb.deleteVersion(v) | ||
| deleted += 1 | ||
| else: | ||
| logging.debug(f"Not deleting {v} as it is in the periods list") | ||
| spared += 1 | ||
| spared_dict[v.metadata["PeriodName"]] += 1 | ||
|
|
||
| logging.info(f"Number of deleted: {deleted}") | ||
| logging.info(f"Number of spared: {spared}") | ||
| logging.info(f"Number of skipped: {skipped}") | ||
| logging.info(f"Spared : {spared_dict}") | ||
| global_deleted += deleted | ||
| global_skipped += skipped | ||
| global_spared += spared | ||
| global_spared_dict = defaultdict(int, {key: spared_dict.get(key, 0) + global_spared_dict.get(key, 0) for key in | ||
| set(spared_dict) | set(global_spared_dict)}) | ||
|
|
||
| logging.info(f"Global results : ") | ||
| logging.info(f" Number of deleted: {global_deleted}") | ||
| logging.info(f" Number of spared: {global_spared}") | ||
| logging.info(f" Number of skipped: {global_skipped}") | ||
| logging.info(f" Spared : {global_spared_dict}") | ||
|
|
||
| # **************** | ||
| # We start here ! | ||
| # **************** | ||
|
|
||
| def main(): | ||
| binUtils.prepare_main_logger() | ||
|
|
||
| # Parse arguments | ||
| args = parse_args() | ||
| logging.getLogger().setLevel(int(args.log_level)) | ||
|
|
||
| run(args) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.