1
2
3 """
4 load, quit, version, help plugins
5
6 Plugin read by omero.cli.Cli during initialization. The method(s)
7 defined here will be added to the Cli class for later use.
8
9 The load plugin is used to read in files with omero cli commands
10 (omitting the omero). For example,
11
12 ./omero load some/file.osh
13
14 The help, quit, and version plugins are self-explanatory.
15
16 Copyright 2008 Glencoe Software, Inc. All rights reserved.
17 Use is subject to license terms supplied in LICENSE.txt
18
19 """
20
21 import sys
22
23 from omero_ext.argparse import FileType
24
25 from omero.cli import BaseControl
26 from omero.cli import CLI
27 from omero.cli import VERSION
28
29
31
33 self.ctx.exit("", newline=False)
34
35
40
41
43
48
50 for file in args.infile:
51 self.ctx.dbg("Loading file %s" % file)
52 for line in file:
53 self.ctx.invoke(line)
54
55
91
92
94 """
95 Defined here since the background loading might be too
96 slow to have all help available
97 """
98
106
107 - def _complete(self, text, line, begidx, endidx):
108 """
109 This is something of a hack. This should either be a part
110 of the context interface, or we should put it somewhere
111 in a utility. FIXME.
112 """
113 return self.ctx.completenames(text, line, begidx, endidx)
114
116
117 self.ctx.waitForPlugins()
118
119
120
121 commands, topics = [
122 self.__parser__._format_list(x) for x in
123 [sorted(self.ctx.controls), sorted(self.ctx.topics)]]
124
125 if args.all:
126 for control in sorted(self.ctx.controls):
127 self.ctx.out("*" * 80)
128 self.ctx.out(control)
129 self.ctx.out("*" * 80)
130 self.ctx.invoke([control, "-h"])
131 self.ctx.out("\n")
132 for topic in sorted(self.ctx.topics):
133 self.ctx.out("*" * 80)
134 self.ctx.out(topic)
135 self.ctx.out("*" * 80)
136 self.ctx.out(self.ctx.topics[topic])
137 self.ctx.out("\n")
138 elif not args.topic:
139
140 key_list = {"program_name": sys.argv[0], "version": VERSION,
141 "commands": commands, "topics": topics}
142 print """usage: %(program_name)s <command> [options] args
143 See 'help <command>' or '<command> -h' for more information on syntax
144 Type 'quit' to exit
145
146 Available commands:
147 %(commands)s
148
149 Other help topics:
150 %(topics)s
151
152 For additional information, see:
153 http://www.openmicroscopy.org/site/support/omero4/users/\
154 command-line-interface.html
155 Report bugs to <ome-users@lists.openmicroscopy.org.uk>
156 """ % key_list
157
158 else:
159 try:
160 print 1
161 self.ctx.controls[args.topic]
162 self.ctx.invoke("%s -h" % args.topic)
163 except KeyError:
164 try:
165 self.ctx.out(self.ctx.topics[args.topic])
166 except KeyError:
167 self.ctx.err("Unknown help topic: %s" % args.topic)
168
169 controls = {
170 "help": (HelpControl, "Syntax help for all commands"),
171 "quit": (QuitControl, "Quit application"),
172 "shell": (ShellControl, """Starts an IPython interpreter session
173
174 All arguments not understood vi %(prog)s will be passed to the shell.
175 Use "--" to end parsing, e.g. '%(prog)s -- --help' for IPython help"""),
176 "version": (VersionControl, "Version number"),
177 "load": (LoadControl, """Load file as if it were sent on standard in.
178
179 This can be used as the #! header of a file to make standand-alone script.
180
181 Examples:
182 #!/usr/bin/env omero load
183 login -C root@localhost
184 group add new_group
185 user add foo some user new_group
186
187 or
188
189 $ bin/omero login # login can't take place in HERE-document
190 $ bin/omero load <<EOF
191 user list
192 group list
193 EOF
194
195 """)
196 }
197
198 try:
199 for k, v in controls.items():
200 register(k, v[0], v[1])
201 except NameError:
202 if __name__ == "__main__":
203 cli = CLI()
204 for k, v in controls.items():
205 cli.register(k, v[0], v[1])
206 cli.invoke(sys.argv[1:])
207