Commit 6045932f authored by Vincent Pelletier's avatar Vincent Pelletier

Use pkgutil instead of pkg_resources.

parent fcdcc68b
...@@ -42,23 +42,16 @@ import itertools ...@@ -42,23 +42,16 @@ import itertools
import json import json
import math import math
import os import os
import pkgutil
import platform import platform
import re import re
import shlex import shlex
import sys import sys
import time import time
import traceback import traceback
try:
import pkg_resources def getResource(name, encoding='utf-8'):
except ImportError: return pkgutil.get_data(__name__, name).decode(encoding)
# By default, assume resources are next to __file__
abs_file_container = os.path.abspath(os.path.dirname(__file__))
def getResource(name):
return open(os.path.join(abs_file_container, name)).read()
else:
abs_file_container = None
def getResource(name):
return pkg_resources.resource_string(__name__, name)
FILE_OPENER_LIST = [ FILE_OPENER_LIST = [
(gzip.open, IOError), (gzip.open, IOError),
...@@ -1100,7 +1093,6 @@ def _scanstring(*args, **kw): ...@@ -1100,7 +1093,6 @@ def _scanstring(*args, **kw):
json.decoder.scanstring = _scanstring json.decoder.scanstring = _scanstring
def main(): def main():
global abs_file_container
parser = ShlexArgumentParser(description='Compute Apdex out of ' parser = ShlexArgumentParser(description='Compute Apdex out of '
'apache-style log files', fromfile_prefix_chars='@') 'apache-style log files', fromfile_prefix_chars='@')
parser.add_argument('logfile', nargs='*', parser.add_argument('logfile', nargs='*',
...@@ -1134,8 +1126,7 @@ def main(): ...@@ -1134,8 +1126,7 @@ def main():
group.add_argument('-s', '--stats', action='store_true', group.add_argument('-s', '--stats', action='store_true',
help='Enable parsing stats (time spent parsing input, time spent ' help='Enable parsing stats (time spent parsing input, time spent '
'generating output, ...)') 'generating output, ...)')
group.add_argument('--js', default=abs_file_container, group.add_argument('--js', help='Folder containing needed js files.')
help='Folder containing needed js files. Default: %(default)s')
group.add_argument('--js-embed', action='store_true', group.add_argument('--js-embed', action='store_true',
help='Embed js files instead of linking to them.') help='Embed js files instead of linking to them.')
group.add_argument('--fixed-yrange', nargs='?', type=int, const=-1, group.add_argument('--fixed-yrange', nargs='?', type=int, const=-1,
...@@ -1171,7 +1162,6 @@ def main(): ...@@ -1171,7 +1162,6 @@ def main():
'ignored. Useful to exclude monitoring systems.') 'ignored. Useful to exclude monitoring systems.')
args = parser.parse_args() args = parser.parse_args()
abs_file_container = getattr(args, 'js', abs_file_container)
if DURATION_US_FORMAT in args.logformat: if DURATION_US_FORMAT in args.logformat:
getDuration = lambda x: int(x.group('duration')) getDuration = lambda x: int(x.group('duration'))
elif DURATION_S_FORMAT in args.logformat: elif DURATION_S_FORMAT in args.logformat:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment