Merge "common: Stop translating a bunch of printed messages and exceptions"

This commit is contained in:
Zuul
2024-09-06 21:06:25 +00:00
committed by Gerrit Code Review
4 changed files with 12 additions and 18 deletions

View File

@@ -13,16 +13,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from swift import gettext_ as _
class ProfileException(Exception): class ProfileException(Exception):
def __init__(self, msg): def __init__(self, msg):
self.msg = msg self.msg = msg
def __str__(self): def __str__(self):
return _('Profiling Error: %s') % self.msg return 'Profiling Error: %s' % self.msg
class NotFoundException(ProfileException): class NotFoundException(ProfileException):

View File

@@ -19,7 +19,6 @@ import re
import string import string
import tempfile import tempfile
from swift import gettext_ as _
from swift.common.middleware.x_profile.exceptions import PLOTLIBNotInstalled from swift.common.middleware.x_profile.exceptions import PLOTLIBNotInstalled
from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled
from swift.common.middleware.x_profile.exceptions import NotFoundException from swift.common.middleware.x_profile.exceptions import NotFoundException
@@ -307,7 +306,7 @@ class HTMLViewer(object):
nfl_filter, download_format) nfl_filter, download_format)
headers.append(('Access-Control-Allow-Origin', '*')) headers.append(('Access-Control-Allow-Origin', '*'))
else: else:
raise MethodNotAllowed(_('method %s is not allowed.') % method) raise MethodNotAllowed('method %s is not allowed.' % method)
return content, headers return content, headers
def index_page(self, log_files=None, sort='time', limit=-1, def index_page(self, log_files=None, sort='time', limit=-1,
@@ -318,7 +317,7 @@ class HTMLViewer(object):
try: try:
stats = Stats2(*log_files) stats = Stats2(*log_files)
except (IOError, ValueError): except (IOError, ValueError):
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: if not fulldirs:
stats.strip_dirs() stats.strip_dirs()
@@ -369,7 +368,7 @@ class HTMLViewer(object):
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'):
if len(log_files) == 0: if len(log_files) == 0:
raise NotFoundException(_('no log file found')) raise NotFoundException('no log file found')
try: try:
nfl_esc = nfl_filter.replace(r'(', r'\(').replace(r')', r'\)') nfl_esc = nfl_filter.replace(r'(', r'\(').replace(r')', r'\)')
# remove the slash that is intentionally added in the URL # remove the slash that is intentionally added in the URL
@@ -392,14 +391,14 @@ class HTMLViewer(object):
except ODFLIBNotInstalled: except ODFLIBNotInstalled:
raise raise
except Exception as ex: except Exception as ex:
raise ProfileException(_('Data download error: %s') % ex) raise ProfileException('Data download error: %s' % ex)
def plot(self, log_files, sort='time', limit=10, nfl_filter='', def plot(self, log_files, sort='time', limit=10, nfl_filter='',
metric_selected='cc', plot_type='bar'): metric_selected='cc', plot_type='bar'):
if not PLOTLIB_INSTALLED: if not PLOTLIB_INSTALLED:
raise PLOTLIBNotInstalled(_('python-matplotlib not installed.')) raise PLOTLIBNotInstalled('python-matplotlib not installed.')
if len(log_files) == 0: if len(log_files) == 0:
raise NotFoundException(_('no log file found')) raise NotFoundException('no log file found')
try: try:
stats = Stats2(*log_files) stats = Stats2(*log_files)
stats.sort_stats(sort) stats.sort_stats(sort)
@@ -433,7 +432,7 @@ class HTMLViewer(object):
data = profile_img.read() data = profile_img.read()
return data, [('content-type', 'image/jpg')] return data, [('content-type', 'image/jpg')]
except Exception as ex: except Exception as ex:
raise ProfileException(_('plotting results failed due to %s') % ex) raise ProfileException('plotting results failed due to %s' % ex)
def format_source_code(self, nfl): def format_source_code(self, nfl):
nfls = re.split('[:()]', nfl) nfls = re.split('[:()]', nfl)
@@ -444,7 +443,7 @@ class HTMLViewer(object):
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'):
return _('The file type are forbidden to access!') return 'The file type are forbidden to access!'
try: try:
data = [] data = []
i = 0 i = 0
@@ -465,7 +464,7 @@ class HTMLViewer(object):
data.append(fmt % (i, i, i, el)) data.append(fmt % (i, i, i, el))
data = ''.join(data) data = ''.join(data)
except Exception: except Exception:
return _('Can not access the file %s.') % file_path return 'Can not access the file %s.' % file_path
return '<pre>%s</pre>' % data return '<pre>%s</pre>' % data
def generate_stats_html(self, stats, app_path, profile_id, *selection): def generate_stats_html(self, stats, app_path, profile_id, *selection):

View File

@@ -20,7 +20,6 @@ import pstats
import tempfile import tempfile
import time import time
from swift import gettext_ as _
from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled
@@ -125,7 +124,7 @@ class Stats2(pstats.Stats):
def to_ods(self, *selection): def to_ods(self, *selection):
if not ODFLIB_INSTALLED: if not ODFLIB_INSTALLED:
raise ODFLIBNotInstalled(_('odfpy not installed.')) raise ODFLIBNotInstalled('odfpy not installed.')
if self.fcn_list: if self.fcn_list:
stat_list = self.fcn_list[:] stat_list = self.fcn_list[:]
order_text = " Ordered by: " + self.sort_type + '\n' order_text = " Ordered by: " + self.sort_type + '\n'

View File

@@ -83,7 +83,6 @@ import eventlet.green.profile as eprofile
import six import six
from six.moves import urllib from six.moves import urllib
from swift import gettext_ as _
from swift.common.utils import get_logger, config_true_value from swift.common.utils import get_logger, config_true_value
from swift.common.swob import Request from swift.common.swob import Request
from swift.common.middleware.x_profile.exceptions import MethodNotAllowed from swift.common.middleware.x_profile.exceptions import MethodNotAllowed
@@ -227,7 +226,7 @@ class ProfileMiddleware(object):
return '%s' % pf return '%s' % pf
except Exception as ex: except Exception as ex:
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:
_locals = locals() _locals = locals()
code = self.unwind and PROFILE_EXEC_EAGER or\ code = self.unwind and PROFILE_EXEC_EAGER or\