diff options
author | Antoine Beaupré <anarcat@debian.org> | 2018-11-09 14:03:22 -0500 |
---|---|---|
committer | Antoine Beaupré <anarcat@debian.org> | 2018-11-09 14:03:51 -0500 |
commit | 0543551f714b166e7a8c2691c8c0a361fd910124 (patch) | |
tree | e56fea7c6fc132352ad68fe8f1cc32f4e3b6cad2 /bin/review-update-needed | |
parent | a9f0666d09eb7a7a599a68e5f877324cfc2a1863 (diff) |
add --unclaim to remove claimed entries inactive for N seconds
Diffstat (limited to 'bin/review-update-needed')
-rwxr-xr-x | bin/review-update-needed | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/bin/review-update-needed b/bin/review-update-needed index 0a20ba2fb5..13e6d4a4ba 100755 --- a/bin/review-update-needed +++ b/bin/review-update-needed @@ -2,7 +2,7 @@ import argparse import collections -from datetime import datetime +from datetime import datetime, timedelta import os import re import subprocess @@ -32,10 +32,14 @@ parser.add_argument('--sort-by', default='last-update', help='Sort by last-update (default) or by claimed-date') parser.add_argument('--skip-unclaimed', action='store_true', help='Skip unclaimed packages in the review') +parser.add_argument('--unclaim', default=None, metavar='N', type=int, + help='Automatically unclaim entries older than N seconds (default: no automatic unclaim)') args = parser.parse_args() if args.verbose and args.quiet: args.error("--verbose and --quiet contradiction") +unclaim_delta = timedelta(seconds=args.unclaim) + if args.lts: dsa_dla_needed = 'data/dla-needed.txt' else: @@ -101,6 +105,7 @@ if retcode != 0: all_entries.sort(key=lambda x: x[args.sort_by]) +unclaim_pkgs = [] for entry in all_entries: if args.skip_unclaimed and not entry['claimed-by']: continue @@ -108,6 +113,11 @@ for entry in all_entries: if entry['claimed-by']: args.quiet or print("Claimed-By: {}".format(entry['claimed-by'])) args.quiet or print("Claimed-Date: {}".format(format_date(entry['claimed-date']))) + + if args.unclaim: + date_to_format = datetime.utcfromtimestamp(entry['claimed-date']) + if datetime.utcnow() - date_to_format > unclaim_delta: + unclaim_pkgs.append(entry['pkg']) else: args.quiet or print("Unclaimed-Since: {}".format(format_date(entry['claimed-date']))) if entry['last-update'] > entry['claimed-date']: @@ -123,6 +133,25 @@ for entry in all_entries: else: print("") +if args.unclaim: + args.quiet or print("Packages to unclaim: {}".format(", ".join(unclaim_pkgs))) + in_preamble = True + with open(dsa_dla_needed) as orig, open(dsa_dla_needed + '.new', 'w') as new: + for line in orig: + if line.startswith('--'): + in_preamble = False + if in_preamble: + new.write(line) # do not touch preamble + else: + # look for packages to unclaim in this line + for pkg in unclaim_pkgs: + if line.startswith(pkg): + new.write(pkg + "\n") + break + else: # nothing found, write untouched line + new.write(line) + os.rename(dsa_dla_needed + '.new', dsa_dla_needed) + if args.verbose: # sort by number of claimed packages items = sorted(per_user.items(), key=lambda x: len(x[1])) |