add getopt support
This commit is contained in:
parent
e60bc6d57b
commit
8f0618e8eb
1 changed files with 17 additions and 14 deletions
25
moin2doku.py
25
moin2doku.py
|
@ -28,6 +28,7 @@
|
||||||
# https://github.com/glensc/moin2doku
|
# https://github.com/glensc/moin2doku
|
||||||
#
|
#
|
||||||
import sys, os, os.path, re
|
import sys, os, os.path, re
|
||||||
|
import getopt
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isdir, basename
|
from os.path import isdir, basename
|
||||||
|
|
||||||
|
@ -161,10 +162,6 @@ def print_help():
|
||||||
print "Convert MoinMoin pages to DokuWiki."
|
print "Convert MoinMoin pages to DokuWiki."
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def print_parameter_error():
|
|
||||||
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.'
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def unquote(filename):
|
def unquote(filename):
|
||||||
filename = filename.lower()
|
filename = filename.lower()
|
||||||
filename = filename.replace('(2d)', '-') # hyphen
|
filename = filename.replace('(2d)', '-') # hyphen
|
||||||
|
@ -234,16 +231,22 @@ def convertfile(pathname):
|
||||||
#
|
#
|
||||||
# "main" starts here
|
# "main" starts here
|
||||||
#
|
#
|
||||||
if len(sys.argv) > 1:
|
try:
|
||||||
if sys.argv[1] in ('-h', '--help'):
|
opts, args = getopt.getopt(sys.argv[1:], 'h', [ "help" ])
|
||||||
|
except getopt.GetoptError:
|
||||||
|
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "--help" or o == "-h":
|
||||||
print_help()
|
print_help()
|
||||||
elif len(sys.argv) > 2:
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
moin_pages_dir = sys.argv[1]
|
moin_pages_dir = sys.argv[1]
|
||||||
output_dir = sys.argv[2]
|
output_dir = sys.argv[2]
|
||||||
else:
|
|
||||||
print_parameter_error()
|
|
||||||
else:
|
|
||||||
print_parameter_error()
|
|
||||||
|
|
||||||
check_dirs(moin_pages_dir, output_dir)
|
check_dirs(moin_pages_dir, output_dir)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue