use moinmoun to fetch all page names
This commit is contained in:
parent
1411385a01
commit
924197ced1
1 changed files with 7 additions and 38 deletions
45
moin2doku.py
45
moin2doku.py
|
@ -21,11 +21,7 @@ from moinformat import moin2doku
|
||||||
|
|
||||||
USEC = 1000000
|
USEC = 1000000
|
||||||
|
|
||||||
def check_dirs(moin_pages_dir, output_dir):
|
def init_dirs(output_dir):
|
||||||
if moin_pages_dir and not isdir(moin_pages_dir):
|
|
||||||
print >> sys.stderr, "MoinMoin pages directory doesn't exist!"
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not isdir(output_dir):
|
if not isdir(output_dir):
|
||||||
print >> sys.stderr, "Output directory doesn't exist!"
|
print >> sys.stderr, "Output directory doesn't exist!"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -42,20 +38,6 @@ def check_dirs(moin_pages_dir, output_dir):
|
||||||
if not isdir(metadir):
|
if not isdir(metadir):
|
||||||
mkdir(metadir)
|
mkdir(metadir)
|
||||||
|
|
||||||
def get_path_names(moin_pages_dir, basenames = False):
|
|
||||||
items = listdir(moin_pages_dir)
|
|
||||||
pathnames = []
|
|
||||||
|
|
||||||
for item in items:
|
|
||||||
absitem = os.path.join(moin_pages_dir, item)
|
|
||||||
if isdir(absitem):
|
|
||||||
if basenames:
|
|
||||||
pathnames.append(item)
|
|
||||||
else:
|
|
||||||
pathnames.append(absitem)
|
|
||||||
|
|
||||||
return pathnames
|
|
||||||
|
|
||||||
def readfile(filename):
|
def readfile(filename):
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
text = f.read()
|
text = f.read()
|
||||||
|
@ -253,7 +235,6 @@ except getopt.GetoptError, e:
|
||||||
|
|
||||||
overwrite = False
|
overwrite = False
|
||||||
input_file = None
|
input_file = None
|
||||||
moin_pages_dir = None
|
|
||||||
output_dir = None
|
output_dir = None
|
||||||
convert_attic = False
|
convert_attic = False
|
||||||
redirect_conf = False
|
redirect_conf = False
|
||||||
|
@ -263,8 +244,6 @@ for o, a in opts:
|
||||||
print_help()
|
print_help()
|
||||||
if o == "-f":
|
if o == "-f":
|
||||||
overwrite = True
|
overwrite = True
|
||||||
if o == "-m":
|
|
||||||
moin_pages_dir = a
|
|
||||||
if o == "-a":
|
if o == "-a":
|
||||||
convert_attic = True
|
convert_attic = True
|
||||||
if o == "-r":
|
if o == "-r":
|
||||||
|
@ -274,15 +253,8 @@ for o, a in opts:
|
||||||
if o == "-F":
|
if o == "-F":
|
||||||
input_file = a
|
input_file = a
|
||||||
|
|
||||||
if not moin_pages_dir and not input_file:
|
|
||||||
print_help()
|
|
||||||
print >> sys.stderr, 'No input file or page dir to process'
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
check_dirs(moin_pages_dir, output_dir)
|
|
||||||
|
|
||||||
print "Input dir is: '%s'" % moin_pages_dir
|
|
||||||
print "Output dir is: '%s'" % output_dir
|
print "Output dir is: '%s'" % output_dir
|
||||||
|
init_dirs(output_dir)
|
||||||
|
|
||||||
dw = DokuWiki()
|
dw = DokuWiki()
|
||||||
request = RequestCLI()
|
request = RequestCLI()
|
||||||
|
@ -298,16 +270,13 @@ else:
|
||||||
if res != None:
|
if res != None:
|
||||||
converted += 1
|
converted += 1
|
||||||
|
|
||||||
pathnames = get_path_names(moin_pages_dir)
|
# get list of all pages in wiki
|
||||||
for pathname in pathnames:
|
pages = request.rootpage.getPageDict(user = '', exists = not convert_attic)
|
||||||
if pathname.count('MoinEditorBackup') > 0:
|
for page in pages.values():
|
||||||
print "SKIP %s: skip backups" % pathname
|
res = convertfile(page.getPagePath(), overwrite = overwrite)
|
||||||
continue
|
|
||||||
|
|
||||||
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(pages) + 1, converted)
|
||||||
|
|
||||||
if redirect_conf:
|
if redirect_conf:
|
||||||
print "Writing %s: %d items" % (redirect_conf, len(redirect_map))
|
print "Writing %s: %d items" % (redirect_conf, len(redirect_map))
|
||||||
|
|
Loading…
Reference in a new issue