diff --git a/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/__init__.py b/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/__init__.py index 8330c28..30602e5 100644 --- a/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/__init__.py +++ b/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/__init__.py @@ -83,10 +83,26 @@ def upload(self, request): self._tmpDir = tempfile.mkdtemp(prefix='ucsschool-distribution-upload-') MODULE.info('Created temporary directory: %s' % self._tmpDir) - # we got an uploaded file with the following properties: - # name, filename, tmpfile - destPath = os.path.join(self._tmpDir, file['filename']) - MODULE.info('Received file "%s", saving it to "%s"' % (file['tmpfile'], destPath)) + ### the following code block is a heuristic to support both: fixed and unfixed Bug #37716 + filename = file['filename'] + try: + # The UMC-Webserver decodes filename in latin-1, need to revert + filename = filename.encode('ISO8859-1') + except UnicodeEncodeError: + # we got non-latin characters, Bug #37716 is fixed and string contains e.g. '→' + filename = file['filename'].encode('UTF-8') + else: + # the string contains at least no non-latin1 characters + try: + # try if the bytes could be UTF-8 + # can't fail if Bug #37716 is fixed + filename.decode('UTF-8') + except UnicodeDecodeError: + filename = file['filename'].encode('UTF-8') # Bug #37716 was fixed + MODULE.info('Detected filename %r as %r' % (file['filename'], filename)) + ### the code block can be removed and replaced by filename = file['filename'].encode('UTF-8') after Bug #37716 + destPath = os.path.join(self._tmpDir, filename) + MODULE.info('Received file %r, saving it to %r' % (file['tmpfile'], destPath)) shutil.move(file['tmpfile'], destPath) # done @@ -117,6 +133,7 @@ def checkfiles(self, request): result = [] for ifile in request.options.get('filenames'): + ifile = ifile.encode('UTF-8') # check whether file has already been upload in this session iresult = dict(sessionDuplicate = False, projectDuplicate = False, distributed = False) iresult['filename'] = ifile @@ -191,6 +208,9 @@ def _save( self, request, doUpdate = True, ldap_user_read = None, ldap_position for k in ('atJobNumCollect', 'atJobNumDistribute'): iprops.pop(k, None) + # transform filenames into bytestrings + iprops['files'] = [f.encode('UTF-8') for f in iprops.get('files', [])] + # load the project or create a new one project = None orgProject = None diff --git a/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/util.py b/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/util.py index 7a73faa..6fc27a2 100644 --- a/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/util.py +++ b/ucs-school-4.0/ucs-school-umc-distribution/umc/python/distribution/util.py @@ -403,9 +403,7 @@ def isNameInUse(self): # check whether a project directory with the given name exists in the # recipients' home directories - l = [ iuser for iuser in self.getRecipients() if os.path.exists( self.user_projectdir( iuser ) ) ] - - return len( l ) > 0 + return any(iuser for iuser in self.getRecipients() if os.path.exists(self.user_projectdir(iuser))) def save(self): '''Save project data to disk and create job. In case of any errors, an IOError is raised.'''