Update remaining exception syntaxes

This commit is contained in:
Roberto Rosario
2014-07-20 22:44:12 -04:00
parent e9717d9bdd
commit 7321b12c7d
14 changed files with 63 additions and 70 deletions

View File

@@ -163,8 +163,8 @@ def bootstrap_setup_execute(request, bootstrap_setup_pk):
bootstrap_setup.execute() bootstrap_setup.execute()
except ExistingData: except ExistingData:
messages.error(request, _(u'Cannot execute bootstrap setup, there is existing data. Erase all data and try again.')) messages.error(request, _(u'Cannot execute bootstrap setup, there is existing data. Erase all data and try again.'))
except Exception, exc: except Exception as exception:
messages.error(request, _(u'Error executing bootstrap setup; %s') % exc) messages.error(request, _(u'Error executing bootstrap setup; %s') % exception)
else: else:
messages.success(request, _(u'Bootstrap setup "%s" executed successfully.') % bootstrap_setup) messages.success(request, _(u'Bootstrap setup "%s" executed successfully.') % bootstrap_setup)
return HttpResponseRedirect(next) return HttpResponseRedirect(next)
@@ -295,8 +295,8 @@ def erase_database_view(request):
if request.method == 'POST': if request.method == 'POST':
try: try:
Cleanup.execute_all() Cleanup.execute_all()
except Exception, exc: except Exception as exception:
messages.error(request, _(u'Error erasing database; %s') % exc) messages.error(request, _(u'Error erasing database; %s') % exception)
else: else:
messages.success(request, _(u'Database erased successfully.')) messages.success(request, _(u'Database erased successfully.'))
return HttpResponseRedirect(next) return HttpResponseRedirect(next)

View File

@@ -78,8 +78,8 @@ def checkout_document(request, document_pk):
document_checkout = form.save(commit=False) document_checkout = form.save(commit=False)
document_checkout.user_object = request.user document_checkout.user_object = request.user
document_checkout.save() document_checkout.save()
except Exception, exc: except Exception as exception:
messages.error(request, _(u'Error trying to check out document; %s') % exc) messages.error(request, _(u'Error trying to check out document; %s') % exception)
else: else:
messages.success(request, _(u'Document "%s" checked out successfully.') % document) messages.success(request, _(u'Document "%s" checked out successfully.') % document)
return HttpResponseRedirect(reverse('checkout_info', args=[document.pk])) return HttpResponseRedirect(reverse('checkout_info', args=[document.pk]))
@@ -122,8 +122,8 @@ def checkin_document(request, document_pk):
document.check_in(user=request.user) document.check_in(user=request.user)
except DocumentNotCheckedOut: except DocumentNotCheckedOut:
messages.error(request, _(u'Document has not been checked out.')) messages.error(request, _(u'Document has not been checked out.'))
except Exception, exc: except Exception as exception:
messages.error(request, _(u'Error trying to check in document; %s') % exc) messages.error(request, _(u'Error trying to check in document; %s') % exception)
else: else:
messages.success(request, _(u'Document "%s" checked in successfully.') % document) messages.success(request, _(u'Document "%s" checked in successfully.') % document)
return HttpResponseRedirect(next) return HttpResponseRedirect(next)

View File

@@ -78,9 +78,9 @@ def return_attrib(obj, attrib, arguments=None):
return result() return result()
else: else:
return result return result
except Exception, err: except Exception as exception:
if settings.DEBUG: if settings.DEBUG:
return 'Attribute error: %s; %s' % (attrib, err) return 'Attribute error: %s; %s' % (attrib, exception)
else: else:
pass pass

View File

@@ -62,8 +62,8 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
def exists_with_famfam(path): def exists_with_famfam(path):
try: try:
return two_state_template(os.path.exists(path)) return two_state_template(os.path.exists(path))
except Exception, exc: except Exception as exception:
return exc return exception
def two_state_template(state, famfam_ok_icon=u'tick', famfam_fail_icon=u'cross'): def two_state_template(state, famfam_ok_icon=u'tick', famfam_fail_icon=u'cross'):

View File

