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 Arguments, BaseControl, CLI, VERSION, OMERODIR 
12  import omero.java 
13   
14  START_CLASS="ome.formats.importer.cli.CommandLineImporter" 
15  TEST_CLASS="ome.formats.test.util.TestEngine" 
16   
17 -class ImportControl(BaseControl):
18
19 - def __init__(self, ctx, dir = OMERODIR):
20 BaseControl.__init__(self, ctx, dir) 21 self.command = [ START_CLASS ]
22
23 - def _run(self, args = []):
24 args = Arguments(args) 25 client_dir = self.ctx.dir / "lib" / "client" 26 log4j = "-Dlog4j.configuration=log4j-cli.properties" 27 classpath = [ file.abspath() for file in client_dir.files("*.jar") ] 28 xargs = [ log4j, "-Xmx1024M", "-cp", os.pathsep.join(classpath) ] 29 30 # Here we permit passing ---file=some_output_file in order to 31 # facilitate the omero.util.import_candidates.as_dictionary 32 # call. This may not always be necessary. 33 out = None 34 err = None 35 for i in args.args: 36 if i.startswith("---file="): 37 out = i 38 if i.startswith("---errs="): 39 err = i 40 if out: 41 args.args.remove(out) 42 out = open(out[8:], "w") 43 if err: 44 args.args.remove(err) 45 err = open(err[8:], "w") 46 47 p = omero.java.popen(self.command + args.args, debug=False, xargs = xargs, stdout=out, stderr=err) 48 self.ctx.rv = p.wait()
49
50 - def help(self, args = None):
51 self._run() # Prints help by default
52
53 - def __call__(self, *args):
54 args = Arguments(*args) 55 self._run(args)
56 57
58 -class TestEngine(ImportControl):
59
60 - def __init__(self, ctx, dir = OMERODIR):
61 ImportControl.__init__(self, ctx, dir) 62 self.command = [ TEST_CLASS ]
63 64 try: 65 register("import", ImportControl) 66 register("testengine", TestEngine) 67 except NameError: 68 ImportControl(None)._main() 69