Python 3.x compatibility
Now the code is python2 and python3 compatible, and they both generate the same output regardless of subtle differences. Change-Id: Ic6b908387becf4d0de5d9da72ce6915d3f7c3b1c
This commit is contained in:
parent
c095b83d35
commit
809bb6add3
|
@ -11,8 +11,8 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import urllib2
|
|
||||||
|
|
||||||
|
from six.moves.urllib.parse import urlparse
|
||||||
|
|
||||||
__version__ = '1.1.0'
|
__version__ = '1.1.0'
|
||||||
|
|
||||||
|
@ -96,7 +96,11 @@ class LogEntry(object):
|
||||||
self.data += EXTRALINES_PADDING + line
|
self.data += EXTRALINES_PADDING + line
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
return cmp(self.dt, other.dt)
|
return cmp(self.dt, other.dt) * 2 + cmp(self.alias, other.alias)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.dt < other.dt or (self.dt == other.dt and
|
||||||
|
(self.alias < other.alias))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s [%s] %s' % (self.dt_str, self.alias, self.data.rstrip('\n'))
|
return '%s [%s] %s' % (self.dt_str, self.alias, self.data.rstrip('\n'))
|
||||||
|
@ -327,7 +331,7 @@ class TSLogParser(LogParser):
|
||||||
class LogFile(object):
|
class LogFile(object):
|
||||||
def _detect_format(self, filename, cfg):
|
def _detect_format(self, filename, cfg):
|
||||||
parsers = []
|
parsers = []
|
||||||
for cls in LOG_TYPES.values() + DETECTED_LOG_TYPES:
|
for cls in list(LOG_TYPES.values()) + DETECTED_LOG_TYPES:
|
||||||
if cls is None:
|
if cls is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -394,7 +398,7 @@ class LogFile(object):
|
||||||
print("CACHED: %s at %s" % (url, path), file=sys.stderr)
|
print("CACHED: %s at %s" % (url, path), file=sys.stderr)
|
||||||
return path
|
return path
|
||||||
print("DOWNLOADING: %s to %s" % (url, path), file=sys.stderr)
|
print("DOWNLOADING: %s to %s" % (url, path), file=sys.stderr)
|
||||||
http_in = urllib2.urlopen(url)
|
http_in = urlopen(url)
|
||||||
file_out = open(path, 'w')
|
file_out = open(path, 'w')
|
||||||
file_out.write(http_in.read())
|
file_out.write(http_in.read())
|
||||||
file_out.close()
|
file_out.close()
|
||||||
|
@ -521,7 +525,7 @@ def reduce_tree(tree):
|
||||||
if not len(tree[1]):
|
if not len(tree[1]):
|
||||||
return tree
|
return tree
|
||||||
# Reduce the names of all subdirectories in this directory
|
# Reduce the names of all subdirectories in this directory
|
||||||
reduced = reduce_strings(tree[1].keys())
|
reduced = reduce_strings(list(tree[1].keys()))
|
||||||
# For each of those subdirectories reduce subtrees using the reduced name
|
# For each of those subdirectories reduce subtrees using the reduced name
|
||||||
# but we still use the original diretory's name as the directory key.
|
# but we still use the original diretory's name as the directory key.
|
||||||
return (tree[0],
|
return (tree[0],
|
||||||
|
@ -634,7 +638,7 @@ def all_unique_values(*args):
|
||||||
|
|
||||||
values = set()
|
values = set()
|
||||||
for a in args:
|
for a in args:
|
||||||
vals = a.values()
|
vals = list(a.values())
|
||||||
if vals and isinstance(vals[0], tuple):
|
if vals and isinstance(vals[0], tuple):
|
||||||
vals = [reconstruct_path(v) for v in vals]
|
vals = [reconstruct_path(v) for v in vals]
|
||||||
values.update(vals)
|
values.update(vals)
|
||||||
|
@ -736,8 +740,7 @@ one has not been provided:'
|
||||||
2016-02-01 10:26:34.680 [1/N-API]
|
2016-02-01 10:26:34.680 [1/N-API]
|
||||||
2016-02-01 10:27:34.680 [2/N-CPU]
|
2016-02-01 10:27:34.680 [2/N-CPU]
|
||||||
"""
|
"""
|
||||||
|
parser = MyParser(description=general_description,
|
||||||
parser = MyParser(description=general_description, version=__version__,
|
|
||||||
epilog=general_epilog, argument_default='',
|
epilog=general_epilog, argument_default='',
|
||||||
formatter_class=argparse.RawTextHelpFormatter)
|
formatter_class=argparse.RawTextHelpFormatter)
|
||||||
parser.add_argument('--log-base ', '-b', dest='log_base',
|
parser.add_argument('--log-base ', '-b', dest='log_base',
|
||||||
|
|
Loading…
Reference in New Issue