@@ -85,9 +85,9 @@ class OfficeConverter(object):
try: try:
self.backend.convert(self.input_filepath, self.output_filepath) self.backend.convert(self.input_filepath, self.output_filepath)
self.exists = True self.exists = True
except OfficeBackendError, msg: except OfficeBackendError as exception:
# convert exception so that at least the mime type icon is displayed # convert exception so that at least the mime type icon is displayed
raise UnknownFileFormat(msg) raise UnknownFileFormat(exception)
def __unicode__(self): def __unicode__(self):
return getattr(self, 'output_filepath', None) return getattr(self, 'output_filepath', None)
@@ -140,7 +140,7 @@ class OfficeConverterBackendDirect(object):
logger.debug('converted_output: %s' % converted_output) logger.debug('converted_output: %s' % converted_output)
os.rename(converted_output, self.output_filepath) os.rename(converted_output, self.output_filepath)
except OSError, msg: except OSError as exception:
raise OfficeBackendError(msg) raise OfficeBackendError(exception)
except Exception, msg: except Exception as exception:
logger.error('Unhandled exception', exc_info=msg) logger.error('Unhandled exception', exc_info=exception)

View File

@@ -100,8 +100,8 @@ def key_delete(request, fingerprint, key_type):
gpg.delete_key(key) gpg.delete_key(key)
messages.success(request, _(u'Key: %s, deleted successfully.') % fingerprint) messages.success(request, _(u'Key: %s, deleted successfully.') % fingerprint)
return HttpResponseRedirect(next) return HttpResponseRedirect(next)
except Exception, msg: except Exception as exception:
messages.error(request, msg) messages.error(request, exception)
return HttpResponseRedirect(previous) return HttpResponseRedirect(previous)
return render_to_response('generic_confirm.html', { return render_to_response('generic_confirm.html', {

View File

@@ -81,18 +81,18 @@ def cascade_eval(eval_dict, document, template_node, parent_index_instance=None)
if template_node.enabled: if template_node.enabled:
try: try:
result = eval(template_node.expression, eval_dict, AVAILABLE_INDEXING_FUNCTIONS) 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') % { 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: else:
if result: if result:
index_instance, created = IndexInstanceNode.objects.get_or_create(index_template_node=template_node, value=result, parent=parent_index_instance) index_instance, created = IndexInstanceNode.objects.get_or_create(index_template_node=template_node, value=result, parent=parent_index_instance)
# if created: # if created:
try: try:
fs_create_index_directory(index_instance) 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') % { 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: if template_node.link_documents:
suffix = find_lowest_available_suffix(index_instance, document) 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: try:
fs_create_document_link(index_instance, document, suffix) 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') % { 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) index_instance.documents.add(document)
@@ -147,7 +147,7 @@ def cascade_document_remove(document, index_instance):
warnings.extend(parent_warnings) warnings.extend(parent_warnings)
except DocumentRenameCount.DoesNotExist: except DocumentRenameCount.DoesNotExist:
return warnings return warnings
except Exception, exc: except Exception as exception:
warnings.append(_(u'Unable to delete document indexing node; %s') % exc) warnings.append(_(u'Unable to delete document indexing node; %s') % exception)
return warnings return warnings

View File

@@ -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)]) target_directory = assemble_path_from_list([FILESYSTEM_SERVING[index_instance.index_template_node.index.name], get_instance_path(index_instance)])
try: try:
os.mkdir(target_directory) os.mkdir(target_directory)
except OSError, exc: except OSError as exception:
if exc.errno == errno.EEXIST: if exception.errno == errno.EEXIST:
pass pass
else: 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): 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: try:
os.symlink(document.file.path, filepath) os.symlink(document.file.path, filepath)
except OSError, exc: except OSError as exception:
if exc.errno == errno.EEXIST: if exception.errno == errno.EEXIST:
# This link should not exist, try to delete it # This link should not exist, try to delete it
try: try:
os.unlink(filepath) os.unlink(filepath)
# Try again # Try again
os.symlink(document.file.path, filepath) os.symlink(document.file.path, filepath)
except Exception, exc: except Exception as exception:
raise Exception(_(u'Unable to create symbolic link, file exists and could not be deleted: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc}) raise Exception(_(u'Unable to create symbolic link, file exists and could not be deleted: %(filepath)s; %(exception)s') % {'filepath': filepath, 'exception': exception})
else: 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): 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: try:
os.unlink(filepath) os.unlink(filepath)
except OSError, exc: except OSError as exception:
if exc.errno != errno.ENOENT: if exception.errno != errno.ENOENT:
# Raise when any error other than doesn't exits # 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): 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)]) target_directory = assemble_path_from_list([FILESYSTEM_SERVING[index_instance.index_template_node.index.name], get_instance_path(index_instance)])
try: try:
os.removedirs(target_directory) os.removedirs(target_directory)
except OSError, exc: except OSError as exception:
if exc.errno == errno.EEXIST: if exception.errno == errno.EEXIST:
pass pass
else: 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): def fs_delete_directory_recusive(index):

View File

