add -f option to allow overwriting output
This commit is contained in:
parent
8f0618e8eb
commit
dfefeb05fa
1 changed files with 11 additions and 7 deletions
18
moin2doku.py
18
moin2doku.py
|
@ -160,6 +160,8 @@ def convert_markup(page, filename):
|
||||||
def print_help():
|
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 "-f Overwrite output files"
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def unquote(filename):
|
def unquote(filename):
|
||||||
|
@ -183,7 +185,7 @@ def unquote(filename):
|
||||||
filename = filename.replace('(c3b6)', 'oe') # umlaut
|
filename = filename.replace('(c3b6)', 'oe') # umlaut
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def convertfile(pathname):
|
def convertfile(pathname, overwrite = False):
|
||||||
print "-> %s" % pathname
|
print "-> %s" % pathname
|
||||||
curr_rev = get_current_revision(pathname)
|
curr_rev = get_current_revision(pathname)
|
||||||
if curr_rev == None:
|
if curr_rev == None:
|
||||||
|
@ -222,7 +224,7 @@ def convertfile(pathname):
|
||||||
|
|
||||||
content = convert_markup(content, ns)
|
content = convert_markup(content, ns)
|
||||||
out_file = os.path.join(dir, id + '.txt')
|
out_file = os.path.join(dir, id + '.txt')
|
||||||
writefile(out_file, content)
|
writefile(out_file, content, overwrite = overwrite)
|
||||||
|
|
||||||
copy_attachments(pathname, attachment_dir)
|
copy_attachments(pathname, attachment_dir)
|
||||||
|
|
||||||
|
@ -232,21 +234,23 @@ def convertfile(pathname):
|
||||||
# "main" starts here
|
# "main" starts here
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'h', [ "help" ])
|
opts, args = getopt.getopt(sys.argv[1:], 'hf', [ "help" ])
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.'
|
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
overwrite = False
|
||||||
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":
|
||||||
|
overwrite = True
|
||||||
|
|
||||||
if len(sys.argv) != 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.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
moin_pages_dir = sys.argv[1]
|
(moin_pages_dir, output_dir) = args
|
||||||
output_dir = sys.argv[2]
|
|
||||||
|
|
||||||
check_dirs(moin_pages_dir, output_dir)
|
check_dirs(moin_pages_dir, output_dir)
|
||||||
|
|
||||||
|
@ -256,7 +260,7 @@ print 'Output dir is: %s.' % output_dir
|
||||||
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)
|
res = convertfile(pathname, overwrite = overwrite)
|
||||||
if res != None:
|
if res != None:
|
||||||
converted += 1
|
converted += 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue