1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - Command line utilities
5
@copyright: 2000, 2001, 2002 by J�rgen Hermann <jh@web.de>,
6
2006 MoinMoin:ThomasWaldmann
7
@license: GNU GPL, see COPYING for details.
14
#############################################################################
16
#############################################################################
18
def fatal(msgtext, **kw):
19
""" Print error msg to stderr and exit. """
20
sys.stderr.write("FATAL ERROR: " + msgtext + "\n")
25
""" Optionally print error msg to stderr. """
27
sys.stderr.write(msgtext + "\n")
30
#############################################################################
31
### Commandline Support
32
#############################################################################
35
def __init__(self, cmd, usage, argv=None, def_values=None):
36
#print "argv:", argv, "def_values:", repr(def_values)
38
self.argv = sys.argv[1:]
41
self.def_values = def_values
44
_start_time = time.clock()
47
from MoinMoin import version
49
rev = "%s %s [%s]" % (version.project, version.release, version.revision)
52
self.parser = optparse.OptionParser(
53
usage="%(cmd)s %(usage)s\n\n" % {'cmd': cmd, 'usage': usage, },
55
self.parser.allow_interspersed_args = False
57
self.parser.set_defaults(**def_values.__dict__)
58
self.parser.add_option(
60
action="store_true", dest="quiet",
61
help="Be quiet (no informational messages)"
63
self.parser.add_option(
65
action="store_true", dest="show_timing", default=False,
66
help="Show timing values [default: False]"
69
def run(self, showtime=1):
70
""" Run the main function of a command. """
74
self.options, self.args = self.parser.parse_args(self.argv)
75
flag_quiet = self.options.quiet
77
except KeyboardInterrupt:
78
log("*** Interrupted by user!")
87
""" Print the total command run time. """
88
if self.options.show_timing:
89
log("Needed %.3f secs." % (time.clock() - _start_time,))
92
class MoinScript(Script):
93
""" Moin main script class """
95
def __init__(self, argv=None, def_values=None):
96
Script.__init__(self, "moin", "[general options] command subcommand [specific options]", argv, def_values)
97
# those are options potentially useful for all sub-commands:
98
self.parser.add_option(
99
"--config-dir", metavar="DIR", dest="config_dir",
100
help=("Path to the directory containing the wiki "
101
"configuration files. [default: current directory]")
103
self.parser.add_option(
104
"--wiki-url", metavar="WIKIURL", dest="wiki_url",
105
help="URL of a single wiki to migrate e.g. localhost/mywiki/ [default: CLI]"
107
self.parser.add_option(
108
"--page", dest="page", default='',
109
help="wiki page name or regex [default: all pages]"
112
def init_request(self):
113
""" create request """
114
from MoinMoin.request import RequestCLI
115
if self.options.wiki_url:
116
self.request = RequestCLI(self.options.wiki_url, self.options.page)
118
self.request = RequestCLI(pagename=self.options.page)
121
# Insert config dir or the current directory to the start of the path.
122
config_dir = self.options.config_dir
123
if config_dir and not os.path.isdir(config_dir):
124
fatal("bad path given to --config-dir option")
125
sys.path.insert(0, os.path.abspath(config_dir or os.curdir))
129
self.parser.error("""You must specify a command module and name:
131
moin ... account check ...
132
moin ... account create ...
133
moin ... account disable ...
135
moin ... cli show ...
137
moin ... export dump ...
139
moin ... import irclog ...
141
moin ... lupy build ...
142
moin ... lupy optimize ...
144
moin ... maint cleancache ...
145
moin ... maint cleanpage ...
146
moin ... maint globaledit ...
147
moin ... maint mkpagepacks ...
148
moin ... maint reducewiki ...
150
moin ... migration data ...
153
Most commands need some general parameters before command subcommand:
154
--config-dir=/config/directory
155
Mandatory for most commands and specifies the directory that contains
156
your wikiconfig.py (or farmconfig.py).
158
--wiki-url=wiki.example.org/
159
Mandatory for most commands and specifies the url of the wiki you like
163
Most commands need additional parameters after command subcommand.
165
Sorry, but there is not much docs about that stuff yet, you can check
166
docs/CHANGES and the MoinMoin wiki site for more infos (or just try to
167
invoke some command/subcommand to see if it emits more help).
168
The code you invoke is contained in MoinMoin/script/command/subcommand.py,
169
so just reading the comments / source there might help you, too.
173
cmd_module, cmd_name = args[:2]
174
from MoinMoin import wikiutil
175
plugin_class = wikiutil.importBuiltinPlugin('script.%s' % cmd_module, cmd_name, 'PluginScript')
176
plugin_class(args[2:], self.options).run() # all starts again there