[oe] [PATCH 1/2] source-checker: usability tweaks

Michael Smith msmith at cbnco.com
Sat Jun 27 21:29:38 UTC 2009


checksum sorter, source checker: exit(1) on failure; send usage to
stderr; make executable

checksum sorter: read from stdin if no arg; accept --inplace option to
read and write from the same file.

Signed-off-by: Michael Smith <msmith at cbnco.com>
---
 contrib/source-checker/oe-checksums-sorter.py |   59 +++++++++++++++++++++----
 contrib/source-checker/oe-source-checker.py   |    4 +-
 2 files changed, 52 insertions(+), 11 deletions(-)
 mode change 100644 => 100755 contrib/source-checker/oe-checksums-sorter.py
 mode change 100644 => 100755 contrib/source-checker/oe-source-checker.py

diff --git a/contrib/source-checker/oe-checksums-sorter.py b/contrib/source-checker/oe-checksums-sorter.py
old mode 100644
new mode 100755
index 2bab58c..7388c62
--- a/contrib/source-checker/oe-checksums-sorter.py
+++ b/contrib/source-checker/oe-checksums-sorter.py
@@ -29,20 +29,57 @@
 #
 
 
+import ConfigParser
+import getopt
+import os
 import sys
+import tempfile
 
-if len(sys.argv) < 2:
-    print """
-    OpenEmbedded source checksums script require argument:
+def usage():
+    print >> sys.stderr, \
+    """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(1)
+
+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()
+
+inplace = False
+readstdin = False
+for opt, val in optlist:
+    if opt == '-i' or opt == '--inplace':
+        inplace = True
+    else:
+        usage()
+
+if len(args) == 0:
+    readstdin = True
+    if inplace:
+        print >> sys.stderr, "%s: --inplace requires a filename" % sys.argv[0]
+        usage()
+
+if len(args) > 1:
+    usage()
+
+out = sys.stdout
+outfn = None
+if inplace:
+    outfd, outfn = tempfile.mkstemp(prefix='cksums')
+    out = os.fdopen(outfd, 'w')
 
 checksums_parser = ConfigParser.ConfigParser()
-checksums_parser.read(sys.argv[1])
+
+if readstdin:
+    checksums_parser.readfp(sys.stdin)
+else:
+    checksums_parser.read(args[0])
 
 item = 1;
 files_total   = len(checksums_parser.sections())
@@ -60,4 +97,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(outfn, args[0])
diff --git a/contrib/source-checker/oe-source-checker.py b/contrib/source-checker/oe-source-checker.py
old mode 100644
new mode 100755
index 0ae3563..79e988b
--- a/contrib/source-checker/oe-source-checker.py
+++ b/contrib/source-checker/oe-source-checker.py
@@ -39,13 +39,13 @@
 import sys
 
 if len(sys.argv) < 3:
-    print """
+    print >> sys.stderr, """
     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
 
-- 
1.6.3





More information about the Openembedded-devel mailing list