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