diff options
author | jstebbins <[email protected]> | 2015-05-06 16:04:08 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2015-05-06 16:04:08 +0000 |
commit | 9c0e97cc2c369e0c720441d182bbde20210742f4 (patch) | |
tree | 8b8f74ed24d0f617c9980d9043ebd53c33c531f3 /scripts/quotestring.py | |
parent | 81bcee10d2ad88f44c0f7791f2dd8da4ee2c1b76 (diff) |
libhb,cli: add preset management to libhb, use it in cli
This results in custom preset support in the CLI and additional
command line options to fully support all preset keys.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7158 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'scripts/quotestring.py')
-rw-r--r-- | scripts/quotestring.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/quotestring.py b/scripts/quotestring.py new file mode 100644 index 000000000..1038719e7 --- /dev/null +++ b/scripts/quotestring.py @@ -0,0 +1,62 @@ +#! /usr/bin/python + +import re +import getopt +import sys + +def usage(): + print >> sys.stderr, ( + "Usage: %s <input> [output]\n" + "Summary:\n" + " Creates a quoted string suitable for inclusion in a C char*\n\n" + "Options:\n" + " <input> Input file to quote\n" + " <output> Output quoted string [stdout]\n" + % sys.argv[0] + ) + +def main(): + global inc_list + + OPTS = "" + try: + opts, args = getopt.gnu_getopt(sys.argv[1:], OPTS) + except getopt.GetoptError, err: + print >> sys.stderr, str(err) + usage() + sys.exit(2) + + for o, a in opts: + usage() + assert False, "unhandled option" + + if len(args) > 2 or len(args) < 1: + usage() + sys.exit(2) + + try: + infile = open(args[0]) + except Exception, err: + print >> sys.stderr, ( "Error: %s" % str(err) ) + sys.exit(1) + + if len(args) > 1: + try: + outfile = open(args[1], "w") + except Exception, err: + print >> sys.stderr, ( "Error: %s" % str(err)) + sys.exit(1) + else: + outfile = sys.stdout + + ss = infile.read() + ss = re.sub(r'\\', r'\\\\', ss) + ss = re.sub(r'"', r'\\"', ss) + pattern = re.compile("$", re.M) + ss = re.sub(pattern, r'\\n"', ss) + pattern = re.compile("^", re.M) + ss = re.sub(pattern, "\"", ss) + outfile.write(ss) + +main() + |