@@ -94,8 +94,8 @@ def document_signature_upload(request, document_pk):
DocumentVersionSignature.objects.add_detached_signature(document, request.FILES['file']) DocumentVersionSignature.objects.add_detached_signature(document, request.FILES['file'])
messages.success(request, _(u'Detached signature uploaded successfully.')) messages.success(request, _(u'Detached signature uploaded successfully.'))
return HttpResponseRedirect(next) return HttpResponseRedirect(next)
except Exception, msg: except Exception as exception:
messages.error(request, msg) messages.error(request, exception)
return HttpResponseRedirect(previous) return HttpResponseRedirect(previous)
else: else:
form = DetachedSignatureForm() form = DetachedSignatureForm()
@@ -153,8 +153,8 @@ def document_signature_delete(request, document_pk):
DocumentVersionSignature.objects.clear_detached_signature(document) DocumentVersionSignature.objects.clear_detached_signature(document)
messages.success(request, _(u'Detached signature deleted successfully.')) messages.success(request, _(u'Detached signature deleted successfully.'))
return HttpResponseRedirect(next) return HttpResponseRedirect(next)
except Exception, exc: except Exception as exception:
messages.error(request, _(u'Error while deleting the detached signature; %s') % exc) messages.error(request, _(u'Error while deleting the detached signature; %s') % exception)
return HttpResponseRedirect(previous) return HttpResponseRedirect(previous)
return render_to_response('generic_confirm.html', { return render_to_response('generic_confirm.html', {

View File

@@ -33,8 +33,6 @@ logger = logging.getLogger(__name__)
def smart_link_action(request): def smart_link_action(request):
# Permission.objects.check_permissions(request.user, [PERMISSION_SMART_LINK_VIEW])
action = request.GET.get('action', None) action = request.GET.get('action', None)
if not action: if not action:
@@ -178,7 +176,6 @@ def smart_link_edit(request, smart_link_pk):
form = SmartLinkForm(instance=smart_link) form = SmartLinkForm(instance=smart_link)
return render_to_response('generic_form.html', { return render_to_response('generic_form.html', {
# 'navigation_object_name': 'smart_link',
'object': smart_link, 'object': smart_link,
'form': form, 'form': form,
'title': _(u'Edit smart link: %s') % smart_link 'title': _(u'Edit smart link: %s') % smart_link
@@ -200,10 +197,10 @@ def smart_link_delete(request, smart_link_pk):
try: try:
smart_link.delete() smart_link.delete()
messages.success(request, _(u'Smart link: %s deleted successfully.') % smart_link) messages.success(request, _(u'Smart link: %s deleted successfully.') % smart_link)
except Exception, error: except Exception as exception:
messages.error(request, _(u'Error deleting smart link: %(smart_link)s; %(error)s.') % { messages.error(request, _(u'Error deleting smart link: %(smart_link)s; %(exception)s.') % {
'smart_link': smart_link, 'smart_link': smart_link,
'error': error 'exception': exception
}) })
return HttpResponseRedirect(next) return HttpResponseRedirect(next)
@@ -315,10 +312,10 @@ def smart_link_condition_delete(request, smart_link_condition_pk):
try: try:
smart_link_condition.delete() smart_link_condition.delete()
messages.success(request, _(u'Smart link condition: "%s" deleted successfully.') % smart_link_condition) messages.success(request, _(u'Smart link condition: "%s" deleted successfully.') % smart_link_condition)
except Exception, error: except Exception as exception:
messages.error(request, _(u'Error deleting smart link condition: %(smart_link_condition)s; %(error)s.') % { messages.error(request, _(u'Error deleting smart link condition: %(smart_link_condition)s; %(exception)s.') % {
'smart_link_condition': smart_link_condition, 'smart_link_condition': smart_link_condition,
'error': error 'exception': exception
}) })
return HttpResponseRedirect(next) return HttpResponseRedirect(next)

View File

@@ -22,8 +22,8 @@ class LockManager(models.Manager):
lock.save(force_insert=True) lock.save(force_insert=True)
logger.debug('acquired lock: %s' % name) logger.debug('acquired lock: %s' % name)
return lock return lock
except IntegrityError, msg: except IntegrityError as exception:
logger.debug('IntegrityError: %s', msg) logger.debug('IntegrityError: %s', exception)
# There is already an existing lock # There is already an existing lock
# Check it's expiration date and if expired, reset it # Check it's expiration date and if expired, reset it
try: try:

View File

@@ -1,8 +1,8 @@
from __future__ import absolute_import from __future__ import absolute_import
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _
from django.forms.formsets import formset_factory from django.forms.formsets import formset_factory
from django.utils.translation import ugettext_lazy as _
from common.widgets import ScrollableCheckboxSelectMultiple from common.widgets import ScrollableCheckboxSelectMultiple
@@ -17,7 +17,6 @@ class MetadataForm(forms.Form):
# Set form fields initial values # Set form fields initial values
if 'initial' in kwargs: if 'initial' in kwargs:
self.metadata_type = kwargs['initial'].pop('metadata_type', None) self.metadata_type = kwargs['initial'].pop('metadata_type', None)
# self.document_type = kwargs['initial'].pop('document_type', None)
# FIXME: # FIXME:
# required = self.document_type.documenttypemetadatatype_set.get(metadata_type=self.metadata_type).required # required = self.document_type.documenttypemetadatatype_set.get(metadata_type=self.metadata_type).required
@@ -42,15 +41,15 @@ class MetadataForm(forms.Form):
choices.insert(0, ('', '------')) choices.insert(0, ('', '------'))
self.fields['value'].choices = choices self.fields['value'].choices = choices
self.fields['value'].required = required self.fields['value'].required = required
except Exception, err: except Exception as exception:
self.fields['value'].initial = err self.fields['value'].initial = exception
self.fields['value'].widget = forms.TextInput(attrs={'readonly': 'readonly'}) self.fields['value'].widget = forms.TextInput(attrs={'readonly': 'readonly'})
if self.metadata_type.default: if self.metadata_type.default:
try: try:
self.fields['value'].initial = eval(self.metadata_type.default, AVAILABLE_FUNCTIONS) self.fields['value'].initial = eval(self.metadata_type.default, AVAILABLE_FUNCTIONS)
except Exception, err: except Exception as exception:
self.fields['value'].initial = err self.fields['value'].initial = exception
id = forms.CharField(label=_(u'id'), widget=forms.HiddenInput) id = forms.CharField(label=_(u'id'), widget=forms.HiddenInput)
name = forms.CharField(label=_(u'Name'), name = forms.CharField(label=_(u'Name'),
@@ -71,7 +70,6 @@ class MetadataRemoveForm(MetadataForm):
class MetadataSelectionForm(forms.Form): class MetadataSelectionForm(forms.Form):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# document_type = kwargs.pop('document_type', None)
super(MetadataSelectionForm, self).__init__(*args, **kwargs) super(MetadataSelectionForm, self).__init__(*args, **kwargs)
document_type = getattr(self, 'initial', {}).get('document_type', None) document_type = getattr(self, 'initial', {}).get('document_type', None)
if document_type: if document_type:
@@ -86,7 +84,6 @@ class MetadataSelectionForm(forms.Form):
queryset=MetadataSet.objects.all(), queryset=MetadataSet.objects.all(),
label=_(u'Metadata sets'), label=_(u'Metadata sets'),
required=False, required=False,
# widget=forms.widgets.SelectMultiple(attrs={'size': 10, 'class': 'choice_form'})
widget=ScrollableCheckboxSelectMultiple(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(), queryset=MetadataType.objects.all(),
label=_(u'Metadata'), label=_(u'Metadata'),
required=False, required=False,
# widget=forms.widgets.SelectMultiple(attrs={'size': 10, 'class': 'choice_form'})
widget=ScrollableCheckboxSelectMultiple(attrs={'size': 10, 'class': 'choice_form'}) widget=ScrollableCheckboxSelectMultiple(attrs={'size': 10, 'class': 'choice_form'})
) )

View File

@@ -105,9 +105,9 @@ def resolve_links(context, links, current_view, current_path, parsed_query_strin
new_link['url'] = reverse(link['view'], args=args) new_link['url'] = reverse(link['view'], args=args)
if link.get('keep_query', False): if link.get('keep_query', False):
new_link['url'] = urlquote(new_link['url'], parsed_query_string) new_link['url'] = urlquote(new_link['url'], parsed_query_string)
except NoReverseMatch, err: except NoReverseMatch as exception:
new_link['url'] = '#' new_link['url'] = '#'
new_link['error'] = err new_link['error'] = exception
elif 'url' in link: elif 'url' in link:
if not link.get('dont_mark_active', False): if not link.get('dont_mark_active', False):
new_link['active'] = link['url'] == current_path new_link['active'] = link['url'] == current_path

View File

@@ -116,8 +116,8 @@ class OfficeParser(Parser):
else: else:
raise ParserError raise ParserError
except OfficeConversionError, msg: except OfficeConversionError as exception:
logger.error(msg) logger.error(exception)
raise ParserError raise ParserError