scan underlay dir to find pages not to convert

This commit is contained in:
Elan Ruusamäe 2012-09-17 23:38:04 +02:00
parent da1a497b0b
commit 415026c59d

View file

@ -15,6 +15,13 @@ from os.path import isdir, basename
from doku import DokuWiki
from moinformat import moin2doku
def scan_underlay_pages(dirpath):
pages = []
paths = get_path_names(dirpath, basenames = True)
for path in paths:
pages.append(wikiname(path))
return pages
def check_dirs(moin_pages_dir, output_dir):
if moin_pages_dir and not isdir(moin_pages_dir):
print >> sys.stderr, "MoinMoin pages directory doesn't exist!"
@ -24,14 +31,17 @@ def check_dirs(moin_pages_dir, output_dir):
print >> sys.stderr, "Output directory doesn't exist!"
sys.exit(1)
def get_path_names(moin_pages_dir):
def get_path_names(moin_pages_dir, basenames = False):
items = listdir(moin_pages_dir)
pathnames = []
for item in items:
item = os.path.join(moin_pages_dir, item)
if isdir(item):
absitem = os.path.join(moin_pages_dir, item)
if isdir(absitem):
if basenames:
pathnames.append(item)
else:
pathnames.append(absitem)
return pathnames
@ -239,6 +249,10 @@ def convertfile(pagedir, overwrite = False):
print "SKIP %s: skip backups" % pagedir
return
if pagename in moin_underlay_pages:
print "SKIP %s: page in underlay" % pagename
return
content = readfile2(curr_rev)
# print "content:[%s]" % content
# content = convert_markup(pagename, content)
@ -261,7 +275,7 @@ def convertfile(pagedir, overwrite = False):
# "main" starts here
#
try:
opts, args = getopt.getopt(sys.argv[1:], 'hfm:d:F:', [ "help" ])
opts, args = getopt.getopt(sys.argv[1:], 'hfm:u:d:F:', [ "help" ])
except getopt.GetoptError, e:
print >> sys.stderr, 'Incorrect parameters! Use --help switch to learn more.: %s' % e
sys.exit(1)
@ -269,6 +283,7 @@ except getopt.GetoptError, e:
overwrite = False
input_file = None
moin_pages_dir = None
moin_underlay_pages = None
output_dir = None
for o, a in opts:
if o == "--help" or o == "-h":
@ -277,6 +292,8 @@ for o, a in opts:
overwrite = True
if o == "-m":
moin_pages_dir = a
if o == "-u":
moin_underlay_pages = scan_underlay_pages(a)
if o == "-d":
output_dir = a
if o == "-F":