Package omero :: Package plugins :: Module import
[hide private]
[frames] | no frames]

Source Code for Module omero.plugins.import

  1  #!/usr/bin/env python 
  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   
34 -class ImportControl(BaseControl):
35 36 COMMAND = [START_CLASS] 37
38 - def _configure(self, parser):
39 parser.add_argument("--javahelp", action="store_true", help="Show the Java help text") 40 parser.add_argument("---file", nargs="?", help="File for storing the standard out of the Java process") 41 parser.add_argument("---errs", nargs="?", help="File for storing the standard err of the Java process") 42 # The following arguments are strictly passed to Java 43 parser.add_argument("-f", dest="java_f", action="store_true", help="Display used files (**)") 44 parser.add_argument("-c", dest="java_c", action="store_true", help="Continue importing after errors (**)") 45 parser.add_argument("-l", dest="java_l", help="Use the list of readers rather than the default (**)", metavar="READER_FILE") 46 parser.add_argument("-d", dest="java_d", help="OMERO dataset Id to import image into (**)", metavar="DATASET_ID") 47 parser.add_argument("-r", dest="java_r", help="OMERO screen Id to import plate into (**)", metavar="SCREEN_ID") 48 parser.add_argument("-n", dest="java_n", help="Image name to use (**)", metavar="NAME") 49 parser.add_argument("-x", dest="java_x", help="Image description to use (**)", metavar="DESCRIPTION") 50 parser.add_argument("--report", action="store_true", dest="java_report", help="Report errors to the OME team (**)") 51 parser.add_argument("--upload", action="store_true", dest="java_upload", help="Upload broken files with report (**)") 52 parser.add_argument("--logs", action="store_true", dest="java_logs", help="Upload log file with report (**)") 53 parser.add_argument("--email", dest="java_email", help="Email for reported errors (**)", metavar="EMAIL") 54 parser.add_argument("--debug", dest="java_debug", help="Turn debug logging on (**; must be preceded by '--')",\ 55 choices=["ALL","DEBUG","ERROR","FATAL","INFO","TRACE","WARN"], metavar="LEVEL") 56 parser.add_argument("arg", nargs="*", help="Arguments to be passed to the Java process") 57 parser.set_defaults(func=self.importer)
58 59
60 - def importer(self, args):
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 # Here we permit passing ---file=some_output_file in order to 68 # facilitate the omero.util.import_candidates.as_dictionary 69 # call. This may not always be necessary. 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 # Due to the use of "--" some of these like debug 91 # will never be filled out. But for completeness 92 # sake, we include them here. 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
119 -class TestEngine(ImportControl):
120 COMMAND = [ TEST_CLASS ]
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