flake8: follow E265 rule

This commit is contained in:
Yuming Zhu 2020-02-25 22:50:14 +08:00
parent 642508ccf6
commit 97cfaa4fcf
27 changed files with 794 additions and 793 deletions

View file

@ -50,7 +50,7 @@ def getTag(session, tag, event=None):
if (tag, event) in cache:
ts, info = cache[(tag,event)]
if now - ts < 600:
#use the cache
# use the cache
return info
info = session.getTag(tag, event=event)
if info:
@ -83,7 +83,7 @@ class ManagedRepo(object):
self.first_seen = time.time()
if self.current:
order = self.session.getFullInheritance(self.tag_id, event=self.event_id)
#order may contain same tag more than once
# order may contain same tag more than once
tags = {self.tag_id : 1}
for x in order:
tags[x['parent_id']] = 1
@ -156,13 +156,13 @@ class ManagedRepo(object):
- timestamp really, really old
"""
timeout = 36000
#XXX - config
# XXX - config
if self.state != koji.REPO_INIT:
return False
age = time.time() - max(self.event_ts, self.first_seen)
#the first_seen timestamp is also factored in because a repo can be
#created from an older event and should not be expired based solely on
#that event's timestamp.
# the first_seen timestamp is also factored in because a repo can be
# created from an older event and should not be expired based solely on
# that event's timestamp.
return age > timeout
def tryDelete(self):
@ -177,8 +177,8 @@ class ManagedRepo(object):
lifetime = self.options.deleted_repo_lifetime
# (should really be called expired_repo_lifetime)
try:
#also check dir age. We do this because a repo can be created from an older event
#and should not be removed based solely on that event's timestamp.
# also check dir age. We do this because a repo can be created from an older event
# and should not be removed based solely on that event's timestamp.
mtime = os.stat(path).st_mtime
except OSError as e:
if e.errno == 2:
@ -200,7 +200,7 @@ class ManagedRepo(object):
if self.state != koji.REPO_EXPIRED:
raise koji.GenericError("Repo not expired")
if self.session.repoDelete(self.repo_id) > 0:
#cannot delete, we are referenced by a buildroot
# cannot delete, we are referenced by a buildroot
self.logger.debug("Cannot delete repo %s, still referenced" % self.repo_id)
return False
self.logger.info("Deleted repo %s" % self.repo_id)
@ -299,9 +299,9 @@ class RepoManager(object):
(childpid, status) = os.waitpid(pid, os.WNOHANG)
except OSError as e:
if e.errno != errno.ECHILD:
#should not happen
# should not happen
raise
#otherwise assume the process is gone
# otherwise assume the process is gone
self.logger.info("%s: %s" % (prefix, e))
return True
if childpid != 0:
@ -345,7 +345,7 @@ class RepoManager(object):
repo_id = data['id']
repo = self.repos.get(repo_id)
if repo:
#we're already tracking it
# we're already tracking it
if repo.state != data['state']:
self.logger.info('State changed for repo %s: %s -> %s'
%(repo_id, koji.REPO_STATES[repo.state], koji.REPO_STATES[data['state']]))
@ -383,7 +383,7 @@ class RepoManager(object):
repo.current = False
if repo.expire_ts is None:
repo.expire_ts = time.time()
#also no point in further checking
# also no point in further checking
continue
to_check.append(repo)
if self.logger.isEnabledFor(logging.DEBUG):
@ -441,7 +441,7 @@ class RepoManager(object):
Also, warn about any oddities"""
if self.delete_pids:
#skip
# skip
return
if not os.path.exists(topdir):
self.logger.debug("%s doesn't exist, skipping", topdir)
@ -466,14 +466,14 @@ class RepoManager(object):
self.logger.debug("%s/%s not an int, skipping", tagdir, repo_id)
continue
if repo_id in self.repos:
#we're already managing it, no need to deal with it here
# we're already managing it, no need to deal with it here
continue
repodir = "%s/%s" % (tagdir, repo_id)
try:
# lstat because it could be link to another volume
dirstat = os.lstat(repodir)
except OSError:
#just in case something deletes the repo out from under us
# just in case something deletes the repo out from under us
self.logger.debug("%s deleted already?!", repodir)
continue
symlink = False
@ -513,18 +513,18 @@ class RepoManager(object):
stats = self.tag_use_stats.get(tag_id)
now = time.time()
if stats and now - stats['ts'] < 3600:
#use the cache
# use the cache
return stats
data = self.session.listBuildroots(tagID=tag_id,
queryOpts={'order': '-create_event_id', 'limit' : 100})
#XXX magic number (limit)
# XXX magic number (limit)
if data:
tag_name = data[0]['tag_name']
else:
tag_name = "#%i" % tag_id
stats = {'data': data, 'ts': now, 'tag_name': tag_name}
recent = [x for x in data if now - x['create_ts'] < 3600 * 24]
#XXX magic number
# XXX magic number
stats ['n_recent'] = len(recent)
self.tag_use_stats[tag_id] = stats
self.logger.debug("tag %s recent use count: %i" % (tag_name, len(recent)))
@ -593,7 +593,7 @@ class RepoManager(object):
if n_deletes >= self.options.delete_batch_size:
break
if repo.expired():
#try to delete
# try to delete
if repo.tryDelete():
n_deletes += 1
del self.repos[repo.repo_id]
@ -652,7 +652,7 @@ class RepoManager(object):
t['build_tag'] for t in self.session.getBuildTargets()
if not koji.util.multi_fnmatch(t['build_tag_name'], ignore)
])
#index repos by tag
# index repos by tag
tag_repos = {}
for repo in to_list(self.repos.values()):
tag_repos.setdefault(repo.tag_id, []).append(repo)
@ -931,7 +931,7 @@ def get_options():
'repo_tasks_limit' : 10,
'delete_batch_size' : 3,
'deleted_repo_lifetime': 7*24*3600,
#XXX should really be called expired_repo_lifetime
# XXX should really be called expired_repo_lifetime
'dist_repo_lifetime': 7*24*3600,
'recent_tasks_lifetime': 600,
'sleeptime' : 15,
@ -1003,7 +1003,7 @@ if __name__ == "__main__":
sys.stderr.write("Cannot write to logfile: %s\n" % options.logfile)
sys.exit(1)
koji.add_file_logger("koji", options.logfile)
#note we're setting logging for koji.*
# note we're setting logging for koji.*
logger = logging.getLogger("koji")
if options.debug:
logger.setLevel(logging.DEBUG)
@ -1024,7 +1024,7 @@ if __name__ == "__main__":
session.login()
elif koji.krbV and options.principal and options.keytab:
session.krb_login(options.principal, options.keytab, options.ccache)
#get an exclusive session
# get an exclusive session
try:
session.exclusiveSession(force=options.force_lock)
except koji.AuthLockError: