1.1 --- a/convert.py Sat Apr 21 02:13:37 2012 +0200
1.2 +++ b/convert.py Sun Apr 22 01:50:20 2012 +0200
1.3 @@ -50,7 +50,7 @@
1.4
1.5 # Handle particular types.
1.6
1.7 - if objecttype in ("Page", "Comment"):
1.8 + if objecttype in ("Page", "Comment", "BlogPost"):
1.9
1.10 # Handle pages and revisions, adding revisions to the page manifest.
1.11 # The original version is used as a unifying identifier for all the
1.12 @@ -169,12 +169,14 @@
1.13 finally:
1.14 f.close()
1.15
1.16 -def sort_manifest(filename, pagetitle):
1.17 +def sort_manifest(filename, pagetitle, output=None):
1.18
1.19 """
1.20 Sort the manifest given in 'filename' according to revision. If a
1.21 'pagetitle' file exists, the title column in the manifest will be augmented
1.22 - with the contents of that file.
1.23 + with the contents of that file. If 'output' is given, the manifest details
1.24 + will be appended to the file having that filename instead of being rewritten
1.25 + to the original manifest file.
1.26 """
1.27
1.28 if exists(pagetitle):
1.29 @@ -197,7 +199,12 @@
1.30 finally:
1.31 f.close()
1.32
1.33 - write(filename, "".join(result))
1.34 + s = "".join(result)
1.35 +
1.36 + if output is None:
1.37 + write(filename, s)
1.38 + else:
1.39 + append(output, s)
1.40
1.41 if __name__ == "__main__":
1.42 import sys
1.43 @@ -246,9 +253,31 @@
1.44
1.45 pages_dir = join(directory, "pages")
1.46
1.47 + output_manifest = join(directory, "MOIN_PACKAGE")
1.48 + append(output_manifest, "MoinMoinPackage|1\n")
1.49 +
1.50 for pageid in listdir(pages_dir):
1.51 manifest = join(pages_dir, pageid, "manifest")
1.52 pagetitle = join(pages_dir, pageid, "pagetitle")
1.53 - sort_manifest(manifest, pagetitle)
1.54 + sort_manifest(manifest, pagetitle, output_manifest)
1.55 +
1.56 + # Write the page package.
1.57 +
1.58 + page_package = ZipFile(directory + extsep + "zip", "w")
1.59 +
1.60 + try:
1.61 + # Include the page revisions.
1.62 +
1.63 + versions_dir = join(directory, "versions")
1.64 +
1.65 + for versionid in listdir(versions_dir):
1.66 + page_package.write(join(versions_dir, versionid))
1.67 +
1.68 + # Include only the top-level manifest.
1.69 +
1.70 + page_package.write(output_manifest, "MOIN_PACKAGE")
1.71 +
1.72 + finally:
1.73 + page_package.close()
1.74
1.75 # vim: tabstop=4 expandtab shiftwidth=4