1.1 --- a/convert.py Sat Mar 31 01:35:36 2012 +0200
1.2 +++ b/convert.py Sat Mar 31 01:54:42 2012 +0200
1.3 @@ -1,6 +1,6 @@
1.4 #!/usr/bin/env python
1.5
1.6 -from os import mkdir, makedirs, symlink
1.7 +from os import mkdir, makedirs
1.8 from os.path import exists, extsep, join, splitext
1.9 from zipfile import ZipFile
1.10 from cStringIO import StringIO
1.11 @@ -31,30 +31,6 @@
1.12
1.13 if objecttype == "Page":
1.14
1.15 - # Handle pages.
1.16 -
1.17 - if content.has_key("historicalVersions"):
1.18 - versions = content["historicalVersions"]
1.19 -
1.20 - # Make a page directory and links from the versions to separate
1.21 - # files.
1.22 -
1.23 - page_dir = join(pages_dir, identifier)
1.24 - revisions_dir = join(page_dir, "revisions")
1.25 -
1.26 - mkdir(page_dir)
1.27 - mkdir(revisions_dir)
1.28 -
1.29 - # Historical versions are stored separately.
1.30 -
1.31 - for n, (cls, version) in enumerate(versions):
1.32 - if cls == "Page":
1.33 - symlink(join("..", "..", "..", "..", versions_dir, version), join(revisions_dir, str(n+1)))
1.34 -
1.35 - # The page always seems to hold the current version itself.
1.36 -
1.37 - symlink(join("..", "..", "..", "..", versions_dir, identifier), join(revisions_dir, str(len(versions)+1)))
1.38 -
1.39 # Handle pages and revisions, adding revisions to the page manifest.
1.40
1.41 if content.has_key("originalVersion"):
1.42 @@ -114,16 +90,28 @@
1.43 self.elements.append((attributes[-1]["class"], text.strip()))
1.44
1.45 def mkdirs(name):
1.46 +
1.47 + "Make the directory with the given 'name' at any depth."
1.48 +
1.49 try:
1.50 makedirs(name)
1.51 except OSError:
1.52 pass
1.53
1.54 def append(filename, s):
1.55 +
1.56 + "Append to the file with the given 'filename' the string 's'."
1.57 +
1.58 write(filename, s, True)
1.59
1.60 def write(filename, s, append=False):
1.61 - f = codecs.open(filename, append and "ab" or "wb", encoding="utf-8")
1.62 +
1.63 + """
1.64 + Write to the file with the given 'filename' the string 's'. If the optional
1.65 + 'append' parameter is set to a true value, 's' will be appended to the file.
1.66 + """
1.67 +
1.68 + f = codecs.open(filename, append and "a" or "w", encoding="utf-8")
1.69 try:
1.70 f.write(s)
1.71 finally:
1.72 @@ -154,6 +142,8 @@
1.73 p["collection"] = handler.handle_collection
1.74 p["element"] = handler.handle_element
1.75
1.76 + # Open the XML dump.
1.77 +
1.78 f = open(filename)
1.79
1.80 if is_zipfile:
1.81 @@ -162,9 +152,14 @@
1.82 else:
1.83 ff = f
1.84
1.85 + # Parse the data.
1.86 +
1.87 try:
1.88 p.parse(ff)
1.89 finally:
1.90 f.close()
1.91
1.92 + # Tidy up the import manifests, sorting each of them by revision and
1.93 + # finalising them.
1.94 +
1.95 # vim: tabstop=4 expandtab shiftwidth=4