X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=t%2Fid-other-than;h=9c240fa96fc6db9cde734263e5411c7969ac69f2;hb=ea0cb087050dc86bae886c0b2605b83aa819b7d3;hp=25e7fbf5e90f17d5eaeffd95c172636d812842f6;hpb=b836113e503ab3f8e3c30c3283eb59f936fb0023;p=bup.git diff --git a/t/id-other-than b/t/id-other-than index 25e7fbf..9c240fa 100755 --- a/t/id-other-than +++ b/t/id-other-than @@ -1,11 +1,22 @@ -#!/usr/bin/env python +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/../cmd/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble + +# Note: this currently relies on bup-python to handle arbitrary binary +# user/group names. + +from __future__ import absolute_import, print_function import grp import pwd import sys def usage(): - print >> sys.stderr, "Usage: id-other-than ID [ID ...]" + print('Usage: id-other-than <--user|--group> ID [ID ...]', + file=sys.stderr) if len(sys.argv) < 2: usage() @@ -15,21 +26,25 @@ def is_integer(x): try: int(x) return True - except ValueError, e: + except ValueError as e: return False -excluded_ids = frozenset(int(x) for x in sys.argv[2:] if is_integer(x)) -excluded_names = frozenset(x for x in sys.argv[2:] if not is_integer(x)) +excluded_ids = set(int(x) for x in sys.argv[2:] if is_integer(x)) +excluded_names = (x for x in sys.argv[2:] if not is_integer(x)) if sys.argv[1] == '--user': + for x in excluded_names: + excluded_ids.add(pwd.getpwnam(x).pw_uid) for x in pwd.getpwall(): - if x.pw_name not in excluded_names and x.pw_uid not in excluded_ids: - print x.pw_name + ':' + str(x.pw_uid) + if x.pw_uid not in excluded_ids: + print(x.pw_name + ':' + str(x.pw_uid)) sys.exit(0) elif sys.argv[1] == '--group': + for x in excluded_names: + excluded_ids.add(grp.getgrnam(x).gr_gid) for x in grp.getgrall(): - if x.gr_name not in excluded_names and x.gr_gid not in excluded_ids: - print x.gr_name + ':' + str(x.gr_gid) + if x.gr_gid not in excluded_ids: + print(x.gr_name + ':' + str(x.gr_gid)) sys.exit(0) else: usage()