add -f option to convert single file, rename overwrite option to -o
This commit is contained in:
parent
dfefeb05fa
commit
ade015eb2b
1 changed files with 19 additions and 13 deletions
18
moin2doku.py
18
moin2doku.py
|
@ -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
|
||||||
|
|
||||||
|
if inputfile != None:
|
||||||
|
res = convertfile(inputfile, overwrite = overwrite)
|
||||||
|
else:
|
||||||
pathnames = get_path_names(moin_pages_dir)
|
pathnames = get_path_names(moin_pages_dir)
|
||||||
converted = 0
|
converted = 0
|
||||||
for pathname in pathnames:
|
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)
|
||||||
|
|
Loading…
Reference in a new issue