annotate MoinMoin/script/__init__.py @ 5704:bbb286a9c138

script: Added MoinScript._update_option_help(). script.import.wikipage: update the --page option help message.
author Pascal Volk <user@localhost.localdomain.org>
date Sun, 06 Jun 2010 18:48:02 +0000
parents 7cd4adbd6c50
children 7c6029d23a18
rev   line source
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
3 MoinMoin - Extension Script Package
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
5 @copyright: 2000-2002 Juergen Hermann <jh@web.de>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
6 2006 MoinMoin:ThomasWaldmann
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
8 """
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
9
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
10 import os, sys, time
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1603
diff changeset
11 from StringIO import StringIO
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
12
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
13 flag_quiet = 0
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
14
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
15 # ScriptRequest -----------------------------------------------------------
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
16
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
17 class ScriptRequest(object):
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
18 """this is for scripts (MoinMoin/script/*) running from the commandline (CLI)
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
19 or from the xmlrpc server (triggered by a remote xmlrpc client).
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
20
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
21 Every script needs to do IO using this ScriptRequest class object -
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
22 IT IS DIFFERENT from the usual "request" you have in moin (easily to be seen
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
23 when you look at an xmlrpc script invocation: request.write will write to the
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
24 xmlrpc "channel", but scriptrequest.write needs to write to some buffer we
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
25 transmit later as an xmlrpc function return value.
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
26 """
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
27 def __init__(self, instream, outstream, errstream):
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
28 self.instream = instream
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1603
diff changeset
29 self.outstream = outstream
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
30 self.errstream = errstream
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
31
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
32 def read(self, n=None):
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
33 if n is None:
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
34 data = self.instream.read()
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
35 else:
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
36 data = self.instream.read(n)
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
37 return data
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
38
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
39 def write(self, data):
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
40 self.outstream.write(data)
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
41
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
42 def write_err(self, data):
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
43 self.errstream.write(data)
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
44
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
45
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
46 class ScriptRequestCLI(ScriptRequest):
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
47 """ When a script runs directly on the shell, we just use the CLI request
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2286
diff changeset
48 object (see MoinMoin.request.request_cli) to do I/O (which will use stdin/out/err).
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
49 """
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
50 def __init__(self, request):
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
51 self.request = request
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
52
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
53 def read(self, n=None):
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
54 return self.request.read(n)
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
55
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
56 def write(self, data):
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1603
diff changeset
57 return self.request.write(data)
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
58
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
59 def write_err(self, data):
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1603
diff changeset
60 return self.request.write(data) # XXX use correct request method - log, error, whatever.
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
61
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
62 class ScriptRequestStrings(ScriptRequest):
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
63 """ When a script gets run by our xmlrpc server, we have the input as a
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
64 string and we also need to catch the output / error output as strings.
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
65 """
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
66 def __init__(self, instr):
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
67 self.instream = StringIO(instr)
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
68 self.outstream = StringIO()
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
69 self.errstream = StringIO()
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
70
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
71 def fetch_output(self):
951
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
72 outstr = self.outstream.get_value()
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
73 errstr = self.errstream.get_value()
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
74 self.outstream.close()
b8c1bb917748 fixed usage of reserved keyword in new (unused) scriptrequest classes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 934
diff changeset
75 self.errstream.close()
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
76 return outstr, errstr
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
77
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
78
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
79 # Logging -----------------------------------------------------------------
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
80
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
81 def fatal(msgtext, **kw):
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
82 """ Print error msg to stderr and exit. """
708
09cd69e5de6d merge moin/1.6 main branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
83 sys.stderr.write("\n\nFATAL ERROR: " + msgtext + "\n")
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
84 sys.exit(1)
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
85
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
86
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
87 def log(msgtext):
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
88 """ Optionally print error msg to stderr. """
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
89 if not flag_quiet:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
90 sys.stderr.write(msgtext + "\n")
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
91
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
92
934
9dcfb8f36524 call scripts remotely, ScriptRequest infrastructure (unfinished)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
93 # Commandline Support --------------------------------------------------------
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
94
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
95 class Script:
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
96 def __init__(self, cmd, usage, argv=None, def_values=None):
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
97 #print "argv:", argv, "def_values:", repr(def_values)
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
98 if argv is None:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
99 self.argv = sys.argv[1:]
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
100 else:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
101 self.argv = argv
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
102 self.def_values = def_values
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
103
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
104 global _start_time
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
105 _start_time = time.clock()
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
106
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
107 import optparse
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
108 from MoinMoin import version
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
109
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
110 rev = "%s %s [%s]" % (version.project, version.release, version.revision)
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
111 sys.argv[0] = cmd
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
112
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
113 self.parser = optparse.OptionParser(
708
09cd69e5de6d merge moin/1.6 main branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
114 usage="%(cmd)s [command] %(usage)s" % {'cmd': os.path.basename(sys.argv[0]), 'usage': usage, },
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
115 version=rev, add_help_option=False)
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
116 self.parser.allow_interspersed_args = False
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
117 if def_values:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
118 self.parser.set_defaults(**def_values.__dict__)
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
119 self.parser.add_option(
929
da5623bc6819 script: whitespace only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 708
diff changeset
120 "-q", "--quiet",
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
121 action="store_true", dest="quiet",
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
122 help="Be quiet (no informational messages)"
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
123 )
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
124 self.parser.add_option(
929
da5623bc6819 script: whitespace only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 708
diff changeset
125 "--show-timing",
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
126 action="store_true", dest="show_timing", default=False,
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
127 help="Show timing values [default: False]"
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
128 )
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
129
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
130 def run(self, showtime=1):
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
131 """ Run the main function of a command. """
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
132 global flag_quiet
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
133 try:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
134 try:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
135 self.options, self.args = self.parser.parse_args(self.argv)
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
136 flag_quiet = self.options.quiet
3029
9c12ceee3115 script.__init__: ToDo added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3025
diff changeset
137 # ToDo check if we need to initialize request (self.init_request())
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
138 self.mainloop()
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
139 except KeyboardInterrupt:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
140 log("*** Interrupted by user!")
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
141 except SystemExit:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
142 showtime = 0
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
143 raise
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
144 finally:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
145 if showtime:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
146 self.logRuntime()
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
147
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
148 def logRuntime(self):
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
149 """ Print the total command run time. """
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
150 if self.options.show_timing:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
151 log("Needed %.3f secs." % (time.clock() - _start_time, ))
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
152
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
153
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
154 class MoinScript(Script):
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
155 """ Moin main script class """
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
156
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
157 def __init__(self, argv=None, def_values=None):
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
158 Script.__init__(self, "moin", "[general options] command subcommand [specific options]", argv, def_values)
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
159 # those are options potentially useful for all sub-commands:
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
160 self.parser.add_option(
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
161 "--config-dir", metavar="DIR", dest="config_dir",
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
162 help=("Path to the directory containing the wiki "
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
163 "configuration files. [default: current directory]")
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
164 )
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
165 self.parser.add_option(
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
166 "--wiki-url", metavar="WIKIURL", dest="wiki_url",
5154
1eb3596fbd3a add a note to the docs about new --wiki-url requirements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4594
diff changeset
167 help="URL of a single wiki to migrate e.g. http://localhost/mywiki/ [default: CLI]"
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
168 )
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
169 self.parser.add_option(
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
170 "--page", dest="page", default='',
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
171 help="wiki page name [default: all pages]"
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
172 )
929
da5623bc6819 script: whitespace only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 708
diff changeset
173
5704
bbb286a9c138 script: Added MoinScript._update_option_help().
Pascal Volk <user@localhost.localdomain.org>
parents: 5692
diff changeset
174 def _update_option_help(self, opt_string, help_msg):
bbb286a9c138 script: Added MoinScript._update_option_help().
Pascal Volk <user@localhost.localdomain.org>
parents: 5692
diff changeset
175 """ Update the help string of an option. """
bbb286a9c138 script: Added MoinScript._update_option_help().
Pascal Volk <user@localhost.localdomain.org>
parents: 5692
diff changeset
176 for option in self.parser.option_list:
bbb286a9c138 script: Added MoinScript._update_option_help().
Pascal Volk <user@localhost.localdomain.org>
parents: 5692
diff changeset
177 if option.get_opt_string() == opt_string:
bbb286a9c138 script: Added MoinScript._update_option_help().
Pascal Volk <user@localhost.localdomain.org>
parents: 5692
diff changeset
178 option.help = help_msg
bbb286a9c138 script: Added MoinScript._update_option_help().
Pascal Volk <user@localhost.localdomain.org>
parents: 5692
diff changeset
179 break
bbb286a9c138 script: Added MoinScript._update_option_help().
Pascal Volk <user@localhost.localdomain.org>
parents: 5692
diff changeset
180
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
181 def init_request(self):
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
182 """ create request """
4257
29e81e73fe67 Replace request_cli with ScriptContext in MoinScript
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3722
diff changeset
183 from MoinMoin.web.contexts import ScriptContext
4594
d706f5d4f4ec fix ScriptContext URL default value
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4257
diff changeset
184 url = self.options.wiki_url or None
d706f5d4f4ec fix ScriptContext URL default value
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4257
diff changeset
185 self.request = ScriptContext(url, self.options.page)
929
da5623bc6819 script: whitespace only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 708
diff changeset
186
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
187 def mainloop(self):
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
188 # Insert config dir or the current directory to the start of the path.
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
189 config_dir = self.options.config_dir
1603
767109c48208 rearrange testing setup, make moin.py runnable from toplevel dir
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1569
diff changeset
190 if config_dir:
767109c48208 rearrange testing setup, make moin.py runnable from toplevel dir
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1569
diff changeset
191 if os.path.isdir(config_dir):
767109c48208 rearrange testing setup, make moin.py runnable from toplevel dir
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1569
diff changeset
192 sys.path.insert(0, os.path.abspath(config_dir))
767109c48208 rearrange testing setup, make moin.py runnable from toplevel dir
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1569
diff changeset
193 else:
767109c48208 rearrange testing setup, make moin.py runnable from toplevel dir
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1569
diff changeset
194 fatal("bad path given to --config-dir option")
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
195
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
196 args = self.args
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
197 if len(args) < 2:
708
09cd69e5de6d merge moin/1.6 main branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
198 self.parser.print_help()
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
199 fatal("""You must specify a command module and name:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
200
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
201 moin ... account check ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
202 moin ... account create ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
203 moin ... account disable ...
3722
0259bd2d0777 add resetpw script
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3449
diff changeset
204 moin ... account resetpw ...
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
205
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
206 moin ... cli show ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
207
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
208 moin ... export dump ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
209
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
210 moin ... import irclog ...
5692
7cd4adbd6c50 implemented moin import wikipage
Pascal Volk <user@localhost.localdomain.org>
parents: 5437
diff changeset
211 moin ... import wikipage ...
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
212
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
213 moin ... index build ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
214
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
215 moin ... maint cleancache ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
216 moin ... maint cleanpage ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
217 moin ... maint globaledit ...
3449
933bb04c0935 script.maint.makecache: introduced makecache maint module
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
218 moin ... maint makecache ...
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
219 moin ... maint mkpagepacks ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
220 moin ... maint reducewiki ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
221
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
222 moin ... migration data ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
223
3025
ccf6d7ffb310 standalone server integrated into 'moin' script command (moin server standalone --help), thanks to Forrest Voight
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2338
diff changeset
224 moin ... server standalone ...
ccf6d7ffb310 standalone server integrated into 'moin' script command (moin server standalone --help), thanks to Forrest Voight
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2338
diff changeset
225
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
226 moin ... xmlrpc mailimport ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
227 moin ... xmlrpc remote ...
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
228
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
229 General options:
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
230 Most commands need some general parameters before command subcommand:
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
231 --config-dir=/config/directory
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
232 Mandatory for most commands and specifies the directory that contains
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
233 your wikiconfig.py (or farmconfig.py).
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
234
5437
a20de9383481 fix --wiki-url examples, needs http:// now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5154
diff changeset
235 --wiki-url=http://wiki.example.org/
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
236 Mandatory for most commands and specifies the url of the wiki you like
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
237 to operate on.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
238
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
239 Specific options:
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
240 Most commands need additional parameters after command subcommand.
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
241
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
242 To obtain additonal help on a command use 'moin module subcommand --help'
1569
94daf7c80f6a MoinMoin.script: remove some non-working/unused code, add some help text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
243 """)
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
244
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
245 cmd_module, cmd_name = args[:2]
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
246 from MoinMoin import wikiutil
708
09cd69e5de6d merge moin/1.6 main branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
247 try:
09cd69e5de6d merge moin/1.6 main branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
248 plugin_class = wikiutil.importBuiltinPlugin('script.%s' % cmd_module, cmd_name, 'PluginScript')
09cd69e5de6d merge moin/1.6 main branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
249 except wikiutil.PluginMissingError:
09cd69e5de6d merge moin/1.6 main branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
250 fatal("Command plugin %r, command %r was not found." % (cmd_module, cmd_name))
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
251
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
252 # We have to use the args list here instead of optparse, as optparse only
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
253 # deals with things coming before command subcommand.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
254 if "--help" in args or "-h" in args:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
255 print "MoinMoin Help - %s/ %s\n" % (cmd_module, cmd_name)
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
256 print plugin_class.__doc__
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
257 print "Command line reference:"
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
258 print "======================="
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
259 plugin_class(args[2:], self.options).parser.print_help()
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
260 else:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
261 plugin_class(args[2:], self.options).run() # all starts again there
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3029
diff changeset
262