diff --git a/mayan/apps/bootstrap/views.py b/mayan/apps/bootstrap/views.py index 40a4b737e0..694d067b2b 100644 --- a/mayan/apps/bootstrap/views.py +++ b/mayan/apps/bootstrap/views.py @@ -163,8 +163,8 @@ def bootstrap_setup_execute(request, bootstrap_setup_pk): bootstrap_setup.execute() except ExistingData: messages.error(request, _(u'Cannot execute bootstrap setup, there is existing data. Erase all data and try again.')) - except Exception, exc: - messages.error(request, _(u'Error executing bootstrap setup; %s') % exc) + except Exception as exception: + messages.error(request, _(u'Error executing bootstrap setup; %s') % exception) else: messages.success(request, _(u'Bootstrap setup "%s" executed successfully.') % bootstrap_setup) return HttpResponseRedirect(next) @@ -295,8 +295,8 @@ def erase_database_view(request): if request.method == 'POST': try: Cleanup.execute_all() - except Exception, exc: - messages.error(request, _(u'Error erasing database; %s') % exc) + except Exception as exception: + messages.error(request, _(u'Error erasing database; %s') % exception) else: messages.success(request, _(u'Database erased successfully.')) return HttpResponseRedirect(next) diff --git a/mayan/apps/checkouts/views.py b/mayan/apps/checkouts/views.py index 8102d24d03..1e611e122c 100644 --- a/mayan/apps/checkouts/views.py +++ b/mayan/apps/checkouts/views.py @@ -78,8 +78,8 @@ def checkout_document(request, document_pk): document_checkout = form.save(commit=False) document_checkout.user_object = request.user document_checkout.save() - except Exception, exc: - messages.error(request, _(u'Error trying to check out document; %s') % exc) + except Exception as exception: + messages.error(request, _(u'Error trying to check out document; %s') % exception) else: messages.success(request, _(u'Document "%s" checked out successfully.') % document) return HttpResponseRedirect(reverse('checkout_info', args=[document.pk])) @@ -122,8 +122,8 @@ def checkin_document(request, document_pk): document.check_in(user=request.user) except DocumentNotCheckedOut: messages.error(request, _(u'Document has not been checked out.')) - except Exception, exc: - messages.error(request, _(u'Error trying to check in document; %s') % exc) + except Exception as exception: + messages.error(request, _(u'Error trying to check in document; %s') % exception) else: messages.success(request, _(u'Document "%s" checked in successfully.') % document) return HttpResponseRedirect(next) diff --git a/mayan/apps/common/utils.py b/mayan/apps/common/utils.py index 0c8d6ec103..20d921ce9f 100644 --- a/mayan/apps/common/utils.py +++ b/mayan/apps/common/utils.py @@ -78,9 +78,9 @@ def return_attrib(obj, attrib, arguments=None): return result() else: return result - except Exception, err: + except Exception as exception: if settings.DEBUG: - return 'Attribute error: %s; %s' % (attrib, err) + return 'Attribute error: %s; %s' % (attrib, exception) else: pass diff --git a/mayan/apps/common/widgets.py b/mayan/apps/common/widgets.py index a134f788d0..cafcb3e890 100644 --- a/mayan/apps/common/widgets.py +++ b/mayan/apps/common/widgets.py @@ -62,8 +62,8 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple): def exists_with_famfam(path): try: return two_state_template(os.path.exists(path)) - except Exception, exc: - return exc + except Exception as exception: + return exception def two_state_template(state, famfam_ok_icon=u'tick', famfam_fail_icon=u'cross'): diff --git a/mayan/apps/converter/office_converter.py b/mayan/apps/converter/office_converter.py index fd31d13eb6..d94ae91bec 100644 --- a/mayan/apps/converter/office_converter.py +++ b/mayan/apps/converter/office_converter.py @@ -85,9 +85,9 @@ class OfficeConverter(object): try: self.backend.convert(self.input_filepath, self.output_filepath) self.exists = True - except OfficeBackendError, msg: + except OfficeBackendError as exception: # convert exception so that at least the mime type icon is displayed - raise UnknownFileFormat(msg) + raise UnknownFileFormat(exception) def __unicode__(self): return getattr(self, 'output_filepath', None) @@ -140,7 +140,7 @@ class OfficeConverterBackendDirect(object): logger.debug('converted_output: %s' % converted_output) os.rename(converted_output, self.output_filepath) - except OSError, msg: - raise OfficeBackendError(msg) - except Exception, msg: - logger.error('Unhandled exception', exc_info=msg) + except OSError as exception: + raise OfficeBackendError(exception) + except Exception as exception: + logger.error('Unhandled exception', exc_info=exception) diff --git a/mayan/apps/django_gpg/views.py b/mayan/apps/django_gpg/views.py index 21e2720e1d..441775b749 100644 --- a/mayan/apps/django_gpg/views.py +++ b/mayan/apps/django_gpg/views.py @@ -100,8 +100,8 @@ def key_delete(request, fingerprint, key_type): gpg.delete_key(key) messages.success(request, _(u'Key: %s, deleted successfully.') % fingerprint) return HttpResponseRedirect(next) - except Exception, msg: - messages.error(request, msg) + except Exception as exception: + messages.error(request, exception) return HttpResponseRedirect(previous) return render_to_response('generic_confirm.html', { diff --git a/mayan/apps/document_indexing/api.py b/mayan/apps/document_indexing/api.py index a059512543..7504ff6056 100644 --- a/mayan/apps/document_indexing/api.py +++ b/mayan/apps/document_indexing/api.py @@ -81,18 +81,18 @@ def cascade_eval(eval_dict, document, template_node, parent_index_instance=None) if template_node.enabled: try: result = eval(template_node.expression, eval_dict, AVAILABLE_INDEXING_FUNCTIONS) - except Exception, exc: + except Exception as exception: warnings.append(_(u'Error in document indexing update expression: %(expression)s; %(exception)s') % { - 'expression': template_node.expression, 'exception': exc}) + 'expression': template_node.expression, 'exception': exception}) else: if result: index_instance, created = IndexInstanceNode.objects.get_or_create(index_template_node=template_node, value=result, parent=parent_index_instance) # if created: try: fs_create_index_directory(index_instance) - except Exception, exc: + except Exception as exception: warnings.append(_(u'Error updating document index, expression: %(expression)s; %(exception)s') % { - 'expression': template_node.expression, 'exception': exc}) + 'expression': template_node.expression, 'exception': exception}) if template_node.link_documents: suffix = find_lowest_available_suffix(index_instance, document) @@ -105,9 +105,9 @@ def cascade_eval(eval_dict, document, template_node, parent_index_instance=None) try: fs_create_document_link(index_instance, document, suffix) - except Exception, exc: + except Exception as exception: warnings.append(_(u'Error updating document index, expression: %(expression)s; %(exception)s') % { - 'expression': template_node.expression, 'exception': exc}) + 'expression': template_node.expression, 'exception': exception}) index_instance.documents.add(document) @@ -147,7 +147,7 @@ def cascade_document_remove(document, index_instance): warnings.extend(parent_warnings) except DocumentRenameCount.DoesNotExist: return warnings - except Exception, exc: - warnings.append(_(u'Unable to delete document indexing node; %s') % exc) + except Exception as exception: + warnings.append(_(u'Unable to delete document indexing node; %s') % exception) return warnings diff --git a/mayan/apps/document_indexing/filesystem.py b/mayan/apps/document_indexing/filesystem.py index bf6ead9655..0158b92cdf 100644 --- a/mayan/apps/document_indexing/filesystem.py +++ b/mayan/apps/document_indexing/filesystem.py @@ -44,11 +44,11 @@ def fs_create_index_directory(index_instance): target_directory = assemble_path_from_list([FILESYSTEM_SERVING[index_instance.index_template_node.index.name], get_instance_path(index_instance)]) try: os.mkdir(target_directory) - except OSError, exc: - if exc.errno == errno.EEXIST: + except OSError as exception: + if exception.errno == errno.EEXIST: pass else: - raise Exception(_(u'Unable to create indexing directory; %s') % exc) + raise Exception(_(u'Unable to create indexing directory; %s') % exception) def fs_create_document_link(index_instance, document, suffix=0): @@ -58,17 +58,17 @@ def fs_create_document_link(index_instance, document, suffix=0): try: os.symlink(document.file.path, filepath) - except OSError, exc: - if exc.errno == errno.EEXIST: + except OSError as exception: + if exception.errno == errno.EEXIST: # This link should not exist, try to delete it try: os.unlink(filepath) # Try again os.symlink(document.file.path, filepath) - except Exception, exc: - raise Exception(_(u'Unable to create symbolic link, file exists and could not be deleted: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc}) + except Exception as exception: + raise Exception(_(u'Unable to create symbolic link, file exists and could not be deleted: %(filepath)s; %(exception)s') % {'filepath': filepath, 'exception': exception}) else: - raise Exception(_(u'Unable to create symbolic link: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc}) + raise Exception(_(u'Unable to create symbolic link: %(filepath)s; %(exception)s') % {'filepath': filepath, 'exception': exception}) def fs_delete_document_link(index_instance, document, suffix=0): @@ -78,10 +78,10 @@ def fs_delete_document_link(index_instance, document, suffix=0): try: os.unlink(filepath) - except OSError, exc: - if exc.errno != errno.ENOENT: + except OSError as exception: + if exception.errno != errno.ENOENT: # Raise when any error other than doesn't exits - raise Exception(_(u'Unable to delete document symbolic link; %s') % exc) + raise Exception(_(u'Unable to delete document symbolic link; %s') % exception) def fs_delete_index_directory(index_instance): @@ -89,11 +89,11 @@ def fs_delete_index_directory(index_instance): target_directory = assemble_path_from_list([FILESYSTEM_SERVING[index_instance.index_template_node.index.name], get_instance_path(index_instance)]) try: os.removedirs(target_directory) - except OSError, exc: - if exc.errno == errno.EEXIST: + except OSError as exception: + if exception.errno == errno.EEXIST: pass else: - raise Exception(_(u'Unable to delete indexing directory; %s') % exc) + raise Exception(_(u'Unable to delete indexing directory; %s') % exception) def fs_delete_directory_recusive(index): diff --git a/mayan/apps/document_signatures/views.py b/mayan/apps/document_signatures/views.py index 19cfe26e8b..132db4b8e8 100644 --- a/mayan/apps/document_signatures/views.py +++ b/mayan/apps/document_signatures/views.py @@ -94,8 +94,8 @@ def document_signature_upload(request, document_pk): DocumentVersionSignature.objects.add_detached_signature(document, request.FILES['file']) messages.success(request, _(u'Detached signature uploaded successfully.')) return HttpResponseRedirect(next) - except Exception, msg: - messages.error(request, msg) + except Exception as exception: + messages.error(request, exception) return HttpResponseRedirect(previous) else: form = DetachedSignatureForm() @@ -153,8 +153,8 @@ def document_signature_delete(request, document_pk): DocumentVersionSignature.objects.clear_detached_signature(document) messages.success(request, _(u'Detached signature deleted successfully.')) return HttpResponseRedirect(next) - except Exception, exc: - messages.error(request, _(u'Error while deleting the detached signature; %s') % exc) + except Exception as exception: + messages.error(request, _(u'Error while deleting the detached signature; %s') % exception) return HttpResponseRedirect(previous) return render_to_response('generic_confirm.html', { diff --git a/mayan/apps/linking/views.py b/mayan/apps/linking/views.py index 217306dedd..73540fc3ab 100644 --- a/mayan/apps/linking/views.py +++ b/mayan/apps/linking/views.py @@ -33,8 +33,6 @@ logger = logging.getLogger(__name__) def smart_link_action(request): - # Permission.objects.check_permissions(request.user, [PERMISSION_SMART_LINK_VIEW]) - action = request.GET.get('action', None) if not action: @@ -178,7 +176,6 @@ def smart_link_edit(request, smart_link_pk): form = SmartLinkForm(instance=smart_link) return render_to_response('generic_form.html', { - # 'navigation_object_name': 'smart_link', 'object': smart_link, 'form': form, 'title': _(u'Edit smart link: %s') % smart_link @@ -200,10 +197,10 @@ def smart_link_delete(request, smart_link_pk): try: smart_link.delete() messages.success(request, _(u'Smart link: %s deleted successfully.') % smart_link) - except Exception, error: - messages.error(request, _(u'Error deleting smart link: %(smart_link)s; %(error)s.') % { + except Exception as exception: + messages.error(request, _(u'Error deleting smart link: %(smart_link)s; %(exception)s.') % { 'smart_link': smart_link, - 'error': error + 'exception': exception }) return HttpResponseRedirect(next) @@ -315,10 +312,10 @@ def smart_link_condition_delete(request, smart_link_condition_pk): try: smart_link_condition.delete() messages.success(request, _(u'Smart link condition: "%s" deleted successfully.') % smart_link_condition) - except Exception, error: - messages.error(request, _(u'Error deleting smart link condition: %(smart_link_condition)s; %(error)s.') % { + except Exception as exception: + messages.error(request, _(u'Error deleting smart link condition: %(smart_link_condition)s; %(exception)s.') % { 'smart_link_condition': smart_link_condition, - 'error': error + 'exception': exception }) return HttpResponseRedirect(next) diff --git a/mayan/apps/lock_manager/managers.py b/mayan/apps/lock_manager/managers.py index bf8d5133c5..afe3bb4392 100644 --- a/mayan/apps/lock_manager/managers.py +++ b/mayan/apps/lock_manager/managers.py @@ -22,8 +22,8 @@ class LockManager(models.Manager): lock.save(force_insert=True) logger.debug('acquired lock: %s' % name) return lock - except IntegrityError, msg: - logger.debug('IntegrityError: %s', msg) + except IntegrityError as exception: + logger.debug('IntegrityError: %s', exception) # There is already an existing lock # Check it's expiration date and if expired, reset it try: diff --git a/mayan/apps/metadata/forms.py b/mayan/apps/metadata/forms.py index 50da37036f..6bd11a0775 100644 --- a/mayan/apps/metadata/forms.py +++ b/mayan/apps/metadata/forms.py @@ -1,8 +1,8 @@ from __future__ import absolute_import from django import forms -from django.utils.translation import ugettext_lazy as _ from django.forms.formsets import formset_factory +from django.utils.translation import ugettext_lazy as _ from common.widgets import ScrollableCheckboxSelectMultiple @@ -17,7 +17,6 @@ class MetadataForm(forms.Form): # Set form fields initial values if 'initial' in kwargs: self.metadata_type = kwargs['initial'].pop('metadata_type', None) - # self.document_type = kwargs['initial'].pop('document_type', None) # FIXME: # required = self.document_type.documenttypemetadatatype_set.get(metadata_type=self.metadata_type).required @@ -42,15 +41,15 @@ class MetadataForm(forms.Form): choices.insert(0, ('', '------')) self.fields['value'].choices = choices self.fields['value'].required = required - except Exception, err: - self.fields['value'].initial = err + except Exception as exception: + self.fields['value'].initial = exception self.fields['value'].widget = forms.TextInput(attrs={'readonly': 'readonly'}) if self.metadata_type.default: try: self.fields['value'].initial = eval(self.metadata_type.default, AVAILABLE_FUNCTIONS) - except Exception, err: - self.fields['value'].initial = err + except Exception as exception: + self.fields['value'].initial = exception id = forms.CharField(label=_(u'id'), widget=forms.HiddenInput) name = forms.CharField(label=_(u'Name'), @@ -71,7 +70,6 @@ class MetadataRemoveForm(MetadataForm): class MetadataSelectionForm(forms.Form): def __init__(self, *args, **kwargs): - # document_type = kwargs.pop('document_type', None) super(MetadataSelectionForm, self).__init__(*args, **kwargs) document_type = getattr(self, 'initial', {}).get('document_type', None) if document_type: @@ -86,7 +84,6 @@ class MetadataSelectionForm(forms.Form): queryset=MetadataSet.objects.all(), label=_(u'Metadata sets'), required=False, - # widget=forms.widgets.SelectMultiple(attrs={'size': 10, 'class': 'choice_form'}) widget=ScrollableCheckboxSelectMultiple(attrs={'size': 10, 'class': 'choice_form'}) ) @@ -94,7 +91,6 @@ class MetadataSelectionForm(forms.Form): queryset=MetadataType.objects.all(), label=_(u'Metadata'), required=False, - # widget=forms.widgets.SelectMultiple(attrs={'size': 10, 'class': 'choice_form'}) widget=ScrollableCheckboxSelectMultiple(attrs={'size': 10, 'class': 'choice_form'}) ) diff --git a/mayan/apps/navigation/templatetags/navigation_tags.py b/mayan/apps/navigation/templatetags/navigation_tags.py index 54392ae444..fd698ddf29 100644 --- a/mayan/apps/navigation/templatetags/navigation_tags.py +++ b/mayan/apps/navigation/templatetags/navigation_tags.py @@ -105,9 +105,9 @@ def resolve_links(context, links, current_view, current_path, parsed_query_strin new_link['url'] = reverse(link['view'], args=args) if link.get('keep_query', False): new_link['url'] = urlquote(new_link['url'], parsed_query_string) - except NoReverseMatch, err: + except NoReverseMatch as exception: new_link['url'] = '#' - new_link['error'] = err + new_link['error'] = exception elif 'url' in link: if not link.get('dont_mark_active', False): new_link['active'] = link['url'] == current_path diff --git a/mayan/apps/ocr/parsers/__init__.py b/mayan/apps/ocr/parsers/__init__.py index e158f66afa..a145ef53d4 100644 --- a/mayan/apps/ocr/parsers/__init__.py +++ b/mayan/apps/ocr/parsers/__init__.py @@ -116,8 +116,8 @@ class OfficeParser(Parser): else: raise ParserError - except OfficeConversionError, msg: - logger.error(msg) + except OfficeConversionError as exception: + logger.error(exception) raise ParserError