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