|
72 |
@file_upload |
72 |
@file_upload |
73 |
def upload(self, request): |
73 |
def upload(self, request): |
74 |
# make sure that we got a list |
74 |
# make sure that we got a list |
|
|
75 |
MODULE.info('### upload: %r' % (request, )) |
76 |
MODULE.info('### upload options: %r' % (request.options, )) |
75 |
if not isinstance(request.options, (tuple, list)): |
77 |
if not isinstance(request.options, (tuple, list)): |
76 |
raise UMC_OptionTypeError( 'Expected list of dicts, but got: %s' % str(request.options) ) |
78 |
raise UMC_OptionTypeError( 'Expected list of dicts, but got: %s' % str(request.options) ) |
77 |
file = request.options[0] |
|
|
78 |
if not ('tmpfile' in file and 'filename' in file): |
79 |
raise UMC_OptionTypeError( 'Invalid upload data, got: %s' % str(file) ) |
80 |
|
79 |
|
81 |
# create a temporary upload directory, if it does not already exist |
80 |
#file = request.options[0] |
82 |
if not self._tmpDir: |
81 |
for file in request.options: |
83 |
self._tmpDir = tempfile.mkdtemp(prefix='ucsschool-distribution-upload-') |
82 |
if not ('tmpfile' in file and 'filename' in file): |
84 |
MODULE.info('Created temporary directory: %s' % self._tmpDir) |
83 |
raise UMC_OptionTypeError( 'Invalid upload data, got: %s' % str(file) ) |
85 |
|
84 |
|
86 |
filename = self.__workaround_filename_bug(file) |
85 |
# create a temporary upload directory, if it does not already exist |
87 |
destPath = os.path.join(self._tmpDir, filename) |
86 |
if not self._tmpDir: |
88 |
MODULE.info('Received file %r, saving it to %r' % (file['tmpfile'], destPath)) |
87 |
self._tmpDir = tempfile.mkdtemp(prefix='ucsschool-distribution-upload-') |
89 |
shutil.move(file['tmpfile'], destPath) |
88 |
MODULE.info('Created temporary directory: %s' % self._tmpDir) |
90 |
|
89 |
|
|
|
90 |
filename = self.__workaround_filename_bug(file) |
91 |
destPath = os.path.join(self._tmpDir, filename) |
92 |
MODULE.info('Received file %r, saving it to %r' % (file['tmpfile'], destPath)) |
93 |
shutil.move(file['tmpfile'], destPath) |
94 |
|
91 |
# done |
95 |
# done |
92 |
self.finished( request.id, None ) |
96 |
self.finished( request.id, None ) |
93 |
|
97 |
|
|
124 |
'distributed': True|False |
128 |
'distributed': True|False |
125 |
} |
129 |
} |
126 |
''' |
130 |
''' |
|
|
131 |
###TODO: remove me |
132 |
MODULE.info ('### Request: %r' % (request, )) |
133 |
MODULE.info ('### Request.options: %r' % (request.options, )) |
134 |
self.finished( request.id, True ) |
135 |
return |
127 |
|
136 |
|
128 |
if not 'filenames' in request.options or not 'project' in request.options: |
137 |
if not 'filenames' in request.options or not 'project' in request.options: |
129 |
raise UMC_OptionTypeError( 'Expected dict with entries "filenames" and "project", but got: %s' % request.options ) |
138 |
raise UMC_OptionTypeError( 'Expected dict with entries "filenames" and "project", but got: %s' % request.options ) |