add getopt support
This commit is contained in:
parent
e60bc6d57b
commit
8f0618e8eb
1 changed files with 17 additions and 14 deletions
31
moin2doku.py
31
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" ])
|
||||||
print_help()
|
except getopt.GetoptError:
|
||||||
elif len(sys.argv) > 2:
|
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.'
|
||||||
moin_pages_dir = sys.argv[1]
|
sys.exit(1)
|
||||||
output_dir = sys.argv[2]
|
|
||||||
else:
|
for o, a in opts:
|
||||||
print_parameter_error()
|
if o == "--help" or o == "-h":
|
||||||
else:
|
print_help()
|
||||||
print_parameter_error()
|
|
||||||
|
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]
|
||||||
|
output_dir = sys.argv[2]
|
||||||
|
|
||||||
check_dirs(moin_pages_dir, output_dir)
|
check_dirs(moin_pages_dir, output_dir)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue