1.1 --- a/convert.py Wed Dec 19 22:58:34 2012 +0100
1.2 +++ b/convert.py Thu Dec 20 00:30:55 2012 +0100
1.3 @@ -93,6 +93,7 @@
1.4
1.5 if title:
1.6 title = "%s/%s" % (self.space, title)
1.7 + write(join(pages_dir, pageid, "pagetitle"), title)
1.8
1.9 # See sort_manifest for access to this data.
1.10
1.11 @@ -100,22 +101,11 @@
1.12 "%s|AddRevision|%s|%s|%s|%s\n" % (
1.13 content["version"],
1.14 versionfile,
1.15 - title or content["version"], # comment titles will incorporate the version
1.16 + title, # comment titles will incorporate the comment's position
1.17 content["lastModifierName"],
1.18 content["versionComment"]
1.19 ))
1.20
1.21 - # Write comments as subpages.
1.22 -
1.23 - if content.has_key("comments"):
1.24 -
1.25 - # Define a page directory for each comment, and write the page
1.26 - # title in a special file for later processing.
1.27 -
1.28 - for _comment, commentid in content["comments"]:
1.29 - mkdirs(join(pages_dir, commentid))
1.30 - append(join(pages_dir, commentid, "pagetitle"), title)
1.31 -
1.32 # Add information to parent pages for child page lists.
1.33
1.34 if content.has_key("parent"):
1.35 @@ -123,6 +113,15 @@
1.36 mkdirs(join(pages_dir, parentid))
1.37 append(join(pages_dir, parentid, "children"), title + "\n")
1.38
1.39 + # Add creation details for comments to the owner page.
1.40 + # Since comments can be versioned, the date of the original version
1.41 + # is used, and only this "original" version has the owner property.
1.42 +
1.43 + if objecttype == "Comment" and content.has_key("owner"):
1.44 + ownerid = content["owner"]
1.45 + mkdirs(join(pages_dir, ownerid))
1.46 + append(join(pages_dir, ownerid, "comments"), "%s|%s\n" % (content["creationDate"], pageid))
1.47 +
1.48 # Some metadata is not particularly relevant. For example,
1.49 # ancestors, children, parent are navigation-related.
1.50
1.51 @@ -238,7 +237,40 @@
1.52 def xmltranslate(filename, body):
1.53 translate(filename, body, parser.xmlparse)
1.54
1.55 -def sort_manifest(pageid, output=None):
1.56 +def sort_comments(pages_dir, pageid):
1.57 +
1.58 + """
1.59 + Where 'pageid' has comments associated with it, sort them chronologically
1.60 + and label the comment pages with the owner page's title and comment's
1.61 + position in the chronological sequence. Such labelling is done by writing
1.62 + a "pagetitle" file in each comment page's directory.
1.63 + """
1.64 +
1.65 + comments = join(pages_dir, pageid, "comments")
1.66 +
1.67 + if not exists(comments):
1.68 + return
1.69 +
1.70 + title = read(join(pages_dir, pageid, "pagetitle"))
1.71 +
1.72 + details = [line.split("|") for line in read(comments).split("\n") if line]
1.73 + details.sort()
1.74 +
1.75 + # Write the sorted comments list for testing purposes.
1.76 +
1.77 + write(comments, "\n".join(["|".join(x) for x in details]))
1.78 +
1.79 + # Define comments as subpages by setting their titles using this
1.80 + # page's name/title and their position in the comments collection.
1.81 +
1.82 + for position, (_lastmodified, commentid) in enumerate(details):
1.83 +
1.84 + # In the page directory for each comment, write the page title in a
1.85 + # special file for later processing.
1.86 +
1.87 + write(join(pages_dir, commentid, "pagetitle"), "%s/%s" % (title, position))
1.88 +
1.89 +def sort_manifest(pages_dir, pageid, output=None):
1.90
1.91 """
1.92 Using the given 'pageid', locate the manifest for the page and any page
1.93 @@ -280,10 +312,10 @@
1.94 for line in lines:
1.95 version, _addrevision, filename, old_title, username, comment = line
1.96
1.97 - # Add title information to the information already present.
1.98 + # Replace title information with the information already present.
1.99
1.100 if title is not None:
1.101 - new_title = "%s/%s" % (title, old_title)
1.102 + new_title = title
1.103 else:
1.104 new_title = old_title
1.105
1.106 @@ -383,11 +415,14 @@
1.107
1.108 pages_dir = join(space, "pages")
1.109
1.110 + for pageid in listdir(pages_dir):
1.111 + sort_comments(pages_dir, pageid)
1.112 +
1.113 output_manifest = join(space, "MOIN_PACKAGE")
1.114 append(output_manifest, "MoinMoinPackage|1\n")
1.115
1.116 for pageid in listdir(pages_dir):
1.117 - sort_manifest(pageid, output_manifest)
1.118 + sort_manifest(pages_dir, pageid, output_manifest)
1.119
1.120 # Write the page package.
1.121