[Git][security-tracker-team/security-tracker][master] 7 commits: fix usage help for --verbose flag, obvious copy-paste error
Salvatore Bonaccorso
carnil at debian.org
Sat Nov 10 20:10:00 GMT 2018
Salvatore Bonaccorso pushed to branch master at Debian Security Tracker / security-tracker
Commits:
ae090960 by Antoine Beaupré at 2018-11-09T18:02:50Z
fix usage help for --verbose flag, obvious copy-paste error
- - - - -
ae15f04c by Antoine Beaupré at 2018-11-09T18:12:18Z
more pythonic args checking
- - - - -
a9f0666d by Antoine Beaupré at 2018-11-09T18:13:38Z
add --quiet argument to allow running as a cronjob
- - - - -
0543551f by Antoine Beaupré at 2018-11-09T19:03:51Z
add --unclaim to remove claimed entries inactive for N seconds
- - - - -
1ac9ca91 by Antoine Beaupré at 2018-11-09T19:04:31Z
allow for human-friendly date ranges as well
- - - - -
7fa575e8 by Antoine Beaupré at 2018-11-09T20:20:00Z
add default value for unclaim parameter
- - - - -
ba81c126 by Salvatore Bonaccorso at 2018-11-10T20:09:33Z
Merge branch 'anarcat/security-tracker-unclaim'
- - - - -
1 changed file:
- bin/review-update-needed
Changes:
=====================================
bin/review-update-needed
=====================================
@@ -2,12 +2,17 @@
import argparse
import collections
-from datetime import datetime
+from datetime import datetime, timedelta
import os
import re
import subprocess
import sys
+try:
+ import humanfriendly
+except ImportError:
+ humanfriendly = None
+
def format_date(timestamp):
date_to_format = datetime.utcfromtimestamp(timestamp)
delta = datetime.utcnow() - date_to_format
@@ -24,29 +29,41 @@ parser = argparse.ArgumentParser(description="Review DSA/DLA needed queues")
parser.add_argument('--lts', action='store_true',
help='Review dla-needed.txt instead of dsa-needed.txt')
parser.add_argument('-v', '--verbose', action='store_true',
- help='Review dla-needed.txt instead of dsa-needed.txt')
+ help='Show more information, e.g. notes, commit author and per user stats')
+parser.add_argument('--quiet', action='store_true',
+ help='Do not output anything but errors')
parser.add_argument('--sort-by', default='last-update',
+ choices=('last-update', 'claimed-date'),
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')
+if humanfriendly:
+ parser.add_argument('--unclaim', default=None, metavar='N',
+ nargs='?', const='1w',
+ help='Automatically unclaim entries older than specified delta (default: %(default)s)')
+else:
+ parser.add_argument('--unclaim', default=None, metavar='N', type=int,
+ nargs='?', const=604800,
+ help='Automatically unclaim entries older than N seconds (default: %(default)s)')
args = parser.parse_args()
+if args.verbose and args.quiet:
+ args.error("--verbose and --quiet contradiction")
+
+if humanfriendly:
+ unclaim_delta = timedelta(seconds=humanfriendly.parse_timespan(args.unclaim))
+else:
+ unclaim_delta = timedelta(seconds=args.unclaim)
if args.lts:
dsa_dla_needed = 'data/dla-needed.txt'
else:
dsa_dla_needed = 'data/dsa-needed.txt'
-if args.sort_by not in ('last-update', 'claimed-date'):
- sys.stderr.write('ERROR: usage: --sort-by={last-update,claimed-date}\n')
- sys.exit(1)
-
if not os.path.exists(dsa_dla_needed):
- sys.stderr.write("ERROR: {} not found\n".format(dsa_dla_needed))
- sys.exit(1)
+ args.error("ERROR: {} not found\n".format(dsa_dla_needed))
if not os.path.exists(".git"):
- sys.stderr.write("ERROR: works only in a git checkout\n")
- sys.exit(1)
+ args.error("ERROR: works only in a git checkout\n")
process = subprocess.Popen(["git", "blame", "--line-porcelain", "--",
dsa_dla_needed], stdout=subprocess.PIPE)
@@ -102,19 +119,25 @@ 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
- print("Package: {}".format(entry['pkg']))
+ args.quiet or print("Package: {}".format(entry['pkg']))
if entry['claimed-by']:
- print("Claimed-By: {}".format(entry['claimed-by']))
- print("Claimed-Date: {}".format(format_date(entry['claimed-date'])))
+ 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:
- print("Unclaimed-Since: {}".format(format_date(entry['claimed-date'])))
+ args.quiet or print("Unclaimed-Since: {}".format(format_date(entry['claimed-date'])))
if entry['last-update'] > entry['claimed-date']:
- print("Last-Update: {}".format(format_date(entry['last-update'])))
+ args.quiet or print("Last-Update: {}".format(format_date(entry['last-update'])))
if not args.verbose:
- print("")
+ args.quiet or print("")
continue
print("Last-Update-Author: {}".format(entry['last-update-author']))
print("Last-Update-Summary: {}".format(entry['last-update-summary']))
@@ -124,6 +147,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]))
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/5b0e536cdf279862a96693e708cbfbb838a8f56d...ba81c126669ac63d3ae048531298bcd560a4dad8
--
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/5b0e536cdf279862a96693e708cbfbb838a8f56d...ba81c126669ac63d3ae048531298bcd560a4dad8
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-security-tracker-commits/attachments/20181110/6b0036f8/attachment-0001.html>
More information about the debian-security-tracker-commits
mailing list