1.1 --- a/convert.py Wed Dec 19 00:15:50 2012 +0100
1.2 +++ b/convert.py Wed Dec 19 00:33:55 2012 +0100
1.3 @@ -94,6 +94,8 @@
1.4 if title:
1.5 title = "%s/%s" % (self.space, title)
1.6
1.7 + # See sort_manifest for access to this data.
1.8 +
1.9 append(join(pages_dir, pageid, "manifest"),
1.10 "%s|AddRevision|%s|%s|%s|%s\n" % (
1.11 content["version"],
1.12 @@ -236,26 +238,37 @@
1.13 def xmltranslate(filename, body):
1.14 translate(filename, body, parser.xmlparse)
1.15
1.16 -def sort_manifest(filename, pagetitle, output=None):
1.17 +def sort_manifest(pageid, output=None):
1.18
1.19 """
1.20 - Sort the manifest given in 'filename' according to revision.
1.21 + Using the given 'pageid', locate the manifest for the page and any page
1.22 + title information written to a "pagetitle" file.
1.23
1.24 - If a 'pagetitle' file exists, the title column in the manifest will be
1.25 + Then sort the manifest according to revision so that it will be added to
1.26 + MoinMoin in the correct order.
1.27 +
1.28 + If a "pagetitle" file exists, the title column in the manifest will be
1.29 augmented with the contents of that file. This is typically done for
1.30 comments.
1.31
1.32 + If a "children" file exists, the pages in that file will be added as a list
1.33 + to the end of each revision's content.
1.34 +
1.35 If 'output' is given, the manifest details will be appended to the file
1.36 having that filename instead of being rewritten to the original manifest
1.37 file.
1.38 """
1.39
1.40 + manifest = join(pages_dir, pageid, "manifest")
1.41 + pagetitle = join(pages_dir, pageid, "pagetitle")
1.42 + children = join(pages_dir, pageid, "children")
1.43 +
1.44 if exists(pagetitle):
1.45 title = read(pagetitle)
1.46 else:
1.47 title = None
1.48
1.49 - f = codecs.open(filename, "r", encoding="utf-8")
1.50 + f = codecs.open(manifest, "r", encoding="utf-8")
1.51 try:
1.52 lines = [x.split("|") for x in f.readlines()]
1.53 lines.sort(cmp=lambda x, y: cmp(int(x[0]), int(y[0])))
1.54 @@ -263,20 +276,54 @@
1.55 # Reconstruct the lines, optionally changing the titles.
1.56
1.57 result = []
1.58 - for x in lines:
1.59 +
1.60 + for line in lines:
1.61 + version, _addrevision, filename, old_title, username, comment = line
1.62 +
1.63 + # Add title information to the information already present.
1.64 +
1.65 if title is not None:
1.66 - x[3] = "%s/%s" % (title, x[3])
1.67 - result.append("|".join(x[1:]))
1.68 + new_title = "%s/%s" % (title, old_title)
1.69 + else:
1.70 + new_title = old_title
1.71 +
1.72 + # The version is omitted now that the manifest is ordered.
1.73 +
1.74 + line = _addrevision, filename, new_title, username, comment
1.75 + result.append("|".join(line))
1.76 +
1.77 + # Add child page information to the content.
1.78 +
1.79 + if exists(children):
1.80 + child_pages = []
1.81 + child_page_names = [x for x in read(children).split("\n") if x]
1.82 + child_page_names.sort()
1.83 +
1.84 + for child_page_name in child_page_names:
1.85 + child_pages.append(" * [[%s]]" % child_page_name)
1.86 +
1.87 + append(filename, child_page_section % "\n".join(child_pages))
1.88 +
1.89 finally:
1.90 f.close()
1.91
1.92 s = "".join(result)
1.93
1.94 if output is None:
1.95 - write(filename, s)
1.96 + write(manifest, s)
1.97 else:
1.98 append(output, s)
1.99
1.100 +# Template for child page information.
1.101 +
1.102 +child_page_section = """
1.103 +----
1.104 +
1.105 +%s
1.106 +"""
1.107 +
1.108 +# Main program.
1.109 +
1.110 if __name__ == "__main__":
1.111 try:
1.112 filename = sys.argv[1]
1.113 @@ -340,9 +387,7 @@
1.114 append(output_manifest, "MoinMoinPackage|1\n")
1.115
1.116 for pageid in listdir(pages_dir):
1.117 - manifest = join(pages_dir, pageid, "manifest")
1.118 - pagetitle = join(pages_dir, pageid, "pagetitle")
1.119 - sort_manifest(manifest, pagetitle, output_manifest)
1.120 + sort_manifest(pageid, output_manifest)
1.121
1.122 # Write the page package.
1.123