updated hacking rules
1) Added comment for H231, which we were already enforcing. H231 is for Python 3.x compatible except statements. 2) Added check for H201, which we were enforcing in reviews but waiting on hacking checks to be updated. H201 is for bare except statements, and the update in upstream hacking is to support the " # noqa" flag on it. The H201 check catches some existing bare excepts that are fixed. Change-Id: I68638aa9ea925ef62f9035a426548c2c804911a8
This commit is contained in:
parent
813cc0fe0d
commit
e567722c4e
@ -313,55 +313,55 @@ class HTMLViewer(object):
|
|||||||
return empty_description, headers
|
return empty_description, headers
|
||||||
try:
|
try:
|
||||||
stats = Stats2(*log_files)
|
stats = Stats2(*log_files)
|
||||||
if not fulldirs:
|
except (IOError, ValueError):
|
||||||
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:
|
|
||||||
raise DataLoadFailure(_('Can not load profile data from %s.')
|
raise DataLoadFailure(_('Can not load profile data from %s.')
|
||||||
% log_files)
|
% 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='',
|
def download(self, log_files, sort='time', limit=-1, nfl_filter='',
|
||||||
output_format='default'):
|
output_format='default'):
|
||||||
@ -438,7 +438,7 @@ class HTMLViewer(object):
|
|||||||
file_path = nfls[0]
|
file_path = nfls[0]
|
||||||
try:
|
try:
|
||||||
lineno = int(nfls[1])
|
lineno = int(nfls[1])
|
||||||
except:
|
except (TypeError, ValueError, IndexError):
|
||||||
lineno = 0
|
lineno = 0
|
||||||
# for security reason, this need to be fixed.
|
# for security reason, this need to be fixed.
|
||||||
if not file_path.endswith('.py'):
|
if not file_path.endswith('.py'):
|
||||||
|
@ -242,18 +242,13 @@ class ProfileMiddleware(object):
|
|||||||
start_response('500 Internal Server Error', [])
|
start_response('500 Internal Server Error', [])
|
||||||
return _('Error on render profiling results: %s') % ex
|
return _('Error on render profiling results: %s') % ex
|
||||||
else:
|
else:
|
||||||
try:
|
_locals = locals()
|
||||||
_locals = locals()
|
code = self.unwind and PROFILE_EXEC_EAGER or\
|
||||||
code = self.unwind and PROFILE_EXEC_EAGER or\
|
PROFILE_EXEC_LAZY
|
||||||
PROFILE_EXEC_LAZY
|
self.profiler.runctx(code, globals(), _locals)
|
||||||
self.profiler.runctx(code, globals(), _locals)
|
app_iter = _locals['app_iter_']
|
||||||
app_iter = _locals['app_iter_']
|
self.dump_checkpoint()
|
||||||
self.dump_checkpoint()
|
return app_iter
|
||||||
return app_iter
|
|
||||||
except:
|
|
||||||
self.logger.exception(_('Error profiling code'))
|
|
||||||
finally:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def renew_profile(self):
|
def renew_profile(self):
|
||||||
self.profiler = get_profiler(self.profile_module)
|
self.profiler = get_profiler(self.profile_module)
|
||||||
|
@ -732,7 +732,7 @@ class ContainerReconciler(Daemon):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.reconcile()
|
self.reconcile()
|
||||||
except:
|
except: # noqa
|
||||||
self.logger.exception('Unhandled Exception trying to reconcile')
|
self.logger.exception('Unhandled Exception trying to reconcile')
|
||||||
self.log_stats(force=True)
|
self.log_stats(force=True)
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class TestRecon(unittest.TestCase):
|
|||||||
def tearDown(self, *_args, **_kwargs):
|
def tearDown(self, *_args, **_kwargs):
|
||||||
try:
|
try:
|
||||||
os.remove(self.tmpfile_name)
|
os.remove(self.tmpfile_name)
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_gen_stats(self):
|
def test_gen_stats(self):
|
||||||
|
5
tox.ini
5
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
|
# it's not a bug that we aren't using all of hacking
|
||||||
# H102 -> apache2 license exists
|
# H102 -> apache2 license exists
|
||||||
# H103 -> license is apache
|
# 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
|
# H501 -> don't use locals() for str formatting
|
||||||
# H903 -> \n not \r\n
|
# H903 -> \n not \r\n
|
||||||
ignore = H
|
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
|
exclude = .venv,.tox,dist,doc,*egg
|
||||||
show-source = True
|
show-source = True
|
||||||
|
Loading…
Reference in New Issue
Block a user