add -f option to convert single file, rename overwrite option to -o

This commit is contained in:
Elan Ruusamäe 2011-02-06 22:36:40 +02:00
parent dfefeb05fa
commit ade015eb2b

View file

@ -161,7 +161,8 @@ def print_help():
print "Usage: moinconv.py <moinmoin pages directory> <output directory>" print "Usage: moinconv.py <moinmoin pages directory> <output directory>"
print "Convert MoinMoin pages to DokuWiki." print "Convert MoinMoin pages to DokuWiki."
print "Options:" print "Options:"
print "-f Overwrite output files" print "-o - overwrite output files"
print "-f FILE - convert signle file"
sys.exit(0) sys.exit(0)
def unquote(filename): def unquote(filename):
@ -234,17 +235,20 @@ def convertfile(pathname, overwrite = False):
# "main" starts here # "main" starts here
# #
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'hf', [ "help" ]) opts, args = getopt.getopt(sys.argv[1:], 'hof:', [ "help" ])
except getopt.GetoptError: except getopt.GetoptError, e:
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.' print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.: %s' % e
sys.exit(1) sys.exit(1)
overwrite = False overwrite = False
inputfile = None
for o, a in opts: for o, a in opts:
if o == "--help" or o == "-h": if o == "--help" or o == "-h":
print_help() print_help()
if o == "-f": if o == "-o":
overwrite = True overwrite = True
if o == "-f":
inputfile = a
if len(args) != 2: if len(args) != 2:
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.' print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.'
@ -257,11 +261,13 @@ check_dirs(moin_pages_dir, output_dir)
print 'Input dir is: %s.' % moin_pages_dir print 'Input dir is: %s.' % moin_pages_dir
print 'Output dir is: %s.' % output_dir print 'Output dir is: %s.' % output_dir
pathnames = get_path_names(moin_pages_dir) if inputfile != None:
converted = 0 res = convertfile(inputfile, overwrite = overwrite)
for pathname in pathnames: else:
pathnames = get_path_names(moin_pages_dir)
converted = 0
for pathname in pathnames:
res = convertfile(pathname, overwrite = overwrite) res = convertfile(pathname, overwrite = overwrite)
if res != None: if res != None:
converted += 1 converted += 1
print "Processed %d files, converted %d" % (len(pathnames), converted)
print "Processed %d files, converted %d" % (len(pathnames), converted)