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

Source Code for Module omero.plugins.upload

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