diff options
author | Rajeesh <rajeesh@bluegene.in.ibm.com> | 2009-05-04 21:17:33 +0530 |
---|---|---|
committer | Rajeesh <rajeesh@bluegene.in.ibm.com> | 2009-05-04 21:17:33 +0530 |
commit | d4f9962ff66f0568b41bd7b785beb857d428c5bc (patch) | |
tree | d9f243e8c181500ef6779bebf9288b2db123b061 /payyans-doc-converter/payyans-doc-converter.py | |
parent | 6d33918b6b8e90f80b3ea78b659fea155b2cb1e0 (diff) | |
download | AnjaliOldLipi.git-d4f9962ff66f0568b41bd7b785beb857d428c5bc.tar.gz AnjaliOldLipi.git-d4f9962ff66f0568b41bd7b785beb857d428c5bc.tar.xz AnjaliOldLipi.git-d4f9962ff66f0568b41bd7b785beb857d428c5bc.zip |
payyans-doc-converter : Add command-line options
Diffstat (limited to 'payyans-doc-converter/payyans-doc-converter.py')
-rw-r--r-- | payyans-doc-converter/payyans-doc-converter.py | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/payyans-doc-converter/payyans-doc-converter.py b/payyans-doc-converter/payyans-doc-converter.py index 2734d88..24498a0 100644 --- a/payyans-doc-converter/payyans-doc-converter.py +++ b/payyans-doc-converter/payyans-doc-converter.py @@ -19,6 +19,7 @@ import sys import os +from optparse import OptionParser # import the oorunner helper module we've written import oorunner @@ -41,8 +42,8 @@ class OOWrapper: # Add to path so we can find uno. if sys.path.count(OPENOFFICE_LIBPATH) == 0: sys.path.insert(0, OPENOFFICE_LIBPATH) + # This is required for loadComponentFromURL to work properly os.putenv('URE_BOOTSTRAP','vnd.sun.star.pathname:' + OPENOFFICE_PATH + '/fundamentalrc') - # This is required for loadComponentFromURL to work properly break # start the openoffice instance @@ -96,18 +97,28 @@ class OOWrapper: if __name__ == "__main__": - if sys.argv.__len__() != 5: - raise SystemExit("usage: "+sys.argv[0]+" <infile> <outfile> <mapfile> <direction>") - infile = sys.argv[1] - outfile = sys.argv[2] - mapfile = sys.argv[3] - direction = sys.argv[4] - if not os.path.exists(os.path.abspath(infile)): - raise SystemExit("Cannot find Input file") - if not os.path.exists(os.path.abspath(mapfile)): - raise SystemExit("Cannot find Mapping file") + + usage = "usage: %prog [options] arg" + parser = OptionParser(usage) + parser.add_option("-i", "--input-file", dest="input_filename", help="the input file in ascii format") + parser.add_option("-o", "--output-file", dest="output_filename", help="the output file name") + parser.add_option("-d", "--direction", dest="direction", help="'a2u': Ascii to Unicode, 'u2a': Unicode to Ascii") + parser.add_option("-m", "--mapping-file", dest="mapping_filename", help="the ascii to unicode mapping file name") + (options, args) = parser.parse_args() + infile = outfile = mapfile = "" + if (options.input_filename): + infile = os.path.abspath(options.input_filename) + if (options.output_filename): + outfile = os.path.abspath(options.output_filename) + if (options.mapping_filename): + mapfile = os.path.abspath(options.mapping_filename) + direction = options.direction + if not os.path.exists(infile): + raise SystemExit("Error : Input file doesn't exist") + if not os.path.exists(mapfile): + raise SystemExit("Error : Mapping file doesn't exist") if not direction in ['a2u', 'u2a']: - raise SystemExit("Direction should be either 'a2u' or 'u2a'") + raise SystemExit("Error :Direction should be either 'a2u' or 'u2a'") app = OOWrapper() app.covertDocWithPayyans(infile, mapfile, outfile, direction) |