~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/_tests/maketestwiki.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
MoinMoin - make a test wiki
 
4
 
 
5
Usage:
 
6
 
 
7
    maketestwiki.py
 
8
 
 
9
@copyright: 2005 by Thomas Waldmann
 
10
@license: GNU GPL, see COPYING for details.
 
11
"""
 
12
 
 
13
import os, sys, shutil, errno
 
14
 
 
15
filename = globals().get("__file__") or sys.argv[0]
 
16
moinpath = os.path.abspath(os.path.join(os.path.dirname(filename), os.pardir, os.pardir))
 
17
sys.path.insert(0, moinpath)
 
18
 
 
19
from MoinMoin.support import tarfile
 
20
 
 
21
WIKI = os.path.abspath(os.path.join(moinpath, 'tests', 'wiki'))
 
22
SHARE = os.path.abspath(os.path.join(moinpath, 'wiki'))
 
23
 
 
24
 
 
25
def removeTestWiki():
 
26
    print 'removing old wiki ...'
 
27
    for dir in ['data', 'underlay']:
 
28
        try:
 
29
            shutil.rmtree(os.path.join(WIKI, dir))
 
30
        except OSError, err:
 
31
            if not (err.errno == errno.ENOENT or
 
32
                    (err.errno == 3 and os.name == 'nt')):
 
33
                raise
 
34
 
 
35
 
 
36
def copyData():
 
37
    print 'copying data ...'
 
38
    src = os.path.join(SHARE, 'data')
 
39
    dst = os.path.join(WIKI, 'data')
 
40
    shutil.copytree(src, dst)
 
41
 
 
42
 
 
43
def untarUnderlay():
 
44
    print 'untaring underlay ...'
 
45
    tar = tarfile.open(os.path.join(SHARE, 'underlay.tar'))
 
46
    for member in tar:
 
47
        tar.extract(member, WIKI)
 
48
    tar.close()
 
49
 
 
50
 
 
51
def run(skip_if_existing=False):
 
52
    try:
 
53
        os.makedirs(WIKI)
 
54
    except OSError, e:
 
55
        if e.errno != errno.EEXIST:
 
56
            raise
 
57
 
 
58
    if skip_if_existing and os.path.exists(os.path.join(WIKI, 'data')):
 
59
        return
 
60
    removeTestWiki()
 
61
    copyData()
 
62
    untarUnderlay()
 
63
 
 
64
if __name__ == '__main__':
 
65
    run()
 
66