source: sage/server/wiki/moin.py @ 2438:caaaac815dd7

Revision 2438:caaaac815dd7, 4.5 KB checked in by William Stein <wstein@…>, 6 years ago (diff)

Fix some issues with moin moin.

Line 
1import os, sys
2
3import sage.misc.misc as misc
4
5from   sage.misc.viewer     import browser
6
7def wiki_create_instance(directory='sage_wiki'):
8    try:
9        from MoinMoin.server.standalone import StandaloneConfig, run
10    except ImportError:
11        print "You must install the optional moin package."
12        print "Try something like install_package('moin-1.5.6'),"
13        print "but note that the package name may have a different"
14        print "version.  Use optional_packages() to get a list"
15        print "of current package names."
16        return 
17
18    share = '%s/share/moin'%misc.SAGE_LOCAL
19   
20    if os.path.exists(directory):
21        print "Directory '%s' already exists."%directory
22        return 
23
24    os.makedirs(directory)
25    os.system('cp -r %s/data %s/'%(share,directory))
26    os.system('cp -r %s/underlay %s'%(share,directory))
27    os.system('cp %s/config/wikiconfig.py %s/'%(share,directory))
28    os.system('cp %s/server/moin.py %s/'%(share,directory))
29
30
31def wiki(directory='sage_wiki',
32         port=9000,
33         address='localhost',
34         open_viewer = False):
35    r"""
36    Create (if necessary) and start up a Moin Moin wiki.
37
38    The wiki will be served on the given port.
39
40    The moin package contains a modified version of moin moin, which
41    comes with jsmath latex typesetting preconfigured; use $'s and
42    $$'s to typeset.
43    """
44    sys.path.insert(0, os.path.abspath(directory))
45   
46    try:
47        from MoinMoin.server.standalone import StandaloneConfig, run
48    except ImportError:
49        print "You must install the optional moin package."
50        print "Try something like install_package('moin-1.5.4'),"
51        print "but note that the package name may have a different"
52        print "version.  Use optional_packages() to get a list"
53        print "of current package names."
54        return False
55
56    if not os.path.exists(directory):
57        wiki_create_instance(directory)
58    os.chdir(directory)
59   
60    moin = '%s/share/moin/'%misc.SAGE_LOCAL
61    the_port = port
62
63    class Config(StandaloneConfig):
64        # Server name
65        # Used to create .log, .pid and .prof files
66        name = 'moin'
67
68        # Path to moin shared files (default '/usr/share/moin/wiki/htdocs')
69        # If you installed with --prefix=PREFIX, use 'PREFIX/share/moin/wiki/htdocs'
70        docs = '%s/htdocs'%moin
71
72        # Port
73        port = the_port
74
75        # To serve privileged port under 1024 you will have to run as root.
76        # Interface (default 'localhost')
77        # The default will listen only to localhost.
78        # '' will listen to any interface
79        interface = address
80
81        # Log (default commented)
82        # Log is written to stderr or to a file you specify here.
83        ## logPath = name + '.log'
84
85        # Server class (default ThreadPoolServer)
86        # 'ThreadPoolServer' - create a constant pool of threads, simplified
87        # Apache worker mpm.
88        # 'ThreadingServer' - serve each request in a new thread. Much
89        # slower for static files.
90        # 'ForkingServer' - serve each request on a new child process -
91        # experimental, slow.
92        # 'SimpleServer' - server one request at a time. Fast, low
93        # memory footprint.
94        # If you set one of the threading servers and threads are not
95        # available, the server will fallback to ForkingServer. If fork is
96        # not available, the server will fallback to SimpleServer.
97        serverClass = 'ThreadPoolServer'
98
99        # Thread limit (default 10)
100        # Limit the number of threads created. Ignored on non threaded servers.
101        threadLimit = 10
102
103        # Request queue size (default 50)
104        # The size of the socket listen backlog.
105        requestQueueSize = 50
106
107        # Properties
108        # Allow overriding any request property by the value defined in
109        # this dict e.g properties = {'script_name': '/mywiki'}.
110        properties = {}
111       
112        # Memory profile (default commented)
113        # Useful only if you are a developer or interested in moin memory usage
114        # A memory profile named 'moin--2004-09-27--01-24.log' is
115        # created each time you start the server.
116        ## from MoinMoin.util.profile import Profiler
117        ## memoryProfile = Profiler(name, requestsPerSample=100, collect=0)
118
119        # Hotshot profile (default commented)
120        # Not compatible with threads - use with SimpleServer only.
121        ## hotshotProfile = name + '.prof'
122
123
124    if open_viewer:
125        cmd = '%s http://%s:%s 1>&2 >/dev/null &'%(browser(), address, port)
126        os.system(cmd)
127
128    run(Config)
129    return True
Note: See TracBrowser for help on using the repository browser.