From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 1C750138204 for ; Fri, 11 Oct 2013 10:33:17 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7F22FE0AD7; Fri, 11 Oct 2013 10:33:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 094FCE0AD7 for ; Fri, 11 Oct 2013 10:33:14 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1FFD533EF52 for ; Fri, 11 Oct 2013 10:33:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id A9809E5466 for ; Fri, 11 Oct 2013 10:33:11 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1381487437.345c54de9e8c9daac190fbb07d33bf40e7bac5a9.vapier@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/xattr-helper.py X-VCS-Directories: bin/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 345c54de9e8c9daac190fbb07d33bf40e7bac5a9 X-VCS-Branch: master Date: Fri, 11 Oct 2013 10:33:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: aaccf79c-6115-483b-a470-267c0fc68e64 X-Archives-Hash: 81b7c3322a9c6d94c4b175003ebfeb09 commit: 345c54de9e8c9daac190fbb07d33bf40e7bac5a9 Author: Mike Frysinger gentoo org> AuthorDate: Fri Oct 11 10:30:37 2013 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Oct 11 10:30:37 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=345c54de xattr-helper: clean up command line interface This uses the standard argparse fields rather than open coding things ourselves. It also makes it a bit easier to test as you can now pass paths on the command line in addition to stdin. --- bin/xattr-helper.py | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/bin/xattr-helper.py b/bin/xattr-helper.py index e84d23d..6d99521 100755 --- a/bin/xattr-helper.py +++ b/bin/xattr-helper.py @@ -103,16 +103,13 @@ def unquote(s): return b''.join(result) -def dump_xattrs(file_in, file_out): - """Dump the xattr data for files in |file_in| to |file_out|""" +def dump_xattrs(pathnames, file_out): + """Dump the xattr data for |pathnames| to |file_out|""" # NOTE: Always quote backslashes, in order to ensure that they are # not interpreted as quotes when they are processed by unquote. quote_chars = b'\n\r\\\\' - for pathname in file_in.read().split(b'\0'): - if not pathname: - continue - + for pathname in pathnames: attrs = xattr.list(pathname) if not attrs: continue @@ -147,14 +144,11 @@ def restore_xattrs(file_in): elif line.strip(): raise ValueError('line %d: malformed entry' % (i + 1,)) -def main(argv): - description = "Dump and restore extended attributes," \ - " using format like that used by getfattr --dump." - usage = "usage: %s [--dump | --restore]\n" % \ - os.path.basename(argv[0]) +def main(argv): - parser = ArgumentParser(description=description, usage=usage) + parser = ArgumentParser(description=__doc__) + parser.add_argument('paths', nargs='*', default=[]) actions = parser.add_argument_group('Actions') actions.add_argument('--dump', @@ -167,28 +161,23 @@ def main(argv): help='Restore extended attributes using' ' a dump read from stdin.') - options, args = parser.parse_known_args(argv[1:]) - - if len(args) != 0: - parser.error("expected zero arguments, " - "got %s" % len(args)) + options = parser.parse_args(argv) if sys.hexversion >= 0x3000000: file_in = sys.stdin.buffer.raw else: file_in = sys.stdin + if not options.paths: + options.paths += [x for x in file_in.read().split(b'\0') if x] if options.dump: - if sys.hexversion >= 0x3000000: file_out = sys.stdout.buffer else: file_out = sys.stdout - - dump_xattrs(file_in, file_out) + dump_xattrs(options.paths, file_out) elif options.restore: - restore_xattrs(file_in) else: @@ -198,5 +187,4 @@ def main(argv): if __name__ == '__main__': - rval = main(sys.argv[:]) - sys.exit(rval) + sys.exit(main(sys.argv[1:]))