Port hb-manifest-read to Python
This commit is contained in:
parent
a59ed46fa4
commit
96968bfae5
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
from hb_test_tools import *
|
from hb_test_tools import *
|
||||||
|
|
||||||
UtilMains.process_multiple_files (DiffFilters.filter_failures)
|
UtilMains.filter_multiple_strings_or_stdin (Unicode.decode, "UNICODE_STRING")
|
||||||
|
|
|
@ -1,36 +1,5 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/python
|
||||||
|
|
||||||
if test $# = 0; then
|
from hb_test_tools import *
|
||||||
echo "Usage: $0 DIR..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
strict=true
|
UtilMains.process_multiple_args (Manifest.print_to_stdout, mnemonic="DIR")
|
||||||
|
|
||||||
recurse () {
|
|
||||||
if ! test -e "$1"; then
|
|
||||||
if $strict; then
|
|
||||||
echo "$0: $1 does not exist" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if test -d "$1"; then
|
|
||||||
if test -f "$1/MANIFEST"; then
|
|
||||||
cat "$1/MANIFEST" | while read f; do
|
|
||||||
recurse "$1/$f"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
if $strict; then
|
|
||||||
echo "$0: $1/MANIFEST does not exist" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
for root in "$@"; do
|
|
||||||
root=${root%/}
|
|
||||||
recurse "$root";
|
|
||||||
done
|
|
||||||
|
|
|
@ -106,23 +106,33 @@ class ShapeFilters:
|
||||||
class UtilMains:
|
class UtilMains:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_multiple_files (callback):
|
def process_multiple_files (callback, mnemonic = "FILE"):
|
||||||
|
|
||||||
if len (sys.argv) == 1:
|
if len (sys.argv) == 1:
|
||||||
print "Usage: %s FILE..." % sys.argv[0]
|
print "Usage: %s %s..." % (sys.argv[0], mnemonic)
|
||||||
sys.exit (1)
|
sys.exit (1)
|
||||||
|
|
||||||
for s in sys.argv[1:]:
|
for s in sys.argv[1:]:
|
||||||
callback (FileHelpers.open_file_or_stdin (s))
|
callback (FileHelpers.open_file_or_stdin (s))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def filter_multiple_strings_or_stdin (callback, string_mnemonic, \
|
def process_multiple_args (callback, mnemonic):
|
||||||
|
|
||||||
|
if len (sys.argv) == 1:
|
||||||
|
print "Usage: %s %s..." % (sys.argv[0], mnemonic)
|
||||||
|
sys.exit (1)
|
||||||
|
|
||||||
|
for s in sys.argv[1:]:
|
||||||
|
callback (s)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def filter_multiple_strings_or_stdin (callback, mnemonic, \
|
||||||
separator = " ", \
|
separator = " ", \
|
||||||
concat_separator = False):
|
concat_separator = False):
|
||||||
|
|
||||||
if len (sys.argv) == 1 or ('--stdin' in sys.argv and len (sys.argv) != 2):
|
if len (sys.argv) == 1 or ('--stdin' in sys.argv and len (sys.argv) != 2):
|
||||||
print "Usage:\n %s %s...\nor:\n %s --stdin" \
|
print "Usage:\n %s %s...\nor:\n %s --stdin" \
|
||||||
% (sys.argv[0], string_mnemonic, sys.argv[0])
|
% (sys.argv[0], mnemonic, sys.argv[0])
|
||||||
sys.exit (1)
|
sys.exit (1)
|
||||||
|
|
||||||
if '--stdin' in sys.argv:
|
if '--stdin' in sys.argv:
|
||||||
|
@ -189,7 +199,7 @@ class Unicode:
|
||||||
return u' + '.join (Unicode.pretty_name (x) for x in s).encode ('utf-8')
|
return u' + '.join (Unicode.pretty_name (x) for x in s).encode ('utf-8')
|
||||||
|
|
||||||
|
|
||||||
class FileHelprs:
|
class FileHelpers:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def open_file_or_stdin (f):
|
def open_file_or_stdin (f):
|
||||||
|
@ -197,5 +207,34 @@ class FileHelprs:
|
||||||
return sys.stdin
|
return sys.stdin
|
||||||
return file (f)
|
return file (f)
|
||||||
|
|
||||||
|
|
||||||
|
class Manifest:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def print_to_stdout (s, strict = True):
|
||||||
|
if not os.path.exists (s):
|
||||||
|
if strict:
|
||||||
|
print >> sys.stderr, "%s: %s does not exist" (sys.argv[0], s)
|
||||||
|
sys.exit (1)
|
||||||
|
return
|
||||||
|
|
||||||
|
if os.path.isdir (s):
|
||||||
|
|
||||||
|
if s[-1] != '/':
|
||||||
|
s += "/"
|
||||||
|
|
||||||
|
try:
|
||||||
|
m = file (s + "/MANIFEST")
|
||||||
|
items = [x.strip () for x in m.readlines ()]
|
||||||
|
for f in items:
|
||||||
|
Manifest.print_to_stdout (s + f)
|
||||||
|
except IOError:
|
||||||
|
if strict:
|
||||||
|
print >> sys.stderr, "%s: %s does not exist" (sys.argv[0], s + "/MANIFEST")
|
||||||
|
sys.exit (1)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print s
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue