1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/archive_wiki.py Wed Dec 12 02:02:25 2007 +0100
1.3 @@ -0,0 +1,85 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +import sys, os
1.7 +
1.8 +wiki_dir, archive_dir = sys.argv[1:3]
1.9 +dry_run = ("-n" in sys.argv)
1.10 +
1.11 +pages = os.path.join(wiki_dir, "wiki", "data", "pages")
1.12 +users = os.path.join(wiki_dir, "wiki", "data", "user")
1.13 +
1.14 +# Make the archive's page directory.
1.15 +
1.16 +archive_pages = os.path.join(archive_dir, "wiki", "data", "pages")
1.17 +if not dry_run and not os.path.exists(archive_pages):
1.18 + os.makedirs(archive_pages)
1.19 +
1.20 +archive_users = os.path.join(archive_dir, "wiki", "data", "user")
1.21 +if not dry_run and not os.path.exists(archive_users):
1.22 + os.makedirs(archive_users)
1.23 +
1.24 +# Copy user details.
1.25 +
1.26 +print "Copying users..."
1.27 +if not dry_run:
1.28 + cmd = "cp %s %s" % (os.path.join(users, "*"), archive_users)
1.29 + print cmd
1.30 + os.system(cmd)
1.31 +
1.32 +# Find active Wiki pages.
1.33 +
1.34 +for page in os.listdir(pages):
1.35 + page_dir = os.path.join(pages, page)
1.36 +
1.37 + if os.path.isdir(page_dir) and "current" in os.listdir(page_dir):
1.38 +
1.39 + f = open(os.path.join(page_dir, "current"))
1.40 + try:
1.41 + current = f.read().strip()
1.42 + finally:
1.43 + f.close()
1.44 +
1.45 + archive_page_dir = os.path.join(archive_pages, page)
1.46 + archive_page_revisions = os.path.join(archive_page_dir, "revisions")
1.47 + page_revisions = os.path.join(page_dir, "revisions")
1.48 +
1.49 + if current not in os.listdir(page_revisions):
1.50 + continue
1.51 +
1.52 + print "Archiving", page
1.53 + print "Revision", current
1.54 +
1.55 + if not dry_run:
1.56 + if not os.path.exists(archive_page_revisions):
1.57 + os.makedirs(archive_page_revisions)
1.58 +
1.59 + f = open(os.path.join(archive_page_dir, "current"), "w")
1.60 + try:
1.61 + f.write("00000001")
1.62 + finally:
1.63 + f.close()
1.64 +
1.65 + cmd = "cp %s %s" % (os.path.join(page_revisions, current), os.path.join(archive_page_revisions, "00000001"))
1.66 + print cmd
1.67 + if not dry_run:
1.68 + os.system(cmd)
1.69 +
1.70 + attachments_dir = os.path.join(page_dir, "attachments")
1.71 + if os.path.exists(attachments_dir):
1.72 + print "Archiving attachments..."
1.73 +
1.74 + archive_attachments_dir = os.path.join(archive_page_dir, "attachments")
1.75 + if not dry_run and not os.path.exists(archive_attachments_dir):
1.76 + os.mkdir(archive_attachments_dir)
1.77 +
1.78 + cmd = "cp %s %s" % (os.path.join(attachments_dir, "*"), archive_attachments_dir)
1.79 + print cmd
1.80 + if not dry_run:
1.81 + os.system(cmd)
1.82 +
1.83 + print
1.84 +
1.85 +print "Now run the following, if adding to a live Wiki:"
1.86 +print "chown -R www-data: %s/www %s/wiki" % (archive_dir, archive_dir)
1.87 +
1.88 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/farmconfig.py Wed Dec 12 01:40:33 2007 +0100
2.2 +++ b/farmconfig.py Wed Dec 12 02:02:25 2007 +0100
2.3 @@ -46,6 +46,8 @@
2.4 # wikiname, url regular expression (no protocol)
2.5 # ---------------------------------------------------------------
2.6 ("ep2008", r".*"), # this is ok for a single wiki
2.7 + #("ep2008", r"localhost/ep2008/.*"),
2.8 + #("tmp_ep2008", r"localhost/tmp_ep2008/.*"),
2.9
2.10 # for multiple wikis, do something like this:
2.11 #("moinmoin", r"^moinmoin.wikiwikiweb.de/.*$"),