From kde-commits Tue Jan 31 23:05:41 2012 From: Patrick Spendrin Date: Tue, 31 Jan 2012 23:05:41 +0000 To: kde-commits Subject: [emerge/kde-4.8] bin: use argparse for repackage.py Message-Id: <20120131230541.F25C3A60C9 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=132805134126377 Git commit 3b915dd373ec382faf60011079ad142e988437c3 by Patrick Spendrin. Committed on 01/02/2012 at 00:05. Pushed by sengels into branch 'kde-4.8'. use argparse for repackage.py M +20 -9 bin/repackage.py http://commits.kde.org/emerge/3b915dd373ec382faf60011079ad142e988437c3 diff --git a/bin/repackage.py b/bin/repackage.py index e53c94f..7dff7df 100644 --- a/bin/repackage.py +++ b/bin/repackage.py @@ -1,25 +1,36 @@ import sys import os +import argparse = -def usage(): - print() - print("can be used to repackage a packagelist") - print("Syntax:") - print("\t", sys.argv[0], "packagelist.txt") = +usage =3D "%(prog)s -f list.txt\n" \ + " or: %(prog)s --file=3Dlist.txt \n" +parser =3D argparse.ArgumentParser(prog=3Dsys.argv[0], usage=3Dusage) + +parser.add_argument("-f", "--file", dest =3D "filename", metavar =3D "list= .txt", + help=3D"the filename for a packagelist") +parser.add_argument("-t", "--type", action =3D "store", default =3D OUTPUT= _DOT, + help=3D"Change the output format type possible values: xml kwi, do= t") + +args, rest =3D parser.parse_known_args() = if len(sys.argv) =3D=3D 1: - usage() + parser.print_help() exit(1) = -if not os.path.exists(sys.argv[1]): - print("error: couldn't find packagelist file", sys.argv[1]) - usage() +if not hasattr(args, "filename") or args.filename !=3D None or not os.path= .exists(args.filename): + print("error: couldn't find packagelist or can't read it") + parser.print_help() exit(1) = +filename =3D args.filename + cmdtemplate =3D "emerge --package%s %s/%s" targettemplate =3D " --target=3D%s" patchleveltemplate =3D " --patchlevel=3D%s" + + + with open(sys.argv[1], 'r') as f: for line in f: if line.startswith('#'):