summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-10-03 01:47:40 +0000
committerGerrit Code Review <review@openstack.org>2014-10-03 01:47:40 +0000
commit513eeb80d70fa06cf224f523bfed1b784d47fb3b (patch)
treec76fcd40aa8e7316fa3fceed7d88da2d0e68b57c
parent301e9f532a1c29ff53c6cb1d2edc0144d4832ec8 (diff)
parente567722c4ea125f4607093112396e16ae6c6dd42 (diff)
downloadswift-513eeb80d70fa06cf224f523bfed1b784d47fb3b.tar.gz
Merge "updated hacking rules"
-rw-r--r--swift/common/middleware/x_profile/html_viewer.py96
-rw-r--r--swift/common/middleware/xprofile.py19
-rw-r--r--swift/container/reconciler.py2
-rw-r--r--test/unit/cli/test_recon.py2
-rw-r--r--tox.ini5
5 files changed, 60 insertions, 64 deletions
diff --git a/swift/common/middleware/x_profile/html_viewer.py b/swift/common/middleware/x_profile/html_viewer.py
index 416ba0116..91ad8f66a 100644
--- a/swift/common/middleware/x_profile/html_viewer.py
+++ b/swift/common/middleware/x_profile/html_viewer.py
@@ -313,55 +313,55 @@ class HTMLViewer(object):
return empty_description, headers
try:
stats = Stats2(*log_files)
- if not fulldirs:
- stats.strip_dirs()
- stats.sort_stats(sort)
- nfl_filter_esc =\
- nfl_filter.replace('(', '\(').replace(')', '\)')
- amount = [nfl_filter_esc, limit] if nfl_filter_esc else [limit]
- profile_html = self.generate_stats_html(stats, self.app_path,
- profile_id, *amount)
- description = "Profiling information is generated by using\
- '%s' profiler." % self.profile_module
- sort_repl = '<option value="%s">' % sort
- sort_selected = '<option value="%s" selected>' % sort
- sort = sort_tmpl.replace(sort_repl, sort_selected)
- plist = ''.join(['<option value="%s">%s</option>' % (p, p)
- for p in self.profile_log.get_all_pids()])
- profile_element = string.Template(profile_tmpl).substitute(
- {'profile_list': plist})
- profile_repl = '<option value="%s">' % profile_id
- profile_selected = '<option value="%s" selected>' % profile_id
- profile_element = profile_element.replace(profile_repl,
- profile_selected)
- limit_repl = '<option value="%s">' % limit
- limit_selected = '<option value="%s" selected>' % limit
- limit = limit_tmpl.replace(limit_repl, limit_selected)
- fulldirs_checked = 'checked' if fulldirs else ''
- fulldirs_element = string.Template(fulldirs_tmpl).substitute(
- {'fulldir_checked': fulldirs_checked})
- nfl_filter_element = string.Template(nfl_filter_tmpl).\
- substitute({'nfl_filter': nfl_filter})
- form_elements = string.Template(formelements_tmpl).substitute(
- {'description': description,
- 'action': url,
- 'profile': profile_element,
- 'sort': sort,
- 'limit': limit,
- 'fulldirs': fulldirs_element,
- 'nfl_filter': nfl_filter_element,
- }
- )
- content = string.Template(index_tmpl).substitute(
- {'formelements': form_elements,
- 'action': url,
- 'description': description,
- 'profilehtml': profile_html,
- })
- return content, headers
- except:
+ except (IOError, ValueError):
raise DataLoadFailure(_('Can not load profile data from %s.')
% log_files)
+ if not fulldirs:
+ stats.strip_dirs()
+ stats.sort_stats(sort)
+ nfl_filter_esc =\
+ nfl_filter.replace('(', '\(').replace(')', '\)')
+ amount = [nfl_filter_esc, limit] if nfl_filter_esc else [limit]
+ profile_html = self.generate_stats_html(stats, self.app_path,
+ profile_id, *amount)
+ description = "Profiling information is generated by using\
+ '%s' profiler." % self.profile_module
+ sort_repl = '<option value="%s">' % sort
+ sort_selected = '<option value="%s" selected>' % sort
+ sort = sort_tmpl.replace(sort_repl, sort_selected)
+ plist = ''.join(['<option value="%s">%s</option>' % (p, p)
+ for p in self.profile_log.get_all_pids()])
+ profile_element = string.Template(profile_tmpl).substitute(
+ {'profile_list': plist})
+ profile_repl = '<option value="%s">' % profile_id
+ profile_selected = '<option value="%s" selected>' % profile_id
+ profile_element = profile_element.replace(profile_repl,
+ profile_selected)
+ limit_repl = '<option value="%s">' % limit
+ limit_selected = '<option value="%s" selected>' % limit
+ limit = limit_tmpl.replace(limit_repl, limit_selected)
+ fulldirs_checked = 'checked' if fulldirs else ''
+ fulldirs_element = string.Template(fulldirs_tmpl).substitute(
+ {'fulldir_checked': fulldirs_checked})
+ nfl_filter_element = string.Template(nfl_filter_tmpl).\
+ substitute({'nfl_filter': nfl_filter})
+ form_elements = string.Template(formelements_tmpl).substitute(
+ {'description': description,
+ 'action': url,
+ 'profile': profile_element,
+ 'sort': sort,
+ 'limit': limit,
+ 'fulldirs': fulldirs_element,
+ 'nfl_filter': nfl_filter_element,
+ }
+ )
+ content = string.Template(index_tmpl).substitute(
+ {'formelements': form_elements,
+ 'action': url,
+ 'description': description,
+ 'profilehtml': profile_html,
+ })
+ return content, headers
def download(self, log_files, sort='time', limit=-1, nfl_filter='',
output_format='default'):
@@ -438,7 +438,7 @@ class HTMLViewer(object):
file_path = nfls[0]
try:
lineno = int(nfls[1])
- except:
+ except (TypeError, ValueError, IndexError):
lineno = 0
# for security reason, this need to be fixed.
if not file_path.endswith('.py'):
diff --git a/swift/common/middleware/xprofile.py b/swift/common/middleware/xprofile.py
index bff0bac8f..08b87f805 100644
--- a/swift/common/middleware/xprofile.py
+++ b/swift/common/middleware/xprofile.py
@@ -242,18 +242,13 @@ class ProfileMiddleware(object):
start_response('500 Internal Server Error', [])
return _('Error on render profiling results: %s') % ex
else:
- try:
- _locals = locals()
- code = self.unwind and PROFILE_EXEC_EAGER or\
- PROFILE_EXEC_LAZY
- self.profiler.runctx(code, globals(), _locals)
- app_iter = _locals['app_iter_']
- self.dump_checkpoint()
- return app_iter
- except:
- self.logger.exception(_('Error profiling code'))
- finally:
- pass
+ _locals = locals()
+ code = self.unwind and PROFILE_EXEC_EAGER or\
+ PROFILE_EXEC_LAZY
+ self.profiler.runctx(code, globals(), _locals)
+ app_iter = _locals['app_iter_']
+ self.dump_checkpoint()
+ return app_iter
def renew_profile(self):
self.profiler = get_profiler(self.profile_module)
diff --git a/swift/container/reconciler.py b/swift/container/reconciler.py
index 9dbb5a697..ea27e32a5 100644
--- a/swift/container/reconciler.py
+++ b/swift/container/reconciler.py
@@ -732,7 +732,7 @@ class ContainerReconciler(Daemon):
"""
try:
self.reconcile()
- except:
+ except: # noqa
self.logger.exception('Unhandled Exception trying to reconcile')
self.log_stats(force=True)
diff --git a/test/unit/cli/test_recon.py b/test/unit/cli/test_recon.py
index ee82d6636..465568fe4 100644
--- a/test/unit/cli/test_recon.py
+++ b/test/unit/cli/test_recon.py
@@ -99,7 +99,7 @@ class TestRecon(unittest.TestCase):
def tearDown(self, *_args, **_kwargs):
try:
os.remove(self.tmpfile_name)
- except:
+ except OSError:
pass
def test_gen_stats(self):
diff --git a/tox.ini b/tox.ini
index b945077b8..96e32f87a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -58,10 +58,11 @@ commands = python setup.py build_sphinx
# it's not a bug that we aren't using all of hacking
# H102 -> apache2 license exists
# H103 -> license is apache
-# H201 -> no bare excepts # add when hacking supports noqa
+# H201 -> no bare excepts (unless marked with " # noqa")
+# H231 -> Check for except statements to be Python 3.x compatible
# H501 -> don't use locals() for str formatting
# H903 -> \n not \r\n
ignore = H
-select = F,E,W,H102,H103,H501,H903,H231
+select = F,E,W,H102,H103,H201,H231,H501,H903
exclude = .venv,.tox,dist,doc,*egg
show-source = True