summaryrefslogtreecommitdiffstats
path: root/bin/review-update-needed
diff options
context:
space:
mode:
authorAntoine Beaupré <anarcat@debian.org>2018-11-09 14:03:22 -0500
committerAntoine Beaupré <anarcat@debian.org>2018-11-09 14:03:51 -0500
commite53d0cf9e3829ac398951bebf28b3894ca14ab3d (patch)
tree4061a8a49b6922658b337d6b7cada27ae03f03b7 /bin/review-update-needed
parentefc5441249ddb58c7ead56e9b87817ab7d31f74f (diff)
add --unclaim to remove claimed entries inactive for N seconds
Diffstat (limited to 'bin/review-update-needed')
-rwxr-xr-xbin/review-update-needed31
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]))

© 2014-2024 Faster IT GmbH | imprint | privacy policy