1
2 """
3 Startup plugin for command-line importer.
4
5 Copyright 2009 Glencoe Software, Inc. All rights reserved.
6 Use is subject to license terms supplied in LICENSE.txt
7
8 """
9
10 import subprocess, optparse, os, sys, signal, time
11 from omero.cli import BaseControl, CLI, OMERODIR
12 import omero.java
13
14 START_CLASS="ome.formats.importer.cli.CommandLineImporter"
15 TEST_CLASS="ome.formats.test.util.TestEngine"
16
17 HELP = """Run the Java-based command-line importer
18
19 This is a Python wrapper around the Java importer. Login is handled
20 by Python OmeroCli. To see more options, use "--javahelp".
21
22 Options marked with "**" are passed strictly to Java. If they interfere
23 with any of the Python arguments, you may need to end precede your arguments
24 with a "--".
25
26 Examples:
27
28 bin/omero login ~/Data/my_file.dv # Use current login
29 bin/omero login -- --debug=ALL ~/Data/my_file2.png # Set Java debug
30
31 """
32 TESTHELP = """Run the Importer TestEngine suite (devs-only)"""
33
35
36 COMMAND = [START_CLASS]
37
58
59
61
62 client_dir = self.ctx.dir / "lib" / "client"
63 log4j = "-Dlog4j.configuration=log4j-cli.properties"
64 classpath = [ file.abspath() for file in client_dir.files("*.jar") ]
65 xargs = [ log4j, "-Xmx1024M", "-cp", os.pathsep.join(classpath) ]
66
67
68
69
70 out = args.file
71 err = args.errs
72
73 if out:
74 args.args.remove(out)
75 out = open(out, "w")
76 if err:
77 args.args.remove(err)
78 err = open(err, "w")
79
80 login_args = []
81 if args.javahelp:
82 login_args.append("-h")
83
84 if "-h" not in login_args and "-f" not in login_args:
85 client = self.ctx.conn(args)
86 srv = client.getProperty("omero.host")
87 login_args.extend(["-s", srv])
88 login_args.extend(["-k", client.getSessionId()])
89
90
91
92
93 java_args = {
94 "java_f": "-f",
95 "java_c": "-c",
96 "java_l": "-l",
97 "java_d": "-d",
98 "java_r": "-r",
99 "java_r": "-r",
100 "java_n": "-n",
101 "java_x": "-x",
102 "java_report": "--report",
103 "java_upload": "--upload",
104 "java_logs": "--logs",
105 "java_email": "--email",
106 "java_debug": "--debug" }
107
108 for attr_name, arg_name in java_args.items():
109 arg_value = getattr(args, attr_name)
110 if arg_value:
111 login_args.append(arg_name)
112 if isinstance(arg_value, (str, unicode)):
113 login_args.append(arg_value)
114
115 a = self.COMMAND + login_args + args.arg
116 p = omero.java.popen(a, debug=False, xargs = xargs, stdout=out, stderr=err)
117 self.ctx.rv = p.wait()
118
121
122 try:
123 register("import", ImportControl, HELP)
124 register("testengine", TestEngine, TESTHELP)
125 except NameError:
126 if __name__ == "__main__":
127 cli = CLI()
128 cli.register("import", ImportControl, HELP)
129 cli.register("testengine", TestEngine, TESTHELP)
130 cli.invoke(sys.argv[1:])
131