1
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 from omero.cli import BaseControl
14 import omero.util.originalfileutils;
15 import omero;
16 import omero.rtypes
17 from omero.rtypes import rlong
18 from omero.rtypes import rint
19 from omero.rtypes import rstring
20 from omero.rtypes import rdouble
21 from omero.rtypes import rfloat
22
23
24 try:
25 import hashlib
26 hash_sha1 = hashlib.sha1
27 except:
28 import sha
29 hash_sha1 = sha.new
30
32
33 - def help(self, args = None):
34 return \
35 """
36 Syntax: %(program_name)s upload <filename> [1..n]
37 Upload the given files to omero.
38
39 Syntax: %(program_name)s upload script
40 Upload default scripts defined in default scripts to the server.
41
42 Syntax: %(program_name)s upload pytable <filename> [1..n]
43 Upload the given files to pytables in omero.
44
45 """
46 SCRIPT_ARG='scripts';
47 PYTABLE_ARG='pytable';
48 FILE_ARG='files';
49
51 fileHandle = open(filename)
52 h = hash_sha1()
53 h.update(fileHandle.read())
54 hash = h.hexdigest()
55 fileHandle.close()
56 return hash;
57
78
79 - def uploadFile(self, filename, originalFile = None):
85
92
105
107 if(filename[len(filename)-3:] == 'pyc'):
108 return filename[:len(filename)-1]
109 return filename;
110
112 import defaultscripts;
113 scripts = defaultscripts.defaultscripts;
114 for id in scripts:
115 script = scripts[id];
116 filename = "";
117 try:
118 importedScript = __import__(script);
119 filename = self.returnSource(importedScript.__file__);
120 except:
121 raise Exception("Script: " + script + " does not exist");
122 if not filename:
123 raise Exception("Non-null filename must be provided")
124
125 if not os.path.exists(filename):
126 raise Exception("File does not exist: " + filename)
127
128 originalFile = self.createOriginalFile(None, script, filename);
129 self.uploadFile(filename, originalFile);
130
132 fileList = commandline[self.FILE_ARG];
133 for file in fileList:
134 obj = self.uploadFile(file);
135 self.ctx.out("Uploaded %s as " % file + str(obj.id.val))
136
137
150
151 try:
152 register("upload", UploadControl)
153 except NameError:
154 UploadControl()._main()
155