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

Source Code for Module omero.plugins.upload

 1  #!/usr/bin/env python 
 2  """ 
 3     upoad 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     Copyright 2007 Glencoe Software, Inc. All rights reserved. 
 9     Use is subject to license terms supplied in LICENSE.txt 
10   
11  """ 
12   
13  import sys, re 
14   
15  from omero.cli import BaseControl, CLI 
16   
17  import omero 
18  import omero.rtypes 
19  import omero.util.originalfileutils 
20   
21  from omero.rtypes import rlong 
22  from omero.rtypes import rint 
23  from omero.rtypes import rstring 
24  from omero.rtypes import rdouble 
25  from omero.rtypes import rfloat 
26   
27   
28  try: 
29      import hashlib 
30      hash_sha1 = hashlib.sha1 
31  except: 
32      import sha 
33      hash_sha1 = sha.new 
34   
35  HELP = """Upload local files to the OMERO server""" 
36  RE = re.compile("\s*upload\s*") 
37   
38 -class UploadControl(BaseControl):
39
40 - def _complete(self, text, line, begidx, endidx):
41 """ 42 Returns a file after "upload" and otherwise delegates to the BaseControl 43 """ 44 m = RE.match(line) 45 if m: 46 return self._complete_file(RE.sub('', line)) 47 else: 48 return BaseControl._complete(self, text, line, begidx, endidx)
49
50 - def _configure(self, parser):
51 parser.add_argument("--pytable", action="store_true", help="If set, the following files are interpreted as pytable files" ) 52 parser.add_argument("file", nargs="+") 53 parser.set_defaults(func=self.upload)
54
55 - def upload(self, args):
56 client = self.ctx.conn(args) 57 for file in args.file: 58 is_importer, omero_format = omero.util.originalfileutils.getFormat(file) 59 if (is_importer == omero.util.originalfileutils.IMPORTER): 60 self.ctx.dir(493, "This file should be imported using omero import") 61 else: 62 obj = client.upload(file, type=omero_format) 63 self.ctx.out("Uploaded %s as " % file + str(obj.id.val)) 64 self.ctx.set("last.upload.id", obj.id.val)
65 66 try: 67 register("upload", UploadControl, HELP) 68 except NameError: 69 if __name__ == "__main__": 70 cli = CLI() 71 cli.register("upload", UploadControl, HELP) 72 cli.invoke(sys.argv[1:]) 73