From 9b5bc1881e8d1517a56554a94fe96cb503bc6344 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 28 Jan 2015 16:00:53 -0800 Subject: [PATCH] Convert old style except blocks to except Exception as variable: blocks --- bcmagic/views.py | 2 +- encode_submission/encode_find.py | 2 +- experiments/experiments.py | 6 +++--- experiments/models.py | 2 +- htsworkflow/pipelines/configure_run.py | 8 ++++---- htsworkflow/pipelines/genome_mapper.py | 2 +- htsworkflow/pipelines/gerald.py | 2 +- htsworkflow/pipelines/retrieve_config.py | 2 +- htsworkflow/pipelines/runfolder.py | 2 +- htsworkflow/pipelines/summary.py | 4 ++-- htsworkflow/pipelines/test/test_retrieve_config.py | 2 +- htsworkflow/submission/daf.py | 4 ++-- htsworkflow/submission/submission.py | 6 +++--- htsworkflow/submission/ucsc.py | 2 +- htsworkflow/util/api.py | 4 ++-- htsworkflow/util/config_helper.py | 2 +- htsworkflow/util/hdquery.py | 2 +- htsworkflow/util/rdfhelp.py | 4 ++-- htsworkflow/util/test/test_ethelp.py | 2 +- htsworkflow/util/test/test_rdfhelp.py | 2 +- htsworkflow/util/version.py | 4 ++-- inventory/models.py | 2 +- inventory/views.py | 12 ++++++------ samples/auth_backend.py | 4 ++-- samples/models.py | 2 +- samples/test_samples.py | 2 +- samples/views.py | 6 +++--- 27 files changed, 47 insertions(+), 47 deletions(-) diff --git a/bcmagic/views.py b/bcmagic/views.py index df86077..3d9206f 100644 --- a/bcmagic/views.py +++ b/bcmagic/views.py @@ -11,7 +11,7 @@ from . import plugin try: import json -except ImportError, e: +except ImportError as e: import simplejson as json import re diff --git a/encode_submission/encode_find.py b/encode_submission/encode_find.py index 7589f54..60e0bee 100644 --- a/encode_submission/encode_find.py +++ b/encode_submission/encode_find.py @@ -566,7 +566,7 @@ def load_library_detail(model, libraryUrn): try: body = get_url_as_text(str(libraryUrn.uri), 'GET') rdfaParser.parse_string_into_model(model, body, libraryUrn.uri) - except httplib2.HttpLib2ErrorWithResponse, e: + except httplib2.HttpLib2ErrorWithResponse as e: LOGGER.error(str(e)) elif len(results) == 1: pass # Assuming that a loaded dataset has one record diff --git a/experiments/experiments.py b/experiments/experiments.py index a5b8436..b8f905e 100644 --- a/experiments/experiments.py +++ b/experiments/experiments.py @@ -4,7 +4,7 @@ from __future__ import absolute_import, print_function from datetime import datetime, timedelta try: import json -except ImportError, e: +except ImportError as e: import simplejson as json import os @@ -28,7 +28,7 @@ def flowcell_information(flowcell_id): """ try: fc = FlowCell.objects.get(flowcell_id__startswith=flowcell_id) - except FlowCell.DoesNotExist, e: + except FlowCell.DoesNotExist as e: return None lane_set = {} @@ -126,7 +126,7 @@ def lanes_for_json(request, username): try: result = lanes_for(username) - except ObjectDoesNotExist, e: + except ObjectDoesNotExist as e: raise Http404 #convert query set to python structure diff --git a/experiments/models.py b/experiments/models.py index 6b92a18..3377e28 100644 --- a/experiments/models.py +++ b/experiments/models.py @@ -25,7 +25,7 @@ LOGGER = logging.getLogger(__name__) default_pM = 5 try: default_pM = int(settings.DEFAULT_PM) -except AttributeError, e: +except AttributeError as e: LOGGER.error("invalid value for default_pm") # how many days to wait before trying to re-import a runfolder diff --git a/htsworkflow/pipelines/configure_run.py b/htsworkflow/pipelines/configure_run.py index 83c7569..d0d43d2 100644 --- a/htsworkflow/pipelines/configure_run.py +++ b/htsworkflow/pipelines/configure_run.py @@ -377,16 +377,16 @@ def retrieve_config(conf_info, flowcell, cfg_filepath, genome_dir): try: saveConfigFile(flowcell, options.url, cfg_filepath) conf_info.config_filepath = cfg_filepath - except FlowCellNotFound, e: + except FlowCellNotFound as e: LOGGER.error(e) return False - except WebError404, e: + except WebError404 as e: LOGGER.error(e) return False - except IOError, e: + except IOError as e: LOGGER.error(e) return False - except Exception, e: + except Exception as e: LOGGER.error(e) return False diff --git a/htsworkflow/pipelines/genome_mapper.py b/htsworkflow/pipelines/genome_mapper.py index fb16d7f..35830a2 100644 --- a/htsworkflow/pipelines/genome_mapper.py +++ b/htsworkflow/pipelines/genome_mapper.py @@ -103,7 +103,7 @@ class constructMapperDict(object): def get(self, key, default=None): try: return self[key] - except KeyError, e: + except KeyError as e: return default def keys(self): diff --git a/htsworkflow/pipelines/gerald.py b/htsworkflow/pipelines/gerald.py index 2eaff67..dd70fe2 100644 --- a/htsworkflow/pipelines/gerald.py +++ b/htsworkflow/pipelines/gerald.py @@ -283,7 +283,7 @@ class LaneParametersGA(LaneParameters): lanes = [x.tag.split('_')[1] for x in container.getchildren()] try: index = lanes.index(self._lane_id) - except ValueError, e: + except ValueError as e: return None element = container[index] return element.text diff --git a/htsworkflow/pipelines/retrieve_config.py b/htsworkflow/pipelines/retrieve_config.py index 7951752..1d44214 100644 --- a/htsworkflow/pipelines/retrieve_config.py +++ b/htsworkflow/pipelines/retrieve_config.py @@ -49,7 +49,7 @@ def retrieve_flowcell_info(base_host_url, flowcell): try: apipayload = urllib.urlencode(apidata) web = urllib2.urlopen(url, apipayload) - except urllib2.URLError, e: + except urllib2.URLError as e: errmsg = 'URLError: %d %s' % (e.code, e.msg) LOGGER.error(errmsg) LOGGER.error('opened %s' % (url,)) diff --git a/htsworkflow/pipelines/runfolder.py b/htsworkflow/pipelines/runfolder.py index 669c5f0..dfc75f4 100644 --- a/htsworkflow/pipelines/runfolder.py +++ b/htsworkflow/pipelines/runfolder.py @@ -336,7 +336,7 @@ def build_gerald_runs(runs, b, image_analysis, bustard_pathname, datadir, pathna p.bustard = b p.gerald = g runs.append(p) - except IOError, e: + except IOError as e: LOGGER.error("Ignoring " + str(e)) return len(runs) - start diff --git a/htsworkflow/pipelines/summary.py b/htsworkflow/pipelines/summary.py index 8f47670..100b2c0 100644 --- a/htsworkflow/pipelines/summary.py +++ b/htsworkflow/pipelines/summary.py @@ -311,7 +311,7 @@ class LaneResultSummary(object): variable_name = tags[element.tag] setattr(self, variable_name, parse_summary_element(element)) - except KeyError, e: + except KeyError as e: LOGGER.warn('Unrecognized tag %s' % (element.tag,)) @@ -414,7 +414,7 @@ def tonumber(v): """ try: v = int(v) - except ValueError, e: + except ValueError as e: v = float(v) return v diff --git a/htsworkflow/pipelines/test/test_retrieve_config.py b/htsworkflow/pipelines/test/test_retrieve_config.py index 1a24c63..7ca8790 100644 --- a/htsworkflow/pipelines/test/test_retrieve_config.py +++ b/htsworkflow/pipelines/test/test_retrieve_config.py @@ -5,7 +5,7 @@ from StringIO import StringIO try: import json -except ImportError, e: +except ImportError as e: import simplejson as json from django.test import TestCase diff --git a/htsworkflow/submission/daf.py b/htsworkflow/submission/daf.py index f04ac8f..30edcdc 100644 --- a/htsworkflow/submission/daf.py +++ b/htsworkflow/submission/daf.py @@ -300,7 +300,7 @@ class UCSCSubmission(object): LOGGER.info("Importing %s from %s" % (lib_id, result_dir)) try: self.import_submission_dir(result_dir, lib_id) - except MetadataLookupException, e: + except MetadataLookupException as e: LOGGER.error("Skipping %s: %s" % (lib_id, str(e))) def import_submission_dir(self, submission_dir, library_id): @@ -531,7 +531,7 @@ class UCSCSubmission(object): LOGGER.debug("Found: %s" % (literal_re,)) try: filename_re = re.compile(literal_re) - except re.error, e: + except re.error as e: LOGGER.error("Unable to compile: %s" % (literal_re,)) patterns[literal_re] = view_name return patterns diff --git a/htsworkflow/submission/submission.py b/htsworkflow/submission/submission.py index 897053f..cb20455 100644 --- a/htsworkflow/submission/submission.py +++ b/htsworkflow/submission/submission.py @@ -44,7 +44,7 @@ class Submission(object): LOGGER.info("Importing %s from %s" % (lib_id, result_dir)) try: self.import_analysis_dir(result_dir, lib_id) - except MetadataLookupException, e: + except MetadataLookupException as e: LOGGER.error("Skipping %s: %s" % (lib_id, str(e))) def import_analysis_dir(self, analysis_dir, library_id): @@ -245,7 +245,7 @@ class Submission(object): LOGGER.debug("Importing %s" % (lane.uri,)) try: parser.parse_into_model(self.model, lane.uri) - except RDF.RedlandError, e: + except RDF.RedlandError as e: LOGGER.error("Error accessing %s" % (lane.uri,)) raise e @@ -286,7 +286,7 @@ class Submission(object): LOGGER.debug("Found: %s" % (literal_re,)) try: filename_re = re.compile(literal_re) - except re.error, e: + except re.error as e: LOGGER.error("Unable to compile: %s" % (literal_re,)) patterns[literal_re] = view_name return patterns diff --git a/htsworkflow/submission/ucsc.py b/htsworkflow/submission/ucsc.py index f7734ad..ff71736 100644 --- a/htsworkflow/submission/ucsc.py +++ b/htsworkflow/submission/ucsc.py @@ -61,7 +61,7 @@ def get_encodedcc_file_index(genome, composite): request = urllib2.urlopen(request_url) file_index = parse_ucsc_file_index(request, base_url) return file_index - except urllib2.HTTPError, e: + except urllib2.HTTPError as e: err = e pass diff --git a/htsworkflow/util/api.py b/htsworkflow/util/api.py index 76ee84d..7abfa2a 100644 --- a/htsworkflow/util/api.py +++ b/htsworkflow/util/api.py @@ -131,7 +131,7 @@ def retrieve_info(url, apidata): try: apipayload = urllib.urlencode(apidata) web = urllib2.urlopen(url, apipayload) - except urllib2.URLError, e: + except urllib2.URLError as e: if hasattr(e, 'code') and e.code == 404: LOGGER.info("%s was not found" % (url,)) return None @@ -168,7 +168,7 @@ def make_django_secret_key(size=216): """return key suitable for use as secret key""" try: source = random.SystemRandom() - except AttributeError, e: + except AttributeError as e: source = random.random() bits = source.getrandbits(size) chars = [] diff --git a/htsworkflow/util/config_helper.py b/htsworkflow/util/config_helper.py index 162580f..4b86da4 100644 --- a/htsworkflow/util/config_helper.py +++ b/htsworkflow/util/config_helper.py @@ -39,5 +39,5 @@ class HTSWConfig(ConfigParser.SafeConfigParser): ini_stream = open(self.filename, 'w') self.write(ini_stream) ini_stream.close() - except IOError, e: + except IOError as e: LOGGER.info("Error saving setting: %s" % (str(e))) diff --git a/htsworkflow/util/hdquery.py b/htsworkflow/util/hdquery.py index 57c05e6..37fd555 100644 --- a/htsworkflow/util/hdquery.py +++ b/htsworkflow/util/hdquery.py @@ -23,7 +23,7 @@ try: # the 2nd of which is the serial number return data.strip('\x00').split()[1] -except ImportError, e: +except ImportError as e: print >>sys.stderr, "hdquery requires py_sg" def get_hd_serial_num(device): diff --git a/htsworkflow/util/rdfhelp.py b/htsworkflow/util/rdfhelp.py index 4829441..cc16f79 100644 --- a/htsworkflow/util/rdfhelp.py +++ b/htsworkflow/util/rdfhelp.py @@ -147,7 +147,7 @@ def fromTypedNode(node): elif value_type in ('dateTime'): try: return datetime.strptime(literal, ISOFORMAT_MS) - except ValueError, _: + except ValueError: return datetime.strptime(literal, ISOFORMAT_SHORT) return literal @@ -280,7 +280,7 @@ def load_into_model(model, parser_name, path, ns=None): statements = rdf_parser.parse_as_stream(url, ns) retries = 0 succeeded = True - except RDF.RedlandError, e: + except RDF.RedlandError as e: errmsg = "RDF.RedlandError: {0} {1} tries remaining" logger.error(errmsg.format(str(e), retries)) diff --git a/htsworkflow/util/test/test_ethelp.py b/htsworkflow/util/test/test_ethelp.py index 379dd9e..5d982e8 100644 --- a/htsworkflow/util/test/test_ethelp.py +++ b/htsworkflow/util/test/test_ethelp.py @@ -3,7 +3,7 @@ from unittest import TestCase try: from xml.etree import ElementTree -except ImportError, e: +except ImportError as e: from elementtree import ElementTree from htsworkflow.util.ethelp import indent, flatten diff --git a/htsworkflow/util/test/test_rdfhelp.py b/htsworkflow/util/test/test_rdfhelp.py index 9694c37..d11d98b 100644 --- a/htsworkflow/util/test/test_rdfhelp.py +++ b/htsworkflow/util/test/test_rdfhelp.py @@ -261,7 +261,7 @@ _:a owl:imports "{loc}extra.turtle" . self.assertTrue(model.contains_statement(s)) -except ImportError, e: +except ImportError as e: print "Unable to test rdfhelp" def suite(): diff --git a/htsworkflow/util/version.py b/htsworkflow/util/version.py index 8097edb..56a1b11 100644 --- a/htsworkflow/util/version.py +++ b/htsworkflow/util/version.py @@ -8,13 +8,13 @@ def version(): version = None try: import pkg_resources - except ImportError, e: + except ImportError as e: LOGGER.error("Can't find version number, please install setuptools") raise e try: version = pkg_resources.get_distribution("htsworkflow") - except pkg_resources.DistributionNotFound, e: + except pkg_resources.DistributionNotFound as e: LOGGER.error("Package not installed") return version diff --git a/inventory/models.py b/inventory/models.py index deefeed..d41025a 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -13,7 +13,7 @@ LOGGER = logging.getLogger(__name__) try: import uuid -except ImportError, e: +except ImportError as e: # Some systems are using python 2.4, which doesn't have uuid # this is a stub LOGGER.warning('Real uuid is not available, initializing fake uuid module') diff --git a/inventory/views.py b/inventory/views.py index 05f300a..149710f 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -21,7 +21,7 @@ register_search_plugin('Inventory Item', item_search) try: import json -except ImportError, e: +except ImportError as e: import simplejson as json INVENTORY_CONTEXT_DEFAULTS = { @@ -216,7 +216,7 @@ def item_summary_by_barcode(request, barcode_id, msg=''): """ try: item = Item.objects.get(barcode_id=barcode_id) - except ObjectDoesNotExist, e: + except ObjectDoesNotExist as e: item = None return item_summary_by_uuid(request, None, msg, item) @@ -231,7 +231,7 @@ def item_summary_by_uuid(request, uuid, msg='', item=None): if item is None: try: item = Item.objects.get(uuid=uuid) - except ObjectDoesNotExist, e: + except ObjectDoesNotExist as e: item = None context_dict = { @@ -291,7 +291,7 @@ def item_print(request, uuid): """ try: item = Item.objects.get(uuid=uuid) - except ObjectDoesNotExist, e: + except ObjectDoesNotExist as e: item = None msg = "Item with UUID %s does not exist" % (uuid) @@ -316,7 +316,7 @@ def link_flowcell_and_device(request, flowcell, serial): # Retrieve Storage Device try: sd = Item.objects.get(barcode_id=serial) - except ObjectDoesNotExist, e: + except ObjectDoesNotExist as e: msg = "Item with barcode_id of %s not found." % (serial) raise ObjectDoesNotExist(msg) @@ -324,7 +324,7 @@ def link_flowcell_and_device(request, flowcell, serial): # Retrieve FlowCell try: fc = FlowCell.objects.get(flowcell_id__startswith=flowcell) - except ObjectDoesNotExist, e: + except ObjectDoesNotExist as e: msg = "FlowCell with flowcell_id of %s not found." % (flowcell) raise ObjectDoesNotExist(msg) diff --git a/samples/auth_backend.py b/samples/auth_backend.py index d3f4330..aacf43b 100644 --- a/samples/auth_backend.py +++ b/samples/auth_backend.py @@ -17,7 +17,7 @@ class HTSUserModelBackend(ModelBackend): if user.check_password(password): return user #except self.user_class.DoesNotExist: - except Exception, e: + except Exception as e: logger.error(str(e)) return None @@ -25,7 +25,7 @@ class HTSUserModelBackend(ModelBackend): try: return self.user_class.objects.get(pk=user_id) #except self.user_class.DoesNotExist: - except Exception, e: + except Exception as e: logger.error(str(e)) return None diff --git a/samples/models.py b/samples/models.py index 5c5c27c..21b6f40 100644 --- a/samples/models.py +++ b/samples/models.py @@ -272,7 +272,7 @@ class Library(models.Model): adapter_type = self.library_type.id, multiplex_id = multiplex_id) return multiplex.sequence - except MultiplexIndex.DoesNotExist, e: + except MultiplexIndex.DoesNotExist as e: return None def index_sequence_text(self, seperator=' '): diff --git a/samples/test_samples.py b/samples/test_samples.py index c339619..61fc930 100644 --- a/samples/test_samples.py +++ b/samples/test_samples.py @@ -276,7 +276,7 @@ try: libNS = RDF.NS("http://jumpgate.caltech.edu/wiki/LibraryOntology#") from htsworkflow.util.rdfhelp import dump_model -except ImportError,e: +except ImportError as e: HAVE_RDF = False diff --git a/samples/views.py b/samples/views.py index 79e7856..e506c7d 100644 --- a/samples/views.py +++ b/samples/views.py @@ -8,7 +8,7 @@ import sys try: import json -except ImportError, e: +except ImportError as e: import simplejson as json from django.views.decorators.csrf import csrf_exempt @@ -338,7 +338,7 @@ def _summary_stats(flowcell_id, lane_id, library_id): summary_list.append(eland_summary) - #except Exception, e: + #except Exception as e: # summary_list.append("Summary report needs to be updated.") # LOGGER.error("Exception: " + str(e)) @@ -471,7 +471,7 @@ def library_dict(library_id): """ try: lib = Library.objects.get(id=library_id) - except Library.DoesNotExist, e: + except Library.DoesNotExist as e: return None #lane_info = lane_information(lib.lane_set) -- 2.30.2