diff options
author | Michael Smith <msmith@cbnco.com> | 2009-06-27 17:12:01 -0400 |
---|---|---|
committer | Michael Smith <msmith@cbnco.com> | 2009-08-19 09:12:51 -0400 |
commit | 3555703d298735f509973b30e5aa40c19c1f6a2e (patch) | |
tree | 11cdff3c1290b84cd21e2cbbbb35428c6e82e9d7 /contrib/source-checker | |
parent | ad0ba478018ac64598b6701df5a79b1f71f9b58f (diff) |
source-checker: usability tweaks
checksum sorter, source checker:
* exit(1) on failure;
* send errors to stderr;
* make executable
checksum sorter:
* read from stdin if no arg;
* accept --inplace option to read and write from the same file;
* check that input file exists as ConfigParser.read() doesn't treat
missing files as an error.
Signed-off-by: Michael Smith <msmith@cbnco.com>
Diffstat (limited to 'contrib/source-checker')
-rwxr-xr-x[-rw-r--r--] | contrib/source-checker/oe-checksums-sorter.py | 66 | ||||
-rwxr-xr-x[-rw-r--r--] | contrib/source-checker/oe-source-checker.py | 3 |
2 files changed, 59 insertions, 10 deletions
diff --git a/contrib/source-checker/oe-checksums-sorter.py b/contrib/source-checker/oe-checksums-sorter.py index 2bab58c9fd..cde6ddc73e 100644..100755 --- a/contrib/source-checker/oe-checksums-sorter.py +++ b/contrib/source-checker/oe-checksums-sorter.py @@ -29,20 +29,64 @@ # +import ConfigParser +import getopt +import os import sys +import tempfile -if len(sys.argv) < 2: - print """ - OpenEmbedded source checksums script require argument: +def usage(rc): + print """usage: %s [--inplace|-i] conf/checksums.ini - 1. location of conf/checksums.ini - """ - sys.exit(0) + --inplace, -i: update file in place (default is to write to stdout) -import ConfigParser, os + If no input file is given, will read from standard input. + """ % sys.argv[0] + sys.exit(rc) + +try: + optlist, args = getopt.getopt(sys.argv[1:], "ih", ["inplace", "help"]) +except getopt.GetoptError, e: + print >> sys.stderr, "%s: %s" % (sys.argv[0], e) + usage(1) + +inplace = False +infp = sys.stdin +filename = None +for opt, val in optlist: + if opt == '-i' or opt == '--inplace': + inplace = True + elif opt == 'h' or opt == '--help': + usage(0) + else: + print >> sys.stderr, "%s: %s: invalid argument" % (sys.argv[0], opt) + usage(1) + +if len(args) == 0: + if inplace: + print >> sys.stderr, "%s: --inplace requires a filename" % sys.argv[0] + usage(1) +elif len(args) == 1: + filename = args[0] + try: + infp = open(filename, "r") + except Exception, e: + print >> sys.stderr, "%s: %s" % (sys.argv[0], e) + sys.exit(1) +else: + print >> sys.stderr, "%s: extra arguments" % sys.argv[0] + usage(1) + +out = sys.stdout +tmpfn = None +if inplace: + outfd, tmpfn = tempfile.mkstemp(prefix='cksums', + dir=os.path.dirname(filename) or '.') + os.chmod(tmpfn, os.stat(filename).st_mode) + out = os.fdopen(outfd, 'w') checksums_parser = ConfigParser.ConfigParser() -checksums_parser.read(sys.argv[1]) +checksums_parser.readfp(infp) item = 1; files_total = len(checksums_parser.sections()) @@ -60,4 +104,8 @@ for source in checksums_parser.sections(): new_list.sort() for entry in new_list: - print "[%s]\nmd5=%s\nsha256=%s\n" % (entry[1], entry[2], entry[3]) + print >> out, "[%s]\nmd5=%s\nsha256=%s\n" % (entry[1], entry[2], entry[3]) + +if inplace: + out.close() + os.rename(tmpfn, filename) diff --git a/contrib/source-checker/oe-source-checker.py b/contrib/source-checker/oe-source-checker.py index 0ae356395c..bb14c87289 100644..100755 --- a/contrib/source-checker/oe-source-checker.py +++ b/contrib/source-checker/oe-source-checker.py @@ -39,13 +39,14 @@ import sys if len(sys.argv) < 3: + print >> sys.stderr, "%s: missing argument" % sys.argv[0] print """ OpenEmbedded source checker script require two arguments: 1. location of conf/checksums.ini 2. path to DL_DIR (without "/" at the end) """ - sys.exit(0) + sys.exit(1) import ConfigParser, os, itertools |