Fix some flakes8 warnings

This commit is contained in:
Ivan A. Melnikov 2019-01-17 13:25:22 +04:00
parent 08bc219dc5
commit 7a656153fc
10 changed files with 47 additions and 51 deletions

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
all:
flake8 --ignore=F403,F405 port_stats/

View File

@ -1,7 +1,5 @@
import collections
import subprocess
from port_stats import rpm_ffi

View File

@ -9,20 +9,20 @@ import json
import logging
import os
import subprocess
import tempfile
import sys
import tempfile
from port_stats import reports
from port_stats import tasks
from port_stats import colorize
from port_stats import lists
from port_stats import reports
from port_stats import tasks
from port_stats import utils
LOG = logging.getLogger('daily')
def main(out_dir, config_path):
os.makedirs(out_dir, mode=0755)
os.makedirs(out_dir, mode=0o755)
logging.basicConfig(
format='%(asctime)s %(levelname)-5s %(name)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
@ -40,7 +40,7 @@ def main(out_dir, config_path):
for r in config['colorize']:
r_dir = os.path.join(out_dir, r['name'])
os.makedirs(r_dir, mode=0755)
os.makedirs(r_dir, mode=0o755)
daily_report(r_dir, r, repos, all_tasks)
_unmets(config['repos'][r['new']], os.path.join(r_dir, 'unmets.txt'))
@ -49,7 +49,7 @@ def main(out_dir, config_path):
def _unmets(repo, out_file):
fno, fname = tempfile.mkstemp('.list')
try:
try:
LOG.debug('File is %s, fno is %s', fname, fno)
with os.fdopen(fno, 'w') as f:
for arch in repo['arch']:
@ -61,7 +61,6 @@ def _unmets(repo, out_file):
os.unlink(fname)
def daily_report(out_dir, what, repos, all_tasks):
LOG.info("Writing daily report for %s", what['name'])
now = datetime.datetime.utcnow()
@ -119,7 +118,9 @@ def daily_report(out_dir, what, repos, all_tasks):
# TSV for packages
with open(os.path.join(out_dir, 'colorized.tsv'), 'w') as out:
for name in sorted(by_name):
print(reports.package_one_line(name, by_name, package_tasks), file=out)
print(reports.package_one_line(name, by_name, package_tasks),
file=out)
if __name__ == '__main__':
sys.exit(main(*sys.argv[1:]))

View File

@ -30,19 +30,17 @@ import logging
import os
import re
import readline
import rlcompleter
import sys
from pydoc import pager
from port_stats import colorize
from port_stats import lists
from port_stats import tasks
from port_stats import task_predicates as tp
from port_stats import reports
from port_stats import utils
from port_stats import logs as m_logs
from port_stats import reports
from port_stats import task_predicates as tp
from port_stats import tasks
from port_stats import utils
LOG = logging.getLogger('port_stats.interactive')
@ -60,23 +58,25 @@ def package_tasks(pkg, data):
return '\n'.join(tasks.format_task(t) for t in ts)
## To targets ##
# {{{ to= targets
def dump(string):
print(string)
def append_to(filename):
if os.path.exists(filename):
LOG.info('File %s already exists, appending', filename)
def _write(string):
if os.path.exists(filename):
LOG.info('File %s already exists, appending', filename)
with open(filename, 'a') as f:
f.write(string)
f.write('\n')
return _write
## The Interactive Part ##
# }}}
# The Interactive Part
CONFIG = None
CURRENT = None
@ -97,7 +97,8 @@ def use(repo=None):
global PACKAGE_TASKS, BY_NAME, BY_COLOR, CURRENT
if repo is not None:
try:
CURRENT = (c for c in CONFIG['colorize'] if c['name'] == repo).next()
CURRENT = (c for c in CONFIG['colorize']
if c['name'] == repo).next()
except StopIteration:
raise ValueError('Unknown repo: ' + repo)
elif CURRENT is None:
@ -139,7 +140,6 @@ def _spi_by_predicate(pred, colors):
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)
to(lines)
def gspi(pattern, colors=None, to=print):
@ -225,6 +225,7 @@ def interactive_setup():
global CONFIG
CONFIG = json.load(f)
if __name__ == '__main__':
interactive_setup()
print(__doc__)

View File

@ -1,9 +1,8 @@
import logging
import subprocess
import collections
import logging
import os
import sys
import subprocess
try:
import rpm
@ -53,7 +52,7 @@ class NEVR(collections.namedtuple('NEVR', ['name', 'epoch',
if self.epoch is None:
return '%s-%s' % (self.version, self.release)
else:
return '%s:%s-%s' %(self.epoch, self.version, self.release)
return '%s:%s-%s' % (self.epoch, self.version, self.release)
@property
def evr(self):
@ -84,8 +83,7 @@ def _read_pkglist_rpm(path):
return (NEVR.from_header(h) for h in read_pkglist_headers_rpm(path))
_PKGLIST_QUERY_FORMAT='%{NAME}\t%{EPOCH}\t%{VERSION}\t%{RELEASE}\n'
_PKGLIST_QUERY_FORMAT = '%{NAME}\t%{EPOCH}\t%{VERSION}\t%{RELEASE}\n'
def _read_pkglist_pkglist_query(path):
@ -125,4 +123,3 @@ def read_srclists(prefix, arches):
def read_all_srclists(repos):
return dict((name, read_srclists(v['path'], v['arch']))
for name, v in repos.items())

View File

@ -7,7 +7,6 @@ import errno
import json
import logging
import os
import subprocess
import sys
from port_stats import lists
@ -16,6 +15,8 @@ from port_stats import tasks
from port_stats import utils
LOG = logging.getLogger(__name__)
def subtask_srpm_nevr(task, subtask_id):
try:

View File

@ -2,8 +2,8 @@
import logging
from port_stats import colorize
from port_stats import tasks
from port_stats import lists
from port_stats import tasks
LOG = logging.getLogger(__name__)

View File

@ -72,13 +72,12 @@ def evr_cmp(evr1, evr2, mode):
p_e2, p_v2, p_r2, dep)
def _tests():
assert parse_evr('3:42.8.4-alt1.mipsel0') == (3, '42.8.4', 'alt1.mipsel0')
assert parse_evr('0:42.8.4-alt1.mipsel0') == (0, '42.8.4', 'alt1.mipsel0')
assert parse_evr('42.8.4-alt1.mipsel0') == (None, '42.8.4', 'alt1.mipsel0')
assert parse_evr('1.20.0-alt1_1') == (None, '1.20.0', 'alt1_1')
assert parse_evr('1.20.0-alt1_1') == (None, '1.20.0', 'alt1_1')
assert parse_evr('1:1.20.1-alt1') == (1, '1.20.1', 'alt1')
assert evr_cmp((3, '42.8.4', 'alt1'), (3, '42.8.4', 'alt2'), 'pkg') < 0
@ -86,16 +85,16 @@ def _tests():
assert evr_cmp((3, '42.8.4', 'alt1'), (3, '42.8.4', 'alt1'), 'pkg') == 0
assert evr_cmp((3, '42.9.4', 'alt1'), (5, '42.8.4', 'alt1'), 'pkg') < 0
assert evr_cmp((1, '1.20.0', 'alt1'), (None, '1.20.0', 'alt1_1'), 'pkg') > 0
assert evr_cmp((None, '1.20.0', 'alt1_1'), (1, '1.20.0', 'alt1'), 'pkg') < 0
assert evr_cmp((1, '1.2.0', 'alt1'), (None, '1.2.0', 'alt1_1'), 'pkg') > 0
assert evr_cmp((None, '1.2.0', 'alt1_1'), (1, '1.2.0', 'alt1'), 'pkg') < 0
# 'deps' mode means that first argument satisfies requirement
# specified as second argument; here, if epoch is absent on the right
# side, it's ignored
assert evr_cmp((1, '1.20.0', 'alt1'), (None, '1.20.0', 'alt1_1'), 'deps') < 0
assert evr_cmp((None, '1.20.0', 'alt1_1'), (1, '1.20.0', 'alt1'), 'deps') < 0
assert evr_cmp((1, '1.21.0', 'alt1'), (None, '1.20.0', 'alt1_1'), 'deps') > 0
assert evr_cmp((None, '1.21.0', 'alt1_1'), (1, '1.20.0', 'alt1'), 'deps') < 0
assert evr_cmp((1, '1.2.0', 'alt1'), (None, '1.2.0', 'alt1_1'), 'deps') < 0
assert evr_cmp((None, '1.2.0', 'alt1_1'), (1, '1.2.0', 'alt1'), 'deps') < 0
assert evr_cmp((1, '1.3.0', 'alt1'), (None, '1.2.0', 'alt1_1'), 'deps') > 0
assert evr_cmp((None, '1.3.0', 'alt1_1'), (1, '1.2.0', 'alt1'), 'deps') < 0
if __name__ == '__main__':

View File

@ -2,7 +2,6 @@
import json
import logging
import os
import sys
import time
from collections import defaultdict
@ -50,7 +49,7 @@ def load_task(task_dir, name, cache=None, now=None):
data.setdefault('subtasks', {})
data.setdefault('try', 0)
return data
def load_tasks(prefixes, repo=None, cache=None):
if isinstance(prefixes, basestring):
@ -83,14 +82,14 @@ def load_tasks(prefixes, repo=None, cache=None):
return sorted(tasks, key=lambda t: t.get('taskid'))
_FORMAT_SUBTASK = {
'srpm': lambda st: 'srpm ' + st.get('srpm'),
'delete': lambda st: 'delete ' + st.get('package'),
'repo': lambda st: '%s %s' % (st.get('dir'),
st.get('tag') or st.get('tag_name'))
'srpm': lambda st: 'srpm ' + st.get('srpm'),
'delete': lambda st: 'delete ' + st.get('package'),
'repo': lambda st: '%s %s' % (st.get('dir'),
st.get('tag') or st.get('tag_name'))
}
def format_subtask(subtask, extra_info=None):
stype = subtask.get('type')
result = _FORMAT_SUBTASK.get(stype, utils.format_dict)(subtask)
@ -102,7 +101,7 @@ def format_subtask(subtask, extra_info=None):
def format_task(info, extra_info=None):
head = '%(taskid)s %(state)s try=%(try)s %(owner)s' % info
head = '%(taskid)s %(state)s try=%(try)s %(owner)s' % info
depends = sorted(utils.maybe_int(x) for x in info.get('depends', []))
if depends:
@ -152,9 +151,8 @@ def tasks_by_package(task_list):
try:
for p in task_packages(task):
result[p].append(task)
except Exception as ex:
except Exception:
LOG.error('Failed to parse task: %s',
utils.format_dict(task), exc_info=True)
return dict((p, sorted(l, key=lambda t: utils.maybe_int(t['taskid'])))
for p, l in result.iteritems())

View File

@ -1,8 +1,6 @@
import collections
import datetime
import json
import os
def format_timestamp(ts, fmt='%Y-%m-%d %H:%M:%S'):