More python3 compatibility
Try to convert all names, versions and releases to str when reading. Now we can actually use the interactive shell.
This commit is contained in:
parent
b674458df2
commit
cfd8dee1c6
@ -159,7 +159,7 @@ def update_days(to=pager):
|
||||
|
||||
def _spi_by_predicate(pred, colors):
|
||||
colors = colors or colorize.COLORS
|
||||
return b'\n'.join(
|
||||
return '\n'.join(
|
||||
reports.package_one_line(name, BY_NAME, PACKAGE_TASKS)
|
||||
for name in sorted(BY_NAME)
|
||||
if pred(name) and BY_NAME[name][0] in colors)
|
||||
@ -256,7 +256,7 @@ def fti(num, to=print):
|
||||
|
||||
|
||||
def _page_file(log_file, to):
|
||||
with open(log_file, 'r') as f:
|
||||
with open(log_file, 'rb') as f:
|
||||
log = f.read().decode('utf-8', errors='replace')
|
||||
to(log_file + ':\n\n' + log)
|
||||
|
||||
|
@ -14,16 +14,24 @@ from port_stats import rpm_ffi
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _as_str(item):
|
||||
if isinstance(item, str):
|
||||
return item
|
||||
if isinstance(item, bytes):
|
||||
return item.decode('utf-8', errors='replace')
|
||||
return str(item)
|
||||
|
||||
|
||||
class NEVR(collections.namedtuple('NEVR', ['name', 'epoch',
|
||||
'version', 'release'])):
|
||||
|
||||
if rpm:
|
||||
@classmethod
|
||||
def from_header(cls, header):
|
||||
return cls(header[rpm.RPMTAG_NAME],
|
||||
header[rpm.RPMTAG_EPOCH],
|
||||
header[rpm.RPMTAG_VERSION],
|
||||
header[rpm.RPMTAG_RELEASE])
|
||||
return cls(_as_str(header[rpm.RPMTAG_NAME]),
|
||||
_as_str(header[rpm.RPMTAG_EPOCH]),
|
||||
_as_str(header[rpm.RPMTAG_VERSION]),
|
||||
_as_str(header[rpm.RPMTAG_RELEASE]))
|
||||
|
||||
@classmethod
|
||||
def from_tsv_line(cls, line):
|
||||
@ -47,7 +55,7 @@ class NEVR(collections.namedtuple('NEVR', ['name', 'epoch',
|
||||
LOG.error("Failed to parse epoch from line: %s",
|
||||
line, exc_info=True)
|
||||
return None
|
||||
return cls(n, e, v, r)
|
||||
return cls(_as_str(n), e, _as_str(v), _as_str(r))
|
||||
|
||||
def format_evr(self):
|
||||
if self.epoch is None:
|
||||
@ -141,7 +149,7 @@ def read_src_dot_list(repo_path):
|
||||
try:
|
||||
name, evr = line.split(b'\t', 2)[:2]
|
||||
e, v, r = rpm_ffi.parse_evr(evr)
|
||||
result.append(NEVR(name, e, v, r))
|
||||
result.append(NEVR(_as_str(name), e, _as_str(v), _as_str(r)))
|
||||
except Exception:
|
||||
LOG.warning('Failed to parse line %r', line, exc_info=True)
|
||||
finally:
|
||||
|
Loading…
Reference in New Issue
Block a user