1
2 """
3 script plugin
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 script plugin is used to run arbitrary blitz scripts which
9 take as their sole input Ice configuration arguments, including
10 --Ice.Config=file1,file2.
11
12 The first parameter, the script itself, should be natively executable
13 on a given platform. I.e. invokable by subprocess.call([file,...])
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 subprocess, os, sys
21 from omero.cli import BaseControl
22 from omero_ext.strings import shlex
23
25
26 - def help(self, args = None):
27 self.ctx.out("""
28 Syntax: %(program_name)s script file [configuration parameters]
29 Executes a file as a script. Can be used to test scripts
30 for later deployment on the grid.
31 """)
32
34 args = Arguments(*args)
35
36 if hasattr(self, "secure"):
37 self.ctx.err("Secure cli cannot execture python scripts")
38
39 if len(args) < 1:
40 self.ctx.err("No file given")
41
42 env = os.environ
43 env["PYTHONPATH"] = self.ctx.pythonpath()
44 p = subprocess.Popen(args,env=os.environ)
45 p.wait()
46 if p.poll() != 0:
47 self.ctx.die(p.poll(), "Execution failed.")
48
49 try:
50 register("script", ScriptControl)
51 except NameError:
52 ScriptControl()._main()
53