diff --git a/hub/kojihub.py b/hub/kojihub.py index 47582eec..23070cba 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -76,11 +76,11 @@ class Task(object): ('task.id', 'id'), ('task.state', 'state'), ('task.create_time', 'create_time'), - ('EXTRACT(EPOCH FROM create_time)','create_ts'), + ('EXTRACT(EPOCH FROM create_time)', 'create_ts'), ('task.start_time', 'start_time'), ('EXTRACT(EPOCH FROM task.start_time)', 'start_ts'), ('task.completion_time', 'completion_time'), - ('EXTRACT(EPOCH FROM completion_time)','completion_ts'), + ('EXTRACT(EPOCH FROM completion_time)', 'completion_ts'), ('task.channel_id', 'channel_id'), ('task.host_id', 'host_id'), ('task.parent', 'parent'), @@ -93,11 +93,11 @@ class Task(object): ('task.priority', 'priority'), ('task.weight', 'weight')) - def __init__(self,id): + def __init__(self, id): self.id = id self.logger = logging.getLogger("koji.hub.Task") - def verifyHost(self,host_id=None): + def verifyHost(self, host_id=None): """Verify that host owns task""" if host_id is None: host_id = context.session.host_id @@ -113,16 +113,16 @@ class Task(object): state, otherhost = r return (state == koji.TASK_STATES['OPEN'] and otherhost == host_id) - def assertHost(self,host_id): + def assertHost(self, host_id): if not self.verifyHost(host_id): - raise koji.ActionNotAllowed, "host %d does not own task %d" % (host_id,self.id) + raise koji.ActionNotAllowed, "host %d does not own task %d" % (host_id, self.id) def getOwner(self): """Return the owner (user_id) for this task""" q = """SELECT owner FROM task WHERE id=%(id)i""" return _singleValue(q, vars(self)) - def verifyOwner(self,user_id=None): + def verifyOwner(self, user_id=None): """Verify that user owns task""" if user_id is None: user_id = context.session.user_id @@ -137,11 +137,11 @@ class Task(object): (owner,) = r return (owner == user_id) - def assertOwner(self,user_id=None): + def assertOwner(self, user_id=None): if not self.verifyOwner(user_id): - raise koji.ActionNotAllowed, "user %d does not own task %d" % (user_id,self.id) + raise koji.ActionNotAllowed, "user %d does not own task %d" % (user_id, self.id) - def lock(self,host_id,newstate='OPEN',force=False): + def lock(self, host_id, newstate='OPEN', force=False): """Attempt to associate the task for host, either to assign or open returns True if successful, False otherwise""" @@ -153,14 +153,14 @@ class Task(object): task_id = self.id if not force: q = """SELECT state,host_id FROM task WHERE id=%(task_id)i FOR UPDATE""" - r = _fetchSingle(q,locals()) + r = _fetchSingle(q, locals()) if not r: raise koji.GenericError, "No such task: %i" % task_id state, otherhost = r if state == koji.TASK_STATES['FREE']: if otherhost is not None: log_error("Error: task %i is both free and locked (host %i)" - % (task_id,otherhost)) + % (task_id, otherhost)) return False elif state == koji.TASK_STATES['ASSIGNED']: if otherhost is None: @@ -174,7 +174,7 @@ class Task(object): else: if otherhost is None: log_error("Error: task %i is non-free but unlocked (state %i)" - % (task_id,state)) + % (task_id, state)) return False #if we reach here, task is either # - free and unlocked @@ -190,17 +190,17 @@ class Task(object): self.runCallbacks('postTaskStateChange', info, 'host_id', host_id) return True - def assign(self,host_id,force=False): + def assign(self, host_id, force=False): """Attempt to assign the task to host. returns True if successful, False otherwise""" - return self.lock(host_id,'ASSIGNED',force) + return self.lock(host_id, 'ASSIGNED', force) - def open(self,host_id): + def open(self, host_id): """Attempt to open the task for host. returns task data if successful, None otherwise""" - if self.lock(host_id,'OPEN'): + if self.lock(host_id, 'OPEN'): # get more complete data to return fields = self.fields + (('task.request', 'request'),) query = QueryProcessor(tables=['task'], clauses=['id=%(id)i'], values=vars(self), @@ -221,23 +221,23 @@ class Task(object): task_id = self.id # access checks should be performed by calling function query = """SELECT state FROM task WHERE id = %(id)i FOR UPDATE""" - row = _fetchSingle(query,vars(self)) + row = _fetchSingle(query, vars(self)) if not row: raise koji.GenericError, "No such task: %i" % self.id oldstate = row[0] - if koji.TASK_STATES[oldstate] in ['CLOSED','CANCELED','FAILED']: + if koji.TASK_STATES[oldstate] in ['CLOSED', 'CANCELED', 'FAILED']: raise koji.GenericError, "Cannot free task %i, state is %s" % \ - (self.id,koji.TASK_STATES[oldstate]) + (self.id, koji.TASK_STATES[oldstate]) newstate = koji.TASK_STATES['FREE'] newhost = None q = """UPDATE task SET state=%(newstate)s,host_id=%(newhost)s WHERE id=%(task_id)s""" - _dml(q,locals()) + _dml(q, locals()) self.runCallbacks('postTaskStateChange', info, 'state', koji.TASK_STATES['FREE']) self.runCallbacks('postTaskStateChange', info, 'host_id', None) return True - def setWeight(self,weight): + def setWeight(self, weight): """Set weight for task""" task_id = self.id weight = float(weight) @@ -245,7 +245,7 @@ class Task(object): self.runCallbacks('preTaskStateChange', info, 'weight', weight) # access checks should be performed by calling function q = """UPDATE task SET weight=%(weight)s WHERE id = %(task_id)s""" - _dml(q,locals()) + _dml(q, locals()) self.runCallbacks('postTaskStateChange', info, 'weight', weight) def setPriority(self, priority, recurse=False): @@ -256,7 +256,7 @@ class Task(object): self.runCallbacks('preTaskStateChange', info, 'priority', priority) # access checks should be performed by calling function q = """UPDATE task SET priority=%(priority)s WHERE id = %(task_id)s""" - _dml(q,locals()) + _dml(q, locals()) self.runCallbacks('postTaskStateChange', info, 'priority', priority) if recurse: @@ -265,7 +265,7 @@ class Task(object): for (child_id,) in _fetchMulti(q, locals()): Task(child_id).setPriority(priority, recurse=True) - def _close(self,result,state): + def _close(self, result, state): """Mark task closed and set response Returns True if successful, False if not""" @@ -286,20 +286,20 @@ class Task(object): self.runCallbacks('postTaskStateChange', info, 'state', state) self.runCallbacks('postTaskStateChange', info, 'completion_ts', now) - def close(self,result): + def close(self, result): # access checks should be performed by calling function - self._close(result,koji.TASK_STATES['CLOSED']) + self._close(result, koji.TASK_STATES['CLOSED']) - def fail(self,result): + def fail(self, result): # access checks should be performed by calling function - self._close(result,koji.TASK_STATES['FAILED']) + self._close(result, koji.TASK_STATES['FAILED']) def getState(self): query = """SELECT state FROM task WHERE id = %(id)i""" return _singleValue(query, vars(self)) def isFinished(self): - return (koji.TASK_STATES[self.getState()] in ['CLOSED','CANCELED','FAILED']) + return (koji.TASK_STATES[self.getState()] in ['CLOSED', 'CANCELED', 'FAILED']) def isCanceled(self): return (self.getState() == koji.TASK_STATES['CANCELED']) @@ -307,7 +307,7 @@ class Task(object): def isFailed(self): return (self.getState() == koji.TASK_STATES['FAILED']) - def cancel(self,recurse=True): + def cancel(self, recurse=True): """Cancel this task. A task can only be canceled if it is not already in the 'CLOSED' state. @@ -321,13 +321,13 @@ class Task(object): self.runCallbacks('preTaskStateChange', info, 'completion_ts', now) task_id = self.id q = """SELECT state FROM task WHERE id = %(task_id)s FOR UPDATE""" - state = _singleValue(q,locals()) + state = _singleValue(q, locals()) st_canceled = koji.TASK_STATES['CANCELED'] st_closed = koji.TASK_STATES['CLOSED'] st_failed = koji.TASK_STATES['FAILED'] if state == st_canceled: return True - elif state in [st_closed,st_failed]: + elif state in [st_closed, st_failed]: return False update = """UPDATE task SET state = %(st_canceled)i, completion_time = NOW() WHERE id = %(task_id)i""" @@ -351,10 +351,10 @@ class Task(object): """Cancel child tasks""" task_id = self.id q = """SELECT id FROM task WHERE parent = %(task_id)i""" - for (id,) in _fetchMulti(q,locals()): + for (id,) in _fetchMulti(q, locals()): Task(id).cancel(recurse=True) - def cancelFull(self,strict=True): + def cancelFull(self, strict=True): """Cancel this task and every other task in its group If strict is true, then this must be a top-level task @@ -362,10 +362,10 @@ class Task(object): """ task_id = self.id q = """SELECT parent FROM task WHERE id = %(task_id)i FOR UPDATE""" - parent = _singleValue(q,locals()) + parent = _singleValue(q, locals()) if parent is not None: if strict: - raise koji.GenericError, "Task %d is not top-level (parent=%d)" % (task_id,parent) + raise koji.GenericError, "Task %d is not top-level (parent=%d)" % (task_id, parent) #otherwise, find the top-level task and go from there seen = {task_id:1} while parent is not None: @@ -373,7 +373,7 @@ class Task(object): raise koji.GenericError, "Task LOOP at task %i" % task_id task_id = parent seen[task_id] = 1 - parent = _singleValue(q,locals()) + parent = _singleValue(q, locals()) return Task(task_id).cancelFull(strict=True) #We handle the recursion ourselves, since self.cancel will stop at #canceled or closed tasks. @@ -387,7 +387,7 @@ class Task(object): raise koji.GenericError, "Task LOOP at task %i" % task_id seen[task_id] = 1 Task(task_id).cancel(recurse=False) - for (child_id,) in _fetchMulti(q_children,locals()): + for (child_id,) in _fetchMulti(q_children, locals()): tasklist.append(child_id) def getRequest(self): @@ -408,7 +408,7 @@ class Task(object): state, xml_result = r if koji.TASK_STATES[state] == 'CANCELED': raise koji.GenericError, "Task %i is canceled" % self.id - elif koji.TASK_STATES[state] not in ['CLOSED','FAILED']: + elif koji.TASK_STATES[state] not in ['CLOSED', 'FAILED']: raise koji.GenericError, "Task %i is not finished" % self.id # If the result is a Fault, then loads will raise it # This is probably what we want to happen. @@ -467,7 +467,7 @@ class Task(object): koji.plugin.run_callbacks(cbtype, attribute=attr, old=old_val, new=new_val, info=info) -def make_task(method,arglist,**opts): +def make_task(method, arglist, **opts): """Create a task This call should not be directly exposed via xmlrpc @@ -482,23 +482,23 @@ def make_task(method,arglist,**opts): """ if opts.has_key('parent'): # for subtasks, we use some of the parent's options as defaults - fields = ('state','owner','channel_id','priority','arch') + fields = ('state', 'owner', 'channel_id', 'priority', 'arch') q = """SELECT %s FROM task WHERE id = %%(parent)i""" % ','.join(fields) - r = _fetchSingle(q,opts) + r = _fetchSingle(q, opts) if not r: raise koji.GenericError, "Invalid parent task: %(parent)s" % opts - pdata = dict(zip(fields,r)) + pdata = dict(zip(fields, r)) if pdata['state'] != koji.TASK_STATES['OPEN']: raise koji.GenericError, "Parent task (id %(parent)s) is not open" % opts #default to a higher priority than parent opts.setdefault('priority', pdata['priority'] - 1) for f in ('owner', 'arch'): - opts.setdefault(f,pdata[f]) - opts.setdefault('label',None) + opts.setdefault(f, pdata[f]) + opts.setdefault('label', None) else: - opts.setdefault('priority',koji.PRIO_DEFAULT) + opts.setdefault('priority', koji.PRIO_DEFAULT) #calling function should enforce priority limitations, if applicable - opts.setdefault('arch','noarch') + opts.setdefault('arch', 'noarch') if not context.session.logged_in: raise koji.GenericError, 'task must have an owner' else: @@ -589,49 +589,49 @@ def eventCondition(event, table=None): raise koji.GenericError, "Invalid event: %r" % event def readGlobalInheritance(event=None): - c=context.cnx.cursor() - fields = ('tag_id','parent_id','name','priority','maxdepth','intransitive', - 'noconfig','pkg_filter') - q="""SELECT %s FROM tag_inheritance JOIN tag ON parent_id = id + c = context.cnx.cursor() + fields = ('tag_id', 'parent_id', 'name', 'priority', 'maxdepth', 'intransitive', + 'noconfig', 'pkg_filter') + q = """SELECT %s FROM tag_inheritance JOIN tag ON parent_id = id WHERE %s ORDER BY priority """ % (",".join(fields), eventCondition(event)) - c.execute(q,locals()) + c.execute(q, locals()) #convert list of lists into a list of dictionaries - return [ dict(zip(fields,x)) for x in c.fetchall() ] + return [dict(zip(fields, x)) for x in c.fetchall()] -def readInheritanceData(tag_id,event=None): - c=context.cnx.cursor() - fields = ('parent_id','name','priority','maxdepth','intransitive','noconfig','pkg_filter') - q="""SELECT %s FROM tag_inheritance JOIN tag ON parent_id = id +def readInheritanceData(tag_id, event=None): + c = context.cnx.cursor() + fields = ('parent_id', 'name', 'priority', 'maxdepth', 'intransitive', 'noconfig', 'pkg_filter') + q = """SELECT %s FROM tag_inheritance JOIN tag ON parent_id = id WHERE %s AND tag_id = %%(tag_id)i ORDER BY priority """ % (",".join(fields), eventCondition(event)) - c.execute(q,locals()) + c.execute(q, locals()) #convert list of lists into a list of dictionaries - data = [ dict(zip(fields,x)) for x in c.fetchall() ] + data = [dict(zip(fields, x)) for x in c.fetchall()] # include the current tag_id as child_id, so we can retrace the inheritance chain later for datum in data: datum['child_id'] = tag_id return data -def readDescendantsData(tag_id,event=None): - c=context.cnx.cursor() - fields = ('tag_id','parent_id','name','priority','maxdepth','intransitive','noconfig','pkg_filter') - q="""SELECT %s FROM tag_inheritance JOIN tag ON tag_id = id +def readDescendantsData(tag_id, event=None): + c = context.cnx.cursor() + fields = ('tag_id', 'parent_id', 'name', 'priority', 'maxdepth', 'intransitive', 'noconfig', 'pkg_filter') + q = """SELECT %s FROM tag_inheritance JOIN tag ON tag_id = id WHERE %s AND parent_id = %%(tag_id)i ORDER BY priority """ % (",".join(fields), eventCondition(event)) - c.execute(q,locals()) + c.execute(q, locals()) #convert list of lists into a list of dictionaries - data = [ dict(zip(fields,x)) for x in c.fetchall() ] + data = [dict(zip(fields, x)) for x in c.fetchall()] return data def writeInheritanceData(tag_id, changes, clear=False): """Add or change inheritance data for a tag""" context.session.assertPerm('admin') - fields = ('parent_id','priority','maxdepth','intransitive','noconfig','pkg_filter') - if isinstance(changes,dict): + fields = ('parent_id', 'priority', 'maxdepth', 'intransitive', 'noconfig', 'pkg_filter') + if isinstance(changes, dict): changes = [changes] for link in changes: check_fields = fields @@ -641,7 +641,7 @@ def writeInheritanceData(tag_id, changes, clear=False): if not link.has_key(f): raise koji.GenericError, "No value for %s" % f # read current data and index - data = dict([[link['parent_id'],link] for link in readInheritanceData(tag_id)]) + data = dict([[link['parent_id'], link] for link in readInheritanceData(tag_id)]) for link in changes: link['is_update'] = True parent_id = link['parent_id'] @@ -681,7 +681,7 @@ def writeInheritanceData(tag_id, changes, clear=False): if len(dups) <= 1: continue #oops, duplicate entries for a single priority - dup_ids = [ link['parent_id'] for link in dups] + dup_ids = [link['parent_id'] for link in dups] raise koji.GenericError, "Inheritance priorities must be unique (pri %s: %r )" % (pri, dup_ids) for parent_id, link in data.iteritems(): if not link.get('is_update'): @@ -705,17 +705,17 @@ def writeInheritanceData(tag_id, changes, clear=False): insert.make_create() insert.execute() -def readFullInheritance(tag_id,event=None,reverse=False,stops=None,jumps=None): +def readFullInheritance(tag_id, event=None, reverse=False, stops=None, jumps=None): """Returns a list representing the full, ordered inheritance from tag""" if stops is None: stops = {} if jumps is None: jumps = {} order = [] - readFullInheritanceRecurse(tag_id,event,order,stops,{},{},0,None,False,[],reverse,jumps) + readFullInheritanceRecurse(tag_id, event, order, stops, {}, {}, 0, None, False, [], reverse, jumps) return order -def readFullInheritanceRecurse(tag_id,event,order,prunes,top,hist,currdepth,maxdepth,noconfig,pfilter,reverse,jumps): +def readFullInheritanceRecurse(tag_id, event, order, prunes, top, hist, currdepth, maxdepth, noconfig, pfilter, reverse, jumps): if maxdepth is not None and maxdepth < 1: return #note: maxdepth is relative to where we are, but currdepth is absolute from @@ -724,9 +724,9 @@ def readFullInheritanceRecurse(tag_id,event,order,prunes,top,hist,currdepth,maxd top = top.copy() top[tag_id] = 1 if reverse: - node = readDescendantsData(tag_id,event) + node = readDescendantsData(tag_id, event) else: - node = readInheritanceData(tag_id,event) + node = readInheritanceData(tag_id, event) for link in node: if reverse: id = link['tag_id'] @@ -738,7 +738,7 @@ def readFullInheritanceRecurse(tag_id,event,order,prunes,top,hist,currdepth,maxd #LOOP! if event is None: # only log if the issue is current - log_error("Warning: INHERITANCE LOOP detected at %s -> %s, pruning" % (tag_id,id)) + log_error("Warning: INHERITANCE LOOP detected at %s -> %s, pruning" % (tag_id, id)) #auto prune continue if prunes.has_key(id): @@ -763,7 +763,7 @@ def readFullInheritanceRecurse(tag_id,event,order,prunes,top,hist,currdepth,maxd if maxdepth is not None: nextdepth = maxdepth - 1 elif maxdepth is not None: - nextdepth = min(nextdepth,maxdepth) - 1 + nextdepth = min(nextdepth, maxdepth) - 1 link['nextdepth'] = nextdepth link['currdepth'] = currdepth #propagate noconfig and pkg_filter controls @@ -807,7 +807,7 @@ def readFullInheritanceRecurse(tag_id,event,order,prunes,top,hist,currdepth,maxd if link['intransitive'] and reverse: # add link, but don't follow it continue - readFullInheritanceRecurse(id,event,order,prunes,top,hist,currdepth,nextdepth,noconfig,filter,reverse,jumps) + readFullInheritanceRecurse(id, event, order, prunes, top, hist, currdepth, nextdepth, noconfig, filter, reverse, jumps) # tag-package operations # add @@ -834,7 +834,7 @@ def _pkglist_add(tag_id, pkg_id, owner, block, extra_arches): insert.make_create() #XXX user_id? insert.execute() -def pkglist_add(taginfo,pkginfo,owner=None,block=None,extra_arches=None,force=False,update=False): +def pkglist_add(taginfo, pkginfo, owner=None, block=None, extra_arches=None, force=False, update=False): """Add to (or update) package list for tag""" #access control comes a little later (via an assert_policy) #should not make any changes until after policy is checked @@ -845,7 +845,7 @@ def pkglist_add(taginfo,pkginfo,owner=None,block=None,extra_arches=None,force=Fa if not isinstance(pkginfo, basestring): raise koji.GenericError, "Invalid package: %s" % pkginfo if owner is not None: - owner = get_user(owner,strict=True)['id'] + owner = get_user(owner, strict=True)['id'] action = 'add' if update: action = 'update' @@ -864,7 +864,7 @@ def pkglist_add(taginfo,pkginfo,owner=None,block=None,extra_arches=None,force=Fa # already present (via inheritance) # blocked pkglist = readPackageList(tag_id, pkgID=pkg['id'], inherit=True) - previous = pkglist.get(pkg['id'],None) + previous = pkglist.get(pkg['id'], None) if previous is None: if block is None: block = False @@ -873,7 +873,7 @@ def pkglist_add(taginfo,pkginfo,owner=None,block=None,extra_arches=None,force=Fa if update and not force: #if update flag is true, require that there be a previous entry raise koji.GenericError, "cannot update: tag %s has no data for package %s" \ - % (tag['name'],pkg['name']) + % (tag['name'], pkg['name']) else: #already there (possibly via inheritance) if owner is None: @@ -886,9 +886,9 @@ def pkglist_add(taginfo,pkginfo,owner=None,block=None,extra_arches=None,force=Fa extra_arches = previous['extra_arches'] #see if the data is the same changed = False - for key,value in (('owner_id',owner), - ('blocked',block), - ('extra_arches',extra_arches)): + for key, value in (('owner_id', owner), + ('blocked', block), + ('extra_arches', extra_arches)): if previous[key] != value: changed = True break @@ -896,7 +896,7 @@ def pkglist_add(taginfo,pkginfo,owner=None,block=None,extra_arches=None,force=Fa #no point in adding it again with the same data return if previous['blocked'] and not block and not force: - raise koji.GenericError, "package %s is blocked in tag %s" % (pkg['name'],tag['name']) + raise koji.GenericError, "package %s is blocked in tag %s" % (pkg['name'], tag['name']) if owner is None: if force: owner = context.session.user_id @@ -906,7 +906,7 @@ def pkglist_add(taginfo,pkginfo,owner=None,block=None,extra_arches=None,force=Fa koji.plugin.run_callbacks('postPackageListChange', action=action, tag=tag, package=pkg, owner=owner, block=block, extra_arches=extra_arches, force=force, update=update) -def pkglist_remove(taginfo,pkginfo,force=False): +def pkglist_remove(taginfo, pkginfo, force=False): """Remove package from the list for tag Most of the time you really want to use the block or unblock functions @@ -922,12 +922,12 @@ def pkglist_remove(taginfo,pkginfo,force=False): if not (force and context.session.hasPerm('admin')): assert_policy('package_list', policy_data) koji.plugin.run_callbacks('prePackageListChange', action='remove', tag=tag, package=pkg) - _pkglist_remove(tag['id'],pkg['id']) + _pkglist_remove(tag['id'], pkg['id']) koji.plugin.run_callbacks('postPackageListChange', action='remove', tag=tag, package=pkg) -def pkglist_block(taginfo,pkginfo): +def pkglist_block(taginfo, pkginfo): """Block the package in tag""" - pkglist_add(taginfo,pkginfo,block=True) + pkglist_add(taginfo, pkginfo, block=True) def pkglist_unblock(taginfo, pkginfo, force=False): """Unblock the package in tag @@ -946,14 +946,14 @@ def pkglist_unblock(taginfo, pkginfo, force=False): tag_id = tag['id'] pkg_id = pkg['id'] pkglist = readPackageList(tag_id, pkgID=pkg_id, inherit=True) - previous = pkglist.get(pkg_id,None) + previous = pkglist.get(pkg_id, None) if previous is None: raise koji.GenericError, "no data (blocked or otherwise) for package %s in tag %s" \ - % (pkg['name'],tag['name']) + % (pkg['name'], tag['name']) if not previous['blocked']: - raise koji.GenericError, "package %s NOT blocked in tag %s" % (pkg['name'],tag['name']) + raise koji.GenericError, "package %s NOT blocked in tag %s" % (pkg['name'], tag['name']) if previous['tag_id'] != tag_id: - _pkglist_add(tag_id,pkg_id,previous['owner_id'],False,previous['extra_arches']) + _pkglist_add(tag_id, pkg_id, previous['owner_id'], False, previous['extra_arches']) else: #just remove the blocking entry _pkglist_remove(tag_id, pkg_id) @@ -964,13 +964,13 @@ def pkglist_unblock(taginfo, pkginfo, force=False): _pkglist_add(tag_id, pkg_id, previous['owner_id'], False, previous['extra_arches']) koji.plugin.run_callbacks('postPackageListChange', action='unblock', tag=tag, package=pkg) -def pkglist_setowner(taginfo,pkginfo,owner,force=False): +def pkglist_setowner(taginfo, pkginfo, owner, force=False): """Set the owner for package in tag""" - pkglist_add(taginfo,pkginfo,owner=owner,force=force,update=True) + pkglist_add(taginfo, pkginfo, owner=owner, force=force, update=True) -def pkglist_setarches(taginfo,pkginfo,arches,force=False): +def pkglist_setarches(taginfo, pkginfo, arches, force=False): """Set extra_arches for package in tag""" - pkglist_add(taginfo,pkginfo,extra_arches=arches,force=force,update=True) + pkglist_add(taginfo, pkginfo, extra_arches=arches, force=force, update=True) def readPackageList(tagID=None, userID=None, pkgID=None, event=None, inherit=False, with_dups=False): """Returns the package list for the specified tag or user. @@ -986,7 +986,7 @@ def readPackageList(tagID=None, userID=None, pkgID=None, event=None, inherit=Fal fields = (('package.id', 'package_id'), ('package.name', 'package_name'), ('tag.id', 'tag_id'), ('tag.name', 'tag_name'), ('users.id', 'owner_id'), ('users.name', 'owner_name'), - ('extra_arches','extra_arches'), + ('extra_arches', 'extra_arches'), ('tag_packages.blocked', 'blocked')) flist = ', '.join([pair[0] for pair in fields]) cond = eventCondition(event) @@ -1016,7 +1016,7 @@ def readPackageList(tagID=None, userID=None, pkgID=None, event=None, inherit=Fal # things are simpler for the first tag pkgid = p['package_id'] if with_dups: - packages.setdefault(pkgid,[]).append(p) + packages.setdefault(pkgid, []).append(p) else: packages[pkgid] = p @@ -1032,7 +1032,7 @@ def readPackageList(tagID=None, userID=None, pkgID=None, event=None, inherit=Fal # precompile filter patterns re_list = [] for pat in filter: - prog = re_cache.get(pat,None) + prog = re_cache.get(pat, None) if prog is None: prog = re.compile(pat) re_cache[pat] = prog @@ -1054,7 +1054,7 @@ def readPackageList(tagID=None, userID=None, pkgID=None, event=None, inherit=Fal if skip: continue if with_dups: - packages.setdefault(pkgid,[]).append(p) + packages.setdefault(pkgid, []).append(p) else: packages[pkgid] = p return packages @@ -1119,7 +1119,7 @@ def list_tags(build=None, package=None, queryOpts=None): opts=queryOpts) return query.iterate() -def readTaggedBuilds(tag,event=None,inherit=False,latest=False,package=None,owner=None,type=None): +def readTaggedBuilds(tag, event=None, inherit=False, latest=False, package=None, owner=None, type=None): """Returns a list of builds for specified tag set inherit=True to follow inheritance @@ -1149,7 +1149,7 @@ def readTaggedBuilds(tag,event=None,inherit=False,latest=False,package=None,owne ('build.id', 'build_id'), ('build.version', 'version'), ('build.release', 'release'), ('build.epoch', 'epoch'), ('build.state', 'state'), ('build.completion_time', 'completion_time'), ('build.start_time', 'start_time'), - ('build.task_id','task_id'), + ('build.task_id', 'task_id'), ('events.id', 'creation_event_id'), ('events.time', 'creation_time'), ('volume.id', 'volume_id'), ('volume.name', 'volume_name'), ('package.id', 'package_id'), ('package.name', 'package_name'), @@ -1175,7 +1175,7 @@ def readTaggedBuilds(tag,event=None,inherit=False,latest=False,package=None,owne else: raise koji.GenericError, 'unsupported build type: %s' % type - q="""SELECT %s + q = """SELECT %s FROM tag_listing JOIN tag ON tag.id = tag_listing.tag_id JOIN build ON build.id = tag_listing.build_id @@ -1203,7 +1203,7 @@ def readTaggedBuilds(tag,event=None,inherit=False,latest=False,package=None,owne #log_error(koji.db._quoteparams(q,locals())) for build in _multiRow(q, locals(), [pair[1] for pair in fields]): pkgid = build['package_id'] - pinfo = packages.get(pkgid,None) + pinfo = packages.get(pkgid, None) if pinfo is None or pinfo['blocked']: # note: # tools should endeavor to keep tag_listing sane w.r.t. @@ -1220,7 +1220,7 @@ def readTaggedBuilds(tag,event=None,inherit=False,latest=False,package=None,owne return builds -def readTaggedRPMS(tag, package=None, arch=None, event=None,inherit=False,latest=True,rpmsigs=False,owner=None,type=None): +def readTaggedRPMS(tag, package=None, arch=None, event=None, inherit=False, latest=True, rpmsigs=False, owner=None, type=None): """Returns a list of rpms for specified tag set inherit=True to follow inheritance @@ -1239,7 +1239,7 @@ def readTaggedRPMS(tag, package=None, arch=None, event=None,inherit=False,latest builds = readTaggedBuilds(tag, event=event, inherit=inherit, latest=latest, package=package, owner=owner, type=type) #index builds - build_idx = dict([(b['build_id'],b) for b in builds]) + build_idx = dict([(b['build_id'], b) for b in builds]) #the following query is run for each tag in the inheritance fields = [('rpminfo.name', 'name'), @@ -1303,7 +1303,7 @@ def readTaggedRPMS(tag, package=None, arch=None, event=None,inherit=False,latest # tools should endeavor to keep tag_listing sane w.r.t. # the package list, but if there is disagreement the package # list should take priority - build = build_idx.get(rpminfo['build_id'],None) + build = build_idx.get(rpminfo['build_id'], None) if build is None: continue elif build['tag_id'] != tagid: @@ -1332,7 +1332,7 @@ def readTaggedArchives(tag, package=None, event=None, inherit=False, latest=True # If type == 'maven', we require that both the build *and* the archive have Maven metadata builds = readTaggedBuilds(tag, event=event, inherit=inherit, latest=latest, package=package, type=type) #index builds - build_idx = dict([(b['build_id'],b) for b in builds]) + build_idx = dict([(b['build_id'], b) for b in builds]) #the following query is run for each tag in the inheritance fields = [('archiveinfo.id', 'id'), @@ -1395,7 +1395,7 @@ def readTaggedArchives(tag, package=None, event=None, inherit=False, latest=True # tools should endeavor to keep tag_listing sane w.r.t. # the package list, but if there is disagreement the package # list should take priority - build = build_idx.get(archiveinfo['build_id'],None) + build = build_idx.get(archiveinfo['build_id'], None) if build is None: continue elif build['tag_id'] != tagid: @@ -1404,7 +1404,7 @@ def readTaggedArchives(tag, package=None, event=None, inherit=False, latest=True archives.append(archiveinfo) return [archives, builds] -def check_tag_access(tag_id,user_id=None): +def check_tag_access(tag_id, user_id=None): """Determine if user has access to tag package with tag. Returns a tuple (access, override, reason) @@ -1424,17 +1424,17 @@ def check_tag_access(tag_id,user_id=None): if tag['locked']: return (False, override, "tag is locked") if tag['perm_id']: - needed_perm = lookup_perm(tag['perm_id'],strict=True)['name'] + needed_perm = lookup_perm(tag['perm_id'], strict=True)['name'] if needed_perm not in perms: return (False, override, "tag requires %s permission" % needed_perm) - return (True,override,"") + return (True, override, "") -def assert_tag_access(tag_id,user_id=None,force=False): - access, override, reason = check_tag_access(tag_id,user_id) +def assert_tag_access(tag_id, user_id=None, force=False): + access, override, reason = check_tag_access(tag_id, user_id) if not access and not (override and force): raise koji.ActionNotAllowed, reason -def _tag_build(tag,build,user_id=None,force=False): +def _tag_build(tag, build, user_id=None, force=False): """Tag a build This function makes access checks based on user_id, which defaults to the @@ -1460,9 +1460,9 @@ def _tag_build(tag,build,user_id=None,force=False): if build['state'] != koji.BUILD_STATES['COMPLETE']: # incomplete builds may not be tagged, not even when forced state = koji.BUILD_STATES[build['state']] - raise koji.TagError, "build %s not complete: state %s" % (nvr,state) + raise koji.TagError, "build %s not complete: state %s" % (nvr, state) #access check - assert_tag_access(tag['id'],user_id=user_id,force=force) + assert_tag_access(tag['id'], user_id=user_id, force=force) # see if it's already tagged retag = False table = 'tag_listing' @@ -1474,7 +1474,7 @@ def _tag_build(tag,build,user_id=None,force=False): if query.executeOne(): #already tagged if not force: - raise koji.TagError, "build %s already tagged (%s)" % (nvr,tag['name']) + raise koji.TagError, "build %s already tagged (%s)" % (nvr, tag['name']) #otherwise we retag retag = True if retag: @@ -1489,7 +1489,7 @@ def _tag_build(tag,build,user_id=None,force=False): insert.execute() koji.plugin.run_callbacks('postTag', tag=tag, build=build, user=user, force=force) -def _untag_build(tag,build,user_id=None,strict=True,force=False): +def _untag_build(tag, build, user_id=None, strict=True, force=False): """Untag a build If strict is true, assert that build is actually tagged @@ -1508,14 +1508,14 @@ def _untag_build(tag,build,user_id=None,strict=True,force=False): koji.plugin.run_callbacks('preUntag', tag=tag, build=build, user=user, force=force, strict=strict) tag_id = tag['id'] build_id = build['id'] - assert_tag_access(tag_id,user_id=user_id,force=force) + assert_tag_access(tag_id, user_id=user_id, force=force) update = UpdateProcessor('tag_listing', values=locals(), clauses=['tag_id=%(tag_id)i', 'build_id=%(build_id)i']) update.make_revoke(user_id=user_id) count = update.execute() if count == 0 and strict: nvr = "%(name)s-%(version)s-%(release)s" % build - raise koji.TagError, "build %s not in tag %s" % (nvr,tag['name']) + raise koji.TagError, "build %s not in tag %s" % (nvr, tag['name']) koji.plugin.run_callbacks('postUntag', tag=tag, build=build, user=user, force=force, strict=strict) # tag-group operations @@ -1525,24 +1525,24 @@ def _untag_build(tag,build,user_id=None,strict=True,force=False): # unblock # list (readTagGroups) -def grplist_add(taginfo,grpinfo,block=False,force=False,**opts): +def grplist_add(taginfo, grpinfo, block=False, force=False, **opts): """Add to (or update) group list for tag""" #only admins.... context.session.assertPerm('admin') tag = get_tag(taginfo) - group = lookup_group(grpinfo,create=True) + group = lookup_group(grpinfo, create=True) block = bool(block) # check current group status (incl inheritance) - groups = get_tag_groups(tag['id'], inherit=True, incl_pkgs=False,incl_reqs=False) - previous = groups.get(group['id'],None) - cfg_fields = ('exported','display_name','is_default','uservisible', - 'description','langonly','biarchonly',) + groups = get_tag_groups(tag['id'], inherit=True, incl_pkgs=False, incl_reqs=False) + previous = groups.get(group['id'], None) + cfg_fields = ('exported', 'display_name', 'is_default', 'uservisible', + 'description', 'langonly', 'biarchonly',) #prevent user-provided opts from doing anything strange opts = dslice(opts, cfg_fields, strict=False) if previous is not None: #already there (possibly via inheritance) if previous['blocked'] and not force: - raise koji.GenericError, "group %s is blocked in tag %s" % (group['name'],tag['name']) + raise koji.GenericError, "group %s is blocked in tag %s" % (group['name'], tag['name']) #check for duplication and grab old data for defaults changed = False for field in cfg_fields: @@ -1556,10 +1556,10 @@ def grplist_add(taginfo,grpinfo,block=False,force=False,**opts): #no point in adding it again with the same data return #provide available defaults and sanity check data - opts.setdefault('display_name',group['name']) - opts.setdefault('biarchonly',False) - opts.setdefault('exported',True) - opts.setdefault('uservisible',True) + opts.setdefault('display_name', group['name']) + opts.setdefault('biarchonly', False) + opts.setdefault('exported', True) + opts.setdefault('uservisible', True) # XXX ^^^ opts['tag_id'] = tag['id'] opts['group_id'] = group['id'] @@ -1574,7 +1574,7 @@ def grplist_add(taginfo,grpinfo,block=False,force=False,**opts): insert.make_create() insert.execute() -def grplist_remove(taginfo,grpinfo,force=False): +def grplist_remove(taginfo, grpinfo, force=False): """Remove group from the list for tag Really this shouldn't be used except in special cases @@ -1591,11 +1591,11 @@ def grplist_remove(taginfo,grpinfo,force=False): update.make_revoke() update.execute() -def grplist_block(taginfo,grpinfo): +def grplist_block(taginfo, grpinfo): """Block the group in tag""" - grplist_add(taginfo,grpinfo,block=True) + grplist_add(taginfo, grpinfo, block=True) -def grplist_unblock(taginfo,grpinfo): +def grplist_unblock(taginfo, grpinfo): """Unblock the group in tag If the group is blocked in this tag, then simply remove the block. @@ -1603,8 +1603,8 @@ def grplist_unblock(taginfo,grpinfo): """ # only admins... context.session.assertPerm('admin') - tag = lookup_tag(taginfo,strict=True) - group = lookup_group(grpinfo,strict=True) + tag = lookup_tag(taginfo, strict=True) + group = lookup_group(grpinfo, strict=True) tag_id = tag['id'] grp_id = group['id'] table = 'group_config' @@ -1614,7 +1614,7 @@ def grplist_unblock(taginfo,grpinfo): values=locals(), opts={'rowlock':True}) blocked = query.singleValue(strict=False) if not blocked: - raise koji.GenericError, "group %s is NOT blocked in tag %s" % (group['name'],tag['name']) + raise koji.GenericError, "group %s is NOT blocked in tag %s" % (group['name'], tag['name']) update = UpdateProcessor(table, values=locals(), clauses=clauses) update.make_revoke() update.execute() @@ -1627,29 +1627,29 @@ def grplist_unblock(taginfo,grpinfo): # unblock # list (readTagGroups) -def grp_pkg_add(taginfo,grpinfo,pkg_name,block=False,force=False,**opts): +def grp_pkg_add(taginfo, grpinfo, pkg_name, block=False, force=False, **opts): """Add package to group for tag""" #only admins.... context.session.assertPerm('admin') tag = lookup_tag(taginfo, strict=True) - group = lookup_group(grpinfo,strict=True) + group = lookup_group(grpinfo, strict=True) block = bool(block) # check current group status (incl inheritance) groups = get_tag_groups(tag['id'], inherit=True, incl_pkgs=True, incl_reqs=False) - grp_cfg = groups.get(group['id'],None) + grp_cfg = groups.get(group['id'], None) if grp_cfg is None: - raise koji.GenericError, "group %s not present in tag %s" % (group['name'],tag['name']) + raise koji.GenericError, "group %s not present in tag %s" % (group['name'], tag['name']) elif grp_cfg['blocked']: - raise koji.GenericError, "group %s is blocked in tag %s" % (group['name'],tag['name']) - previous = grp_cfg['packagelist'].get(pkg_name,None) - cfg_fields = ('type','basearchonly','requires') + raise koji.GenericError, "group %s is blocked in tag %s" % (group['name'], tag['name']) + previous = grp_cfg['packagelist'].get(pkg_name, None) + cfg_fields = ('type', 'basearchonly', 'requires') #prevent user-provided opts from doing anything strange opts = dslice(opts, cfg_fields, strict=False) if previous is not None: #already there (possibly via inheritance) if previous['blocked'] and not force: raise koji.GenericError, "package %s blocked in group %s, tag %s" \ - % (pkg_name,group['name'],tag['name']) + % (pkg_name, group['name'], tag['name']) #check for duplication and grab old data for defaults changed = False for field in cfg_fields: @@ -1666,7 +1666,7 @@ def grp_pkg_add(taginfo,grpinfo,pkg_name,block=False,force=False,**opts): if not changed and not force: #no point in adding it again with the same data (unless force is on) return - opts.setdefault('type','mandatory') + opts.setdefault('type', 'mandatory') opts['group_id'] = group['id'] opts['tag_id'] = tag['id'] opts['package'] = pkg_name @@ -1681,7 +1681,7 @@ def grp_pkg_add(taginfo,grpinfo,pkg_name,block=False,force=False,**opts): insert.make_create() insert.execute() -def grp_pkg_remove(taginfo,grpinfo,pkg_name,force=False): +def grp_pkg_remove(taginfo, grpinfo, pkg_name, force=False): """Remove package from the list for group-tag Really this shouldn't be used except in special cases @@ -1689,18 +1689,18 @@ def grp_pkg_remove(taginfo,grpinfo,pkg_name,force=False): """ #only admins.... context.session.assertPerm('admin') - tag_id = get_tag_id(taginfo,strict=True) - grp_id = get_group_id(grpinfo,strict=True) + tag_id = get_tag_id(taginfo, strict=True) + grp_id = get_group_id(grpinfo, strict=True) update = UpdateProcessor('group_package_listing', values=locals(), clauses=['package=%(pkg_name)s', 'tag_id=%(tag_id)s', 'group_id = %(grp_id)s']) update.make_revoke() update.execute() -def grp_pkg_block(taginfo,grpinfo, pkg_name): +def grp_pkg_block(taginfo, grpinfo, pkg_name): """Block the package in group-tag""" - grp_pkg_add(taginfo,grpinfo,pkg_name,block=True) + grp_pkg_add(taginfo, grpinfo, pkg_name, block=True) -def grp_pkg_unblock(taginfo,grpinfo,pkg_name): +def grp_pkg_unblock(taginfo, grpinfo, pkg_name): """Unblock the package in group-tag If blocked (directly) in this tag, then simply remove the block. @@ -1709,8 +1709,8 @@ def grp_pkg_unblock(taginfo,grpinfo,pkg_name): # only admins... context.session.assertPerm('admin') table = 'group_package_listing' - tag_id = get_tag_id(taginfo,strict=True) - grp_id = get_group_id(grpinfo,strict=True) + tag_id = get_tag_id(taginfo, strict=True) + grp_id = get_group_id(grpinfo, strict=True) clauses = ('group_id=%(grp_id)s', 'tag_id=%(tag_id)s', 'package = %(pkg_name)s') query = QueryProcessor(columns=['blocked'], tables=[table], clauses=('active = TRUE',)+clauses, @@ -1718,7 +1718,7 @@ def grp_pkg_unblock(taginfo,grpinfo,pkg_name): blocked = query.singleValue(strict=False) if not blocked: raise koji.GenericError, "package %s is NOT blocked in group %s, tag %s" \ - % (pkg_name,grp_id,tag_id) + % (pkg_name, grp_id, tag_id) update = UpdateProcessor('group_package_listing', values=locals(), clauses=clauses) update.make_revoke() update.execute() @@ -1730,7 +1730,7 @@ def grp_pkg_unblock(taginfo,grpinfo,pkg_name): # unblock # list (readTagGroups) -def grp_req_add(taginfo,grpinfo,reqinfo,block=False,force=False,**opts): +def grp_req_add(taginfo, grpinfo, reqinfo, block=False, force=False, **opts): """Add group requirement to group for tag""" #only admins.... context.session.assertPerm('admin') @@ -1740,20 +1740,20 @@ def grp_req_add(taginfo,grpinfo,reqinfo,block=False,force=False,**opts): block = bool(block) # check current group status (incl inheritance) groups = get_tag_groups(tag['id'], inherit=True, incl_pkgs=False, incl_reqs=True) - grp_cfg = groups.get(group['id'],None) + grp_cfg = groups.get(group['id'], None) if grp_cfg is None: - raise koji.GenericError, "group %s not present in tag %s" % (group['name'],tag['name']) + raise koji.GenericError, "group %s not present in tag %s" % (group['name'], tag['name']) elif grp_cfg['blocked']: - raise koji.GenericError, "group %s is blocked in tag %s" % (group['name'],tag['name']) - previous = grp_cfg['grouplist'].get(req['id'],None) - cfg_fields = ('type','is_metapkg') + raise koji.GenericError, "group %s is blocked in tag %s" % (group['name'], tag['name']) + previous = grp_cfg['grouplist'].get(req['id'], None) + cfg_fields = ('type', 'is_metapkg') #prevent user-provided opts from doing anything strange opts = dslice(opts, cfg_fields, strict=False) if previous is not None: #already there (possibly via inheritance) if previous['blocked'] and not force: raise koji.GenericError, "requirement on group %s blocked in group %s, tag %s" \ - % (req['name'],group['name'],tag['name']) + % (req['name'], group['name'], tag['name']) #check for duplication and grab old data for defaults changed = False for field in cfg_fields: @@ -1770,7 +1770,7 @@ def grp_req_add(taginfo,grpinfo,reqinfo,block=False,force=False,**opts): if not changed: #no point in adding it again with the same data return - opts.setdefault('type','mandatory') + opts.setdefault('type', 'mandatory') opts['group_id'] = group['id'] opts['tag_id'] = tag['id'] opts['req_id'] = req['id'] @@ -1785,7 +1785,7 @@ def grp_req_add(taginfo,grpinfo,reqinfo,block=False,force=False,**opts): insert.make_create() insert.execute() -def grp_req_remove(taginfo,grpinfo,reqinfo,force=False): +def grp_req_remove(taginfo, grpinfo, reqinfo, force=False): """Remove group requirement from the list for group-tag Really this shouldn't be used except in special cases @@ -1793,19 +1793,19 @@ def grp_req_remove(taginfo,grpinfo,reqinfo,force=False): """ #only admins.... context.session.assertPerm('admin') - tag_id = get_tag_id(taginfo,strict=True) - grp_id = get_group_id(grpinfo,strict=True) - req_id = get_group_id(reqinfo,strict=True) + tag_id = get_tag_id(taginfo, strict=True) + grp_id = get_group_id(grpinfo, strict=True) + req_id = get_group_id(reqinfo, strict=True) update = UpdateProcessor('group_req_listing', values=locals(), clauses=['req_id=%(req_id)s', 'tag_id=%(tag_id)s', 'group_id = %(grp_id)s']) update.make_revoke() update.execute() -def grp_req_block(taginfo,grpinfo,reqinfo): +def grp_req_block(taginfo, grpinfo, reqinfo): """Block the group requirement in group-tag""" - grp_req_add(taginfo,grpinfo,reqinfo,block=True) + grp_req_add(taginfo, grpinfo, reqinfo, block=True) -def grp_req_unblock(taginfo,grpinfo,reqinfo): +def grp_req_unblock(taginfo, grpinfo, reqinfo): """Unblock the group requirement in group-tag If blocked (directly) in this tag, then simply remove the block. @@ -1813,9 +1813,9 @@ def grp_req_unblock(taginfo,grpinfo,reqinfo): """ # only admins... context.session.assertPerm('admin') - tag_id = get_tag_id(taginfo,strict=True) - grp_id = get_group_id(grpinfo,strict=True) - req_id = get_group_id(reqinfo,strict=True) + tag_id = get_tag_id(taginfo, strict=True) + grp_id = get_group_id(grpinfo, strict=True) + req_id = get_group_id(reqinfo, strict=True) table = 'group_req_listing' clauses = ('group_id=%(grp_id)s', 'tag_id=%(tag_id)s', 'req_id = %(req_id)s') @@ -1825,12 +1825,12 @@ def grp_req_unblock(taginfo,grpinfo,reqinfo): blocked = query.singleValue(strict=False) if not blocked: raise koji.GenericError, "group req %s is NOT blocked in group %s, tag %s" \ - % (req_id,grp_id,tag_id) + % (req_id, grp_id, tag_id) update = UpdateProcessor('group_req_listing', values=locals(), clauses=clauses) update.make_revoke() update.execute() -def get_tag_groups(tag,event=None,inherit=True,incl_pkgs=True,incl_reqs=True): +def get_tag_groups(tag, event=None, inherit=True, incl_pkgs=True, incl_reqs=True): """Return group data for the tag If inherit is true, follow inheritance @@ -1842,37 +1842,37 @@ def get_tag_groups(tag,event=None,inherit=True,incl_pkgs=True,incl_reqs=True): filtered out. """ order = None - tag = get_tag_id(tag,strict=True) + tag = get_tag_id(tag, strict=True) taglist = [tag] if inherit: - order = readFullInheritance(tag,event) + order = readFullInheritance(tag, event) taglist += [link['parent_id'] for link in order] evcondition = eventCondition(event) # First get the list of groups - fields = ('name','group_id','tag_id','blocked','exported','display_name', - 'is_default','uservisible','description','langonly','biarchonly',) - q=""" + fields = ('name', 'group_id', 'tag_id', 'blocked', 'exported', 'display_name', + 'is_default', 'uservisible', 'description', 'langonly', 'biarchonly',) + q = """ SELECT %s FROM group_config JOIN groups ON group_id = id WHERE %s AND tag_id = %%(tagid)s - """ % (",".join(fields),evcondition) + """ % (",".join(fields), evcondition) groups = {} for tagid in taglist: - for group in _multiRow(q,locals(),fields): + for group in _multiRow(q, locals(), fields): grp_id = group['group_id'] # we only take the first entry for group as we go through inheritance - groups.setdefault(grp_id,group) + groups.setdefault(grp_id, group) if incl_pkgs: for group in groups.itervalues(): group['packagelist'] = {} - fields = ('group_id','tag_id','package','blocked','type','basearchonly','requires') + fields = ('group_id', 'tag_id', 'package', 'blocked', 'type', 'basearchonly', 'requires') q = """ SELECT %s FROM group_package_listing WHERE %s AND tag_id = %%(tagid)s - """ % (",".join(fields),evcondition) + """ % (",".join(fields), evcondition) for tagid in taglist: - for grp_pkg in _multiRow(q,locals(),fields): + for grp_pkg in _multiRow(q, locals(), fields): grp_id = grp_pkg['group_id'] if not groups.has_key(grp_id): #tag does not have this group @@ -1882,18 +1882,18 @@ def get_tag_groups(tag,event=None,inherit=True,incl_pkgs=True,incl_reqs=True): #ignore blocked groups continue pkg_name = grp_pkg['package'] - group['packagelist'].setdefault(pkg_name,grp_pkg) + group['packagelist'].setdefault(pkg_name, grp_pkg) if incl_reqs: # and now the group reqs for group in groups.itervalues(): group['grouplist'] = {} - fields = ('group_id','tag_id','req_id','blocked','type','is_metapkg','name') + fields = ('group_id', 'tag_id', 'req_id', 'blocked', 'type', 'is_metapkg', 'name') q = """SELECT %s FROM group_req_listing JOIN groups on req_id = id WHERE %s AND tag_id = %%(tagid)s - """ % (",".join(fields),evcondition) + """ % (",".join(fields), evcondition) for tagid in taglist: - for grp_req in _multiRow(q,locals(),fields): + for grp_req in _multiRow(q, locals(), fields): grp_id = grp_req['group_id'] if not groups.has_key(grp_id): #tag does not have this group @@ -1909,16 +1909,16 @@ def get_tag_groups(tag,event=None,inherit=True,incl_pkgs=True,incl_reqs=True): elif groups[req_id]['blocked']: #ignore blocked groups continue - group['grouplist'].setdefault(req_id,grp_req) + group['grouplist'].setdefault(req_id, grp_req) return groups -def readTagGroups(tag,event=None,inherit=True,incl_pkgs=True,incl_reqs=True): +def readTagGroups(tag, event=None, inherit=True, incl_pkgs=True, incl_reqs=True): """Return group data for the tag with blocked entries removed Also scrubs data into an xmlrpc-safe format (no integer keys) """ - groups = get_tag_groups(tag,event,inherit,incl_pkgs,incl_reqs) + groups = get_tag_groups(tag, event, inherit, incl_pkgs, incl_reqs) for group in groups.values(): #filter blocked entries and collapse to a list if 'packagelist' in group: @@ -1928,7 +1928,7 @@ def readTagGroups(tag,event=None,inherit=True,incl_pkgs=True,incl_reqs=True): group['grouplist'] = filter(lambda x: not x['blocked'], group['grouplist'].values()) #filter blocked entries and collapse to a list - return filter(lambda x: not x['blocked'],groups.values()) + return filter(lambda x: not x['blocked'], groups.values()) def set_host_enabled(hostname, enabled=True): context.session.assertPerm('admin') @@ -2025,8 +2025,8 @@ def get_ready_hosts(): is busy with tasks, it should be checking in quite often). """ c = context.cnx.cursor() - fields = ('host.id','name','arches','task_load', 'capacity') - aliases = ('id','name','arches','task_load', 'capacity') + fields = ('host.id', 'name', 'arches', 'task_load', 'capacity') + aliases = ('id', 'name', 'arches', 'task_load', 'capacity') q = """ SELECT %s FROM host JOIN sessions USING (user_id) @@ -2037,10 +2037,10 @@ def get_ready_hosts(): """ % ','.join(fields) # XXX - magic number in query c.execute(q) - hosts = [dict(zip(aliases,row)) for row in c.fetchall()] + hosts = [dict(zip(aliases, row)) for row in c.fetchall()] for host in hosts: q = """SELECT channel_id FROM host_channels WHERE host_id=%(id)s""" - c.execute(q,host) + c.execute(q, host) host['channels'] = [row[0] for row in c.fetchall()] return hosts @@ -2059,7 +2059,7 @@ def get_all_arches(): def get_active_tasks(host=None): """Return data on tasks that are yet to be run""" fields = ['id', 'state', 'channel_id', 'host_id', 'arch', 'method', 'priority', 'create_time'] - values = dslice(koji.TASK_STATES, ('FREE','ASSIGNED')) + values = dslice(koji.TASK_STATES, ('FREE', 'ASSIGNED')) if host: values['arches'] = host['arches'].split() + ['noarch'] values['channels'] = host['channels'] @@ -2197,7 +2197,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None): if tinfo['arches']: for arch in tinfo['arches'].split(): arch = koji.canonArch(arch) - if arch in ['src','noarch']: + if arch in ['src', 'noarch']: continue repo_arches[arch] = 1 repo_id = _singleValue("SELECT nextval('repo_id_seq')") @@ -2224,7 +2224,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None): groupsdir = "%s/groups" % (repodir) koji.ensuredir(groupsdir) comps = koji.generate_comps(groups, expand_groups=True) - fo = file("%s/comps.xml" % groupsdir,'w') + fo = file("%s/comps.xml" % groupsdir, 'w') fo.write(comps) fo.close() @@ -2345,20 +2345,20 @@ def repo_set_state(repo_id, state, check=True): if check: # The repo states are sequential, going backwards makes no sense q = """SELECT state FROM repo WHERE id = %(repo_id)s FOR UPDATE""" - oldstate = _singleValue(q,locals()) + oldstate = _singleValue(q, locals()) if oldstate > state: raise koji.GenericError, "Invalid repo state transition %s->%s" \ - % (oldstate,state) + % (oldstate, state) q = """UPDATE repo SET state=%(state)s WHERE id = %(repo_id)s""" - _dml(q,locals()) + _dml(q, locals()) def repo_info(repo_id, strict=False): fields = ( ('repo.id', 'id'), ('repo.state', 'state'), ('repo.create_event', 'create_event'), - ('events.time','creation_time'), #for compatibility with getRepo - ('EXTRACT(EPOCH FROM events.time)','create_ts'), + ('events.time', 'creation_time'), #for compatibility with getRepo + ('EXTRACT(EPOCH FROM events.time)', 'create_ts'), ('repo.tag_id', 'tag_id'), ('tag.name', 'tag_name'), ) @@ -2370,15 +2370,15 @@ def repo_info(repo_id, strict=False): def repo_ready(repo_id): """Set repo state to ready""" - repo_set_state(repo_id,koji.REPO_READY) + repo_set_state(repo_id, koji.REPO_READY) def repo_expire(repo_id): """Set repo state to expired""" - repo_set_state(repo_id,koji.REPO_EXPIRED) + repo_set_state(repo_id, koji.REPO_EXPIRED) def repo_problem(repo_id): """Set repo state to problem""" - repo_set_state(repo_id,koji.REPO_PROBLEM) + repo_set_state(repo_id, koji.REPO_PROBLEM) def repo_delete(repo_id): """Attempt to mark repo deleted, return number of references @@ -2386,10 +2386,10 @@ def repo_delete(repo_id): If the number of references is nonzero, no change is made""" #get a row lock on the repo q = """SELECT state FROM repo WHERE id = %(repo_id)s FOR UPDATE""" - _singleValue(q,locals()) + _singleValue(q, locals()) references = repo_references(repo_id) if not references: - repo_set_state(repo_id,koji.REPO_DELETED) + repo_set_state(repo_id, koji.REPO_DELETED) return len(references) def repo_expire_older(tag_id, event_id): @@ -2432,7 +2432,7 @@ def get_active_repos(): ('repo.id', 'id'), ('repo.state', 'state'), ('repo.create_event', 'create_event'), - ('EXTRACT(EPOCH FROM events.time)','create_ts'), + ('EXTRACT(EPOCH FROM events.time)', 'create_ts'), ('repo.tag_id', 'tag_id'), ('tag.name', 'tag_name'), ) @@ -2443,7 +2443,7 @@ def get_active_repos(): WHERE repo.state != %%(st_deleted)s""" % ','.join([f[0] for f in fields]) return _multiRow(q, locals(), [f[1] for f in fields]) -def tag_changed_since_event(event,taglist): +def tag_changed_since_event(event, taglist): """Report whether any changes since event affect any of the tags in list The function is used by the repo daemon to determine which of its repos @@ -2520,7 +2520,7 @@ def create_build_target(name, build_tag, dest_tag): #build targets are versioned, so if the target has previously been deleted, it #is possible the name is in the system - id = get_build_target_id(name,create=True) + id = get_build_target_id(name, create=True) insert = InsertProcessor('build_target_config') insert.set(build_target_id=id, build_tag=build_tag, dest_tag=dest_tag) @@ -2634,7 +2634,7 @@ def get_build_target(info, event=None, strict=False): else: return None -def lookup_name(table,info,strict=False,create=False): +def lookup_name(table, info, strict=False, create=False): """Find the id and name in the table associated with info. Info can be the name to look up, or if create is false it can @@ -2651,14 +2651,14 @@ def lookup_name(table,info,strict=False,create=False): Any other fields should have default values, otherwise the create option will fail. """ - fields = ('id','name') + fields = ('id', 'name') if isinstance(info, int) or isinstance(info, long): - q="""SELECT id,name FROM %s WHERE id=%%(info)d""" % table + q = """SELECT id,name FROM %s WHERE id=%%(info)d""" % table elif isinstance(info, str): - q="""SELECT id,name FROM %s WHERE name=%%(info)s""" % table + q = """SELECT id,name FROM %s WHERE name=%%(info)s""" % table else: raise koji.GenericError, 'invalid type for id lookup: %s' % type(info) - ret = _singleRow(q,locals(),fields,strict=False) + ret = _singleRow(q, locals(), fields, strict=False) if ret is None: if strict: raise koji.GenericError, 'No such entry in table %s: %s' % (table, info) @@ -2667,67 +2667,67 @@ def lookup_name(table,info,strict=False,create=False): raise koji.GenericError, 'Name must be a string' id = _singleValue("SELECT nextval('%s_id_seq')" % table, strict=True) q = """INSERT INTO %s(id,name) VALUES (%%(id)i,%%(info)s)""" % table - _dml(q,locals()) + _dml(q, locals()) return {'id': id, 'name': info} else: return ret return ret -def get_id(table,info,strict=False,create=False): +def get_id(table, info, strict=False, create=False): """Find the id in the table associated with info.""" - data = lookup_name(table,info,strict,create) + data = lookup_name(table, info, strict, create) if data is None: return data else: return data['id'] -def get_tag_id(info,strict=False,create=False): +def get_tag_id(info, strict=False, create=False): """Get the id for tag""" - return get_id('tag',info,strict,create) + return get_id('tag', info, strict, create) -def lookup_tag(info,strict=False,create=False): +def lookup_tag(info, strict=False, create=False): """Get the id,name for tag""" - return lookup_name('tag',info,strict,create) + return lookup_name('tag', info, strict, create) -def get_perm_id(info,strict=False,create=False): +def get_perm_id(info, strict=False, create=False): """Get the id for a permission""" - return get_id('permissions',info,strict,create) + return get_id('permissions', info, strict, create) -def lookup_perm(info,strict=False,create=False): +def lookup_perm(info, strict=False, create=False): """Get the id,name for perm""" - return lookup_name('permissions',info,strict,create) + return lookup_name('permissions', info, strict, create) -def get_package_id(info,strict=False,create=False): +def get_package_id(info, strict=False, create=False): """Get the id for a package""" - return get_id('package',info,strict,create) + return get_id('package', info, strict, create) -def lookup_package(info,strict=False,create=False): +def lookup_package(info, strict=False, create=False): """Get the id,name for package""" - return lookup_name('package',info,strict,create) + return lookup_name('package', info, strict, create) -def get_channel_id(info,strict=False,create=False): +def get_channel_id(info, strict=False, create=False): """Get the id for a channel""" - return get_id('channels',info,strict,create) + return get_id('channels', info, strict, create) -def lookup_channel(info,strict=False,create=False): +def lookup_channel(info, strict=False, create=False): """Get the id,name for channel""" - return lookup_name('channels',info,strict,create) + return lookup_name('channels', info, strict, create) -def get_group_id(info,strict=False,create=False): +def get_group_id(info, strict=False, create=False): """Get the id for a group""" - return get_id('groups',info,strict,create) + return get_id('groups', info, strict, create) -def lookup_group(info,strict=False,create=False): +def lookup_group(info, strict=False, create=False): """Get the id,name for group""" - return lookup_name('groups',info,strict,create) + return lookup_name('groups', info, strict, create) -def get_build_target_id(info,strict=False,create=False): +def get_build_target_id(info, strict=False, create=False): """Get the id for a build target""" - return get_id('build_target',info,strict,create) + return get_id('build_target', info, strict, create) -def lookup_build_target(info,strict=False,create=False): +def lookup_build_target(info, strict=False, create=False): """Get the id,name for build target""" - return lookup_name('build_target',info,strict,create) + return lookup_name('build_target', info, strict, create) def create_tag(name, parent=None, arches=None, perm=None, locked=False, maven_support=False, maven_include_all=False): """Create a new tag""" @@ -2750,7 +2750,7 @@ def create_tag(name, parent=None, arches=None, perm=None, locked=False, maven_su parent_id = None #there may already be an id for a deleted tag, this will reuse it - tag_id = get_tag_id(name,create=True) + tag_id = get_tag_id(name, create=True) insert = InsertProcessor('tag_config') insert.set(tag_id=tag_id, arches=arches, perm_id=perm, locked=locked) @@ -2855,7 +2855,7 @@ def edit_tag(tagInfo, **kwargs): context.session.assertPerm('admin') if not context.opts.get('EnableMaven') \ - and dslice(kwargs, ['maven_support','maven_include_all'], strict=False): + and dslice(kwargs, ['maven_support', 'maven_include_all'], strict=False): raise koji.GenericError, "Maven support not enabled" tag = get_tag(tagInfo, strict=True) @@ -2863,7 +2863,7 @@ def edit_tag(tagInfo, **kwargs): if kwargs['perm'] is None: kwargs['perm_id'] = None else: - kwargs['perm_id'] = get_perm_id(kwargs['perm'],strict=True) + kwargs['perm_id'] = get_perm_id(kwargs['perm'], strict=True) name = kwargs.get('name') if name and tag['name'] != name: @@ -2878,10 +2878,10 @@ def edit_tag(tagInfo, **kwargs): 'tagID': tag['id'] } q = """SELECT id FROM tag WHERE name=%(name)s""" - id = _singleValue(q,values,strict=False) + id = _singleValue(q, values, strict=False) if id is not None: #new name is taken - raise koji.GenericError, "Name %s already taken by tag %s" % (name,id) + raise koji.GenericError, "Name %s already taken by tag %s" % (name, id) update = """UPDATE tag SET name = %(name)s WHERE id = %(tagID)i""" @@ -2890,7 +2890,7 @@ def edit_tag(tagInfo, **kwargs): #check for changes data = tag.copy() changed = False - for key in ('perm_id','arches','locked','maven_support','maven_include_all'): + for key in ('perm_id', 'arches', 'locked', 'maven_support', 'maven_include_all'): if kwargs.has_key(key) and data[key] != kwargs[key]: changed = True data[key] = kwargs[key] @@ -2984,7 +2984,7 @@ def create_external_repo(name, url): url += '/' values = {'id': id, 'name': name, 'url': url} insert = InsertProcessor('external_repo_config') - insert.set(external_repo_id = id, url=url) + insert.set(external_repo_id=id, url=url) insert.make_create() insert.execute() return values @@ -3239,11 +3239,11 @@ def get_user(userInfo=None, strict=False): def find_build_id(X, strict=False): - if isinstance(X,int) or isinstance(X,long): + if isinstance(X, int) or isinstance(X, long): return X - elif isinstance(X,str): + elif isinstance(X, str): data = koji.parse_NVR(X) - elif isinstance(X,dict): + elif isinstance(X, dict): data = X else: raise koji.GenericError, "Invalid argument: %r" % X @@ -3252,15 +3252,15 @@ def find_build_id(X, strict=False): data.has_key('release')): raise koji.GenericError, 'did not provide name, version, and release' - c=context.cnx.cursor() - q="""SELECT build.id FROM build JOIN package ON build.pkg_id=package.id + c = context.cnx.cursor() + q = """SELECT build.id FROM build JOIN package ON build.pkg_id=package.id WHERE package.name=%(name)s AND build.version=%(version)s AND build.release=%(release)s """ # contraints should ensure this is unique #log_error(koji.db._quoteparams(q,data)) - c.execute(q,data) - r=c.fetchone() + c.execute(q, data) + r = c.fetchone() #log_error("%r" % r ) if not r: if strict: @@ -3315,9 +3315,9 @@ def get_build(buildInfo, strict=False): ('package.id', 'package_id'), ('package.name', 'package_name'), ('package.name', 'name'), ('volume.id', 'volume_id'), ('volume.name', 'volume_name'), ("package.name || '-' || build.version || '-' || build.release", 'nvr'), - ('EXTRACT(EPOCH FROM events.time)','creation_ts'), + ('EXTRACT(EPOCH FROM events.time)', 'creation_ts'), ('EXTRACT(EPOCH FROM build.start_time)', 'start_ts'), - ('EXTRACT(EPOCH FROM build.completion_time)','completion_ts'), + ('EXTRACT(EPOCH FROM build.completion_time)', 'completion_ts'), ('users.id', 'owner_id'), ('users.name', 'owner_name'), ('build.source', 'source'), ('build.extra', 'extra')) @@ -3433,11 +3433,11 @@ def get_rpm(rpminfo, strict=False, multi=False): ) # we can look up by id or NVRA data = None - if isinstance(rpminfo,(int,long)): + if isinstance(rpminfo, (int, long)): data = {'id': rpminfo} - elif isinstance(rpminfo,str): + elif isinstance(rpminfo, str): data = koji.parse_NVRA(rpminfo) - elif isinstance(rpminfo,dict): + elif isinstance(rpminfo, dict): data = rpminfo.copy() else: raise koji.GenericError, "Invalid argument: %r" % rpminfo @@ -4217,13 +4217,13 @@ def query_buildroots(hostID=None, tagID=None, state=None, rpmID=None, archiveID= ('repo.id', 'repo_id'), ('repo.state', 'repo_state'), ('tag.id', 'tag_id'), ('tag.name', 'tag_name'), ('create_events.id', 'create_event_id'), ('create_events.time', 'create_event_time'), - ('EXTRACT(EPOCH FROM create_events.time)','create_ts'), + ('EXTRACT(EPOCH FROM create_events.time)', 'create_ts'), ('retire_events.id', 'retire_event_id'), ('retire_events.time', 'retire_event_time'), - ('EXTRACT(EPOCH FROM retire_events.time)','retire_ts'), + ('EXTRACT(EPOCH FROM retire_events.time)', 'retire_ts'), ('repo_create.id', 'repo_create_event_id'), ('repo_create.time', 'repo_create_event_time')] tables = ['buildroot'] - joins=['LEFT OUTER JOIN standard_buildroot ON standard_buildroot.buildroot_id = buildroot.id', + joins = ['LEFT OUTER JOIN standard_buildroot ON standard_buildroot.buildroot_id = buildroot.id', 'LEFT OUTER JOIN content_generator ON buildroot.cg_id = content_generator.id', 'LEFT OUTER JOIN host ON host.id = standard_buildroot.host_id', 'LEFT OUTER JOIN repo ON repo.id = standard_buildroot.repo_id', @@ -4288,12 +4288,12 @@ def list_channels(hostID=None): WHERE host_channels.host_id = %(hostID)i""" return _multiRow(query, locals(), fields) -def new_package(name,strict=True): +def new_package(name, strict=True): c = context.cnx.cursor() # TODO - table lock? # check for existing q = """SELECT id FROM package WHERE name=%(name)s""" - c.execute(q,locals()) + c.execute(q, locals()) row = c.fetchone() if row: (pkg_id,) = row @@ -4305,7 +4305,7 @@ def new_package(name,strict=True): (pkg_id,) = c.fetchone() q = """INSERT INTO package (id,name) VALUES (%(pkg_id)s,%(name)s)""" context.commit_pending = True - c.execute(q,locals()) + c.execute(q, locals()) return pkg_id @@ -4431,8 +4431,8 @@ def new_build(data): name = data.get('name') if not name: raise koji.GenericError, "No name or package id provided for build" - data['pkg_id'] = new_package(name,strict=False) - for f in ('version','release','epoch'): + data['pkg_id'] = new_package(name, strict=False) + for f in ('version', 'release', 'epoch'): if not data.has_key(f): raise koji.GenericError, "No %s value for build" % f if 'extra' in data: @@ -4444,12 +4444,12 @@ def new_build(data): data['extra'] = None #provide a few default values - data.setdefault('state',koji.BUILD_STATES['COMPLETE']) + data.setdefault('state', koji.BUILD_STATES['COMPLETE']) data.setdefault('start_time', 'NOW') data.setdefault('completion_time', 'NOW') data.setdefault('source', None) - data.setdefault('owner',context.session.user_id) - data.setdefault('task_id',None) + data.setdefault('owner', context.session.user_id) + data.setdefault('task_id', None) data.setdefault('volume_id', 0) #check for existing build @@ -4466,12 +4466,12 @@ def new_build(data): st_desc = koji.BUILD_STATES[state] if st_desc == 'BUILDING': # check to see if this is the controlling task - if data['state'] == state and data.get('task_id','') == task_id: + if data['state'] == state and data.get('task_id', '') == task_id: #the controlling task must have restarted (and called initBuild again) return build_id raise koji.GenericError, "Build already in progress (task %d)" % task_id # TODO? - reclaim 'stale' builds (state=BUILDING and task_id inactive) - if st_desc in ('FAILED','CANCELED'): + if st_desc in ('FAILED', 'CANCELED'): #should be ok to replace update = UpdateProcessor('build', clauses=['id=%(id)s'], values=data) update.set(**dslice(data, ['state', 'task_id', 'owner', 'start_time', 'completion_time', 'epoch'])) @@ -4543,7 +4543,7 @@ def import_build(srpm, rpms, brmap=None, task_id=None, build_id=None, logs=None) uploadpath = koji.pathinfo.work() #verify files exist for relpath in [srpm] + rpms: - fn = "%s/%s" % (uploadpath,relpath) + fn = "%s/%s" % (uploadpath, relpath) if not os.path.exists(fn): raise koji.GenericError, "no such file: %s" % fn @@ -4559,8 +4559,8 @@ def import_build(srpm, rpms, brmap=None, task_id=None, build_id=None, logs=None) BuildRoot(br_id) #read srpm info - fn = "%s/%s" % (uploadpath,srpm) - build = koji.get_header_fields(fn,('name','version','release','epoch', + fn = "%s/%s" % (uploadpath, srpm) + build = koji.get_header_fields(fn, ('name', 'version', 'release', 'epoch', 'sourcepackage')) if build['sourcepackage'] != 1: raise koji.GenericError, "not a source package: %s" % fn @@ -4573,7 +4573,7 @@ def import_build(srpm, rpms, brmap=None, task_id=None, build_id=None, logs=None) binfo = get_build(build_id, strict=True) st_complete = koji.BUILD_STATES['COMPLETE'] koji.plugin.run_callbacks('preBuildStateChange', attribute='state', old=binfo['state'], new=st_complete, info=binfo) - for key in ('name','version','release','epoch','task_id'): + for key in ('name', 'version', 'release', 'epoch', 'task_id'): if build[key] != binfo[key]: raise koji.GenericError, "Unable to complete build: %s mismatch (build: %s, rpm: %s)" % (key, binfo[key], build[key]) if binfo['state'] != koji.BUILD_STATES['BUILDING']: @@ -4582,11 +4582,11 @@ def import_build(srpm, rpms, brmap=None, task_id=None, build_id=None, logs=None) #update build state update = """UPDATE build SET state=%(st_complete)i,completion_time=NOW() WHERE id=%(build_id)i""" - _dml(update,locals()) + _dml(update, locals()) koji.plugin.run_callbacks('postBuildStateChange', attribute='state', old=binfo['state'], new=st_complete, info=binfo) # now to handle the individual rpms for relpath in [srpm] + rpms: - fn = "%s/%s" % (uploadpath,relpath) + fn = "%s/%s" % (uploadpath, relpath) rpminfo = import_rpm(fn, binfo, brmap.get(relpath)) import_rpm_file(fn, binfo, rpminfo) add_rpm_sig(rpminfo['id'], koji.rip_rpm_sighdr(fn)) @@ -4595,7 +4595,7 @@ def import_build(srpm, rpms, brmap=None, task_id=None, build_id=None, logs=None) if not key: key = None for relpath in files: - fn = "%s/%s" % (uploadpath,relpath) + fn = "%s/%s" % (uploadpath, relpath) import_build_log(fn, binfo, subdir=key) koji.plugin.run_callbacks('postImport', type='build', srpm=srpm, rpms=rpms, brmap=brmap, task_id=task_id, build_id=build_id, build=binfo, logs=logs) @@ -4612,8 +4612,8 @@ def import_rpm(fn, buildinfo=None, brootid=None, wrapper=False, fileinfo=None): #read rpm info hdr = koji.get_rpm_header(fn) - rpminfo = koji.get_header_fields(hdr,['name','version','release','epoch', - 'sourcepackage','arch','buildtime','sourcerpm']) + rpminfo = koji.get_header_fields(hdr, ['name', 'version', 'release', 'epoch', + 'sourcepackage', 'arch', 'buildtime', 'sourcerpm']) if rpminfo['sourcepackage'] == 1: rpminfo['arch'] = "src" @@ -4621,7 +4621,7 @@ def import_rpm(fn, buildinfo=None, brootid=None, wrapper=False, fileinfo=None): basename = os.path.basename(fn) expected = "%(name)s-%(version)s-%(release)s.%(arch)s.rpm" % rpminfo if basename != expected: - raise koji.GenericError, "bad filename: %s (expected %s)" % (basename,expected) + raise koji.GenericError, "bad filename: %s (expected %s)" % (basename, expected) if buildinfo is None: #figure it out for ourselves @@ -4650,10 +4650,10 @@ def import_rpm(fn, buildinfo=None, brootid=None, wrapper=False, fileinfo=None): if rpminfo['sourcepackage'] != 1: if rpminfo['sourcerpm'] != srpmname: raise koji.GenericError, "srpm mismatch for %s: %s (expected %s)" \ - % (fn,rpminfo['sourcerpm'],srpmname) + % (fn, rpminfo['sourcerpm'], srpmname) elif basename != srpmname: raise koji.GenericError, "srpm mismatch for %s: %s (expected %s)" \ - % (fn,basename,srpmname) + % (fn, basename, srpmname) #add rpminfo entry rpminfo['id'] = _singleValue("""SELECT nextval('rpminfo_id_seq')""") @@ -5122,7 +5122,7 @@ def add_external_rpm(rpminfo, external_repo, strict=True): raise koji.GenericError, "external rpm already exists: %s" % disp elif data['payloadhash'] != previous['payloadhash']: raise koji.GenericError, "hash changed for external rpm: %s (%s -> %s)" \ - % (disp, previous['payloadhash'], data['payloadhash']) + % (disp, previous['payloadhash'], data['payloadhash']) else: return previous @@ -5154,14 +5154,14 @@ def import_build_log(fn, buildinfo, subdir=None): if os.path.islink(fn) or not os.path.isfile(fn): raise koji.GenericError("Error importing build log. %s is not a regular file." % fn) safer_move(fn, final_path) - os.symlink(final_path,fn) + os.symlink(final_path, fn) -def import_rpm_file(fn,buildinfo,rpminfo): +def import_rpm_file(fn, buildinfo, rpminfo): """Move the rpm file into the proper place Generally this is done after the db import """ - final_path = "%s/%s" % (koji.pathinfo.build(buildinfo),koji.pathinfo.rpm(rpminfo)) + final_path = "%s/%s" % (koji.pathinfo.build(buildinfo), koji.pathinfo.rpm(rpminfo)) _import_archive_file(fn, os.path.dirname(final_path)) def import_build_in_place(build): @@ -5193,18 +5193,18 @@ def import_build_in_place(build): for basename in os.listdir(srcdir): if basename != srpmname: raise koji.GenericError, "unexpected file: %s" % basename - srpm = "%s/%s" % (srcdir,basename) + srpm = "%s/%s" % (srcdir, basename) for arch in os.listdir(bdir): if arch == 'src': #already done that continue if arch == "data": continue - adir = "%s/%s" % (bdir,arch) + adir = "%s/%s" % (bdir, arch) if not os.path.isdir(adir): raise koji.GenericError, "out of place file: %s" % adir for basename in os.listdir(adir): - fn = "%s/%s" % (adir,basename) + fn = "%s/%s" % (adir, basename) if not os.path.isfile(fn): raise koji.GenericError, "unexpected non-regular file: %s" % fn if fn[-4:] != '.rpm': @@ -5214,7 +5214,7 @@ def import_build_in_place(build): sourcerpm = hdr[rpm.RPMTAG_SOURCERPM] if sourcerpm != srpmname: raise koji.GenericError, "srpm mismatch for %s: %s (expected %s)" \ - % (fn,sourcerpm,srpmname) + % (fn, sourcerpm, srpmname) rpms.append(fn) koji.plugin.run_callbacks('preImport', type='build', in_place=True, srpm=srpm, rpms=rpms) # actually import @@ -5225,7 +5225,7 @@ def import_build_in_place(build): buildinfo = rpminfo['build'] # file already in place for fn in rpms: - rpminfo = import_rpm(fn,buildinfo) + rpminfo = import_rpm(fn, buildinfo) add_rpm_sig(rpminfo['id'], koji.rip_rpm_sighdr(fn)) #update build state build_id = buildinfo['id'] @@ -5233,7 +5233,7 @@ def import_build_in_place(build): koji.plugin.run_callbacks('preBuildStateChange', attribute='state', old=buildinfo['state'], new=st_complete, info=buildinfo) update = """UPDATE build SET state=%(st_complete)i,completion_time=NOW() WHERE id=%(build_id)i""" - _dml(update,locals()) + _dml(update, locals()) koji.plugin.run_callbacks('postBuildStateChange', attribute='state', old=buildinfo['state'], new=st_complete, info=buildinfo) koji.plugin.run_callbacks('postImport', type='build', in_place=True, srpm=srpm, rpms=rpms) return build_id @@ -5477,7 +5477,7 @@ def new_image_build(build_info): def old_image_data(old_image_id): """Return old image data for given id""" - values = dict(img_id = old_image_id) + values = dict(img_id=old_image_id) tables = ['imageinfo'] fields = ['id', 'task_id', 'filename', 'filesize', 'arch', 'hash', 'mediatype'] clauses = ['imageinfo.id = %(img_id)i'] @@ -5890,7 +5890,7 @@ def _scan_sighdr(sighdr, fn): #main header outp.write(inp.read(hdrsize)) inp.close() - outp.seek(0,0) + outp.seek(0, 0) ts = rpm.TransactionSet() ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS) #(we have no payload, so verifies would fail otherwise) @@ -6092,7 +6092,7 @@ def query_history(tables=None, **kwargs): fields.update(common_joined_fields) joined = {} for field in table_fields[table]: - fullname = "%s.%s" % (table,field) + fullname = "%s.%s" % (table, field) fields[fullname] = field name_join = name_joins.get(field) if name_join: @@ -6441,7 +6441,7 @@ def build_references(build_id, limit=None): opts={'order': '-standard_buildroot.create_event', 'limit': 1}) event_id = -1 for (rpm_id,) in rpm_ids: - query.values={'rpm_id': rpm_id} + query.values = {'rpm_id': rpm_id} tmp_id = query.singleValue(strict=False) if tmp_id is not None and tmp_id > event_id: event_id = tmp_id @@ -6725,7 +6725,7 @@ def get_notification_recipients(build, tag_id, state): #FIXME - if tag_id is None, we don't have a good way to get the package owner. # using all package owners from all tags would be way overkill. - emails_uniq = dict([(x,1) for x in emails]).keys() + emails_uniq = dict([(x, 1) for x in emails]).keys() return emails_uniq def tag_notification(is_successful, tag_id, from_id, build_id, user_id, ignore_success=False, failure_msg=''): @@ -6821,7 +6821,7 @@ def drop_group_member(group, user): if not ginfo or ginfo['usertype'] != koji.USERTYPES['GROUP']: raise koji.GenericError, "No such group: %s" % group data = {'user_id' : user['id'], 'group_id' : ginfo['id']} - clauses=["user_id = %(user_id)i", "group_id = %(group_id)i"] + clauses = ["user_id = %(user_id)i", "group_id = %(group_id)i"] update = UpdateProcessor('user_groups', values=data, clauses=clauses) update.make_revoke() update.execute() @@ -6833,7 +6833,7 @@ def get_group_members(group): if group['usertype'] != koji.USERTYPES['GROUP']: raise koji.GenericError, "Not a group: %(name)s" % group group_id = group['id'] - fields = ('id','name','usertype','krb_principal') + fields = ('id', 'name', 'usertype', 'krb_principal') q = """SELECT %s FROM user_groups JOIN users ON user_id = users.id WHERE active = TRUE AND group_id = %%(group_id)i""" % ','.join(fields) @@ -7130,7 +7130,7 @@ class QueryProcessor(object): self.values = values else: self.values = {} - self.transform=transform + self.transform = transform if opts: self.opts = opts else: @@ -7255,7 +7255,7 @@ SELECT %(col_str)s data = _multiRow(query, self.values, fields) data = [self.transform(row) for row in data] # and then convert back to lists - data = [ [row[f] for f in fields] for row in data] + data = [[row[f] for f in fields] for row in data] else: data = _multiRow(query, self.values, (self.aliases or self.columns)) if self.transform is not None: @@ -7295,7 +7295,7 @@ SELECT %(col_str)s buf = _multiRow(query, self.values, fields) buf = [self.transform(row) for row in buf] # and then convert back to lists - buf = [ [row[f] for f in fields] for row in buf] + buf = [[row[f] for f in fields] for row in buf] else: buf = _multiRow(query, {}, fields) if self.transform is not None: @@ -7789,7 +7789,7 @@ def check_policy(name, data, default='deny', strict=False): reason = 'not covered by policy' else: parts = result.split(None, 1) - parts.extend(['','']) + parts.extend(['', '']) result, reason = parts[:2] reason = reason.lower() lastrule = ruleset.last_rule() @@ -7958,7 +7958,7 @@ class RootExports(object): taskOpts['priority'] = koji.PRIO_DEFAULT + priority if channel: taskOpts['channel'] = channel - return make_task('build',[src, target, opts],**taskOpts) + return make_task('build', [src, target, opts], **taskOpts) def chainBuild(self, srcs, target, opts=None, priority=None, channel=None): """Create a chained build task for building sets of packages in order @@ -7984,7 +7984,7 @@ class RootExports(object): if channel: taskOpts['channel'] = channel - return make_task('chainbuild',[srcs,target,opts],**taskOpts) + return make_task('chainbuild', [srcs, target, opts], **taskOpts) def mavenBuild(self, url, target, opts=None, priority=None, channel='maven'): """Create a Maven build task @@ -8157,7 +8157,7 @@ class RootExports(object): if not opts.has_key('scratch') and not opts.has_key('indirection_template_url'): raise koji.ActionNotAllowed, 'Non-scratch builds must provide url for the indirection template' - return make_task('indirectionimage', [ opts ], **taskOpts) + return make_task('indirectionimage', [opts], **taskOpts) # Create the image task. Called from _build_image_oz in the client. # @@ -8191,7 +8191,7 @@ class RootExports(object): check_old_image_files(old) return import_old_image(old, name, version) - def hello(self,*args): + def hello(self, *args): return "Hello World" def fault(self): @@ -8202,7 +8202,7 @@ class RootExports(object): "debugging. raise an error" raise koji.GenericError, "test error" - def echo(self,*args): + def echo(self, *args): return args def getAPIVersion(self): @@ -8276,11 +8276,11 @@ class RootExports(object): q += """ ORDER BY id DESC LIMIT 1""" return _singleRow(q, values, fields, strict=True) - def makeTask(self,*args,**opts): + def makeTask(self, *args, **opts): #this is mainly for debugging #only an admin can make arbitrary tasks context.session.assertPerm('admin') - return make_task(*args,**opts) + return make_task(*args, **opts) def uploadFile(self, path, name, size, md5sum, offset, data): #path: the relative path to upload to @@ -8343,9 +8343,9 @@ class RootExports(object): finally: fcntl.lockf(fd, fcntl.LOCK_UN) if offset == -1: - os.lseek(fd,0,2) + os.lseek(fd, 0, 2) else: - os.lseek(fd,offset,0) + os.lseek(fd, offset, 0) #write contents fcntl.lockf(fd, fcntl.LOCK_EX|fcntl.LOCK_NB, len(contents), 0, 2) try: @@ -8367,7 +8367,7 @@ class RootExports(object): chksum = sum_cls() fcntl.lockf(fd, fcntl.LOCK_SH|fcntl.LOCK_NB) try: - os.lseek(fd,0,0) + os.lseek(fd, 0, 0) while True: block = os.read(fd, 819200) if not block: break @@ -8521,8 +8521,8 @@ class RootExports(object): def createEmptyBuild(self, name, version, release, epoch, owner=None): context.session.assertPerm('admin') - data = { 'name' : name, 'version' : version, 'release' : release, - 'epoch' : epoch } + data = {'name' : name, 'version' : version, 'release' : release, + 'epoch' : epoch} if owner is not None: data['owner'] = owner return new_build(data) @@ -8576,11 +8576,11 @@ class RootExports(object): """ context.session.assertPerm('admin') uploadpath = koji.pathinfo.work() - fn = "%s/%s/%s" %(uploadpath,path,basename) + fn = "%s/%s/%s" %(uploadpath, path, basename) if not os.path.exists(fn): raise koji.GenericError, "No such file: %s" % fn rpminfo = import_rpm(fn) - import_rpm_file(fn,rpminfo['build'],rpminfo) + import_rpm_file(fn, rpminfo['build'], rpminfo) add_rpm_sig(rpminfo['id'], koji.rip_rpm_sighdr(fn)) for tag in list_tags(build=rpminfo['build_id']): set_tag_update(tag['id'], 'IMPORT') @@ -8623,7 +8623,7 @@ class RootExports(object): context.session.assertPerm('admin') add_external_rpm(rpminfo, external_repo, strict=strict) - def tagBuildBypass(self,tag,build,force=False): + def tagBuildBypass(self, tag, build, force=False): """Tag a build without running post checks or notifications This is a short circuit function for imports. @@ -8636,7 +8636,7 @@ class RootExports(object): context.session.assertPerm('admin') _tag_build(tag, build, force=force) - def tagBuild(self,tag,build,force=False,fromtag=None): + def tagBuild(self, tag, build, force=False, fromtag=None): """Request that a build be tagged The force option will attempt to force the action in the event of: @@ -8669,9 +8669,9 @@ class RootExports(object): state = koji.BUILD_STATES[build['state']] raise koji.TagError, "build %s not complete: state %s" % (build['nvr'], state) # basic tag access check - assert_tag_access(tag_id,user_id=None,force=force) + assert_tag_access(tag_id, user_id=None, force=force) if fromtag: - assert_tag_access(fromtag_id,user_id=None,force=force) + assert_tag_access(fromtag_id, user_id=None, force=force) # package list check pkgs = readPackageList(tagID=tag_id, pkgID=pkg_id, inherit=True) pkg_error = None @@ -8681,7 +8681,7 @@ class RootExports(object): pkg_error = "Package %s blocked in %s" % (build['name'], tag['name']) if pkg_error: if force and context.session.hasPerm('admin'): - pkglist_add(tag_id,pkg_id,force=True,block=False) + pkglist_add(tag_id, pkg_id, force=True, block=False) else: raise koji.TagError, pkg_error # tag policy check @@ -8697,7 +8697,7 @@ class RootExports(object): #spawn the tagging task return make_task('tagBuild', [tag_id, build_id, force, fromtag_id], priority=10) - def untagBuild(self,tag,build,strict=True,force=False): + def untagBuild(self, tag, build, strict=True, force=False): """Untag a build Unlike tagBuild, this does not create a task @@ -8712,7 +8712,7 @@ class RootExports(object): #don't check policy for admins using force if not (force and context.session.hasPerm('admin')): assert_policy('tag', policy_data) - _untag_build(tag,build,strict=strict,force=force) + _untag_build(tag, build, strict=strict, force=force) tag_notification(True, None, tag, build, user_id) except Exception: exctype, value = sys.exc_info()[:2] @@ -8729,11 +8729,11 @@ class RootExports(object): context.session.assertPerm('admin') _untag_build(tag, build, strict=strict, force=force) - def moveBuild(self,tag1,tag2,build,force=False): + def moveBuild(self, tag1, tag2, build, force=False): """Move a build from tag1 to tag2 Returns the task id of the task performing the move""" - return self.tagBuild(tag2,build,force=force,fromtag=tag1) + return self.tagBuild(tag2, build, force=force, fromtag=tag1) def moveAllBuilds(self, tag1, tag2, package, force=False): """Move all builds of a package from tag1 to tag2 in the correct order @@ -8756,13 +8756,13 @@ class RootExports(object): pkg_error = "Package %s blocked in tag %s" % (package, tag2) if pkg_error: if force and context.session.hasPerm('admin'): - pkglist_add(tag2_id,pkg_id,force=True,block=False) + pkglist_add(tag2_id, pkg_id, force=True, block=False) else: raise koji.TagError, pkg_error #access check - assert_tag_access(tag1_id,user_id=None,force=force) - assert_tag_access(tag2_id,user_id=None,force=force) + assert_tag_access(tag1_id, user_id=None, force=force) + assert_tag_access(tag2_id, user_id=None, force=force) build_list = readTaggedBuilds(tag1_id, package=package) # we want 'ORDER BY tag_listing.create_event ASC' not DESC so reverse @@ -8908,23 +8908,23 @@ class RootExports(object): raise koji.ActionNotAllowed, 'Cannot cancel build, not owner' return cancel_build(build['id']) - def assignTask(self,task_id,host,force=False): + def assignTask(self, task_id, host, force=False): """Assign a task to a host Specify force=True to assign a non-free task """ context.session.assertPerm('admin') task = Task(task_id) - host = get_host(host,strict=True) - task.assign(host['id'],force) + host = get_host(host, strict=True) + task.assign(host['id'], force) - def freeTask(self,task_id): + def freeTask(self, task_id): """Free a task""" context.session.assertPerm('admin') task = Task(task_id) task.free() - def cancelTask(self,task_id,recurse=True): + def cancelTask(self, task_id, recurse=True): """Cancel a task""" task = Task(task_id) if not task.verifyOwner() and not task.verifyHost(): @@ -8933,13 +8933,13 @@ class RootExports(object): #non-admins can also use cancelBuild task.cancel(recurse=recurse) - def cancelTaskFull(self,task_id,strict=True): + def cancelTaskFull(self, task_id, strict=True): """Cancel a task and all tasks in its group""" context.session.assertPerm('admin') #non-admins can use cancelBuild or cancelTask Task(task_id).cancelFull(strict=strict) - def cancelTaskChildren(self,task_id): + def cancelTaskChildren(self, task_id): """Cancel a task's children, but not the task itself""" task = Task(task_id) if not task.verifyOwner() and not task.verifyHost(): @@ -8953,28 +8953,28 @@ class RootExports(object): task = Task(task_id) task.setPriority(priority, recurse=recurse) - def listTagged(self,tag,event=None,inherit=False,prefix=None,latest=False,package=None,owner=None,type=None): + def listTagged(self, tag, event=None, inherit=False, prefix=None, latest=False, package=None, owner=None, type=None): """List builds tagged with tag""" - if not isinstance(tag,int): + if not isinstance(tag, int): #lookup tag id - tag = get_tag_id(tag,strict=True) - results = readTaggedBuilds(tag,event,inherit=inherit,latest=latest,package=package,owner=owner,type=type) + tag = get_tag_id(tag, strict=True) + results = readTaggedBuilds(tag, event, inherit=inherit, latest=latest, package=package, owner=owner, type=type) if prefix: prefix = prefix.lower() results = [build for build in results if build['package_name'].lower().startswith(prefix)] return results - def listTaggedRPMS(self,tag,event=None,inherit=False,latest=False,package=None,arch=None,rpmsigs=False,owner=None,type=None): + def listTaggedRPMS(self, tag, event=None, inherit=False, latest=False, package=None, arch=None, rpmsigs=False, owner=None, type=None): """List rpms and builds within tag""" - if not isinstance(tag,int): + if not isinstance(tag, int): #lookup tag id - tag = get_tag_id(tag,strict=True) - return readTaggedRPMS(tag,event=event,inherit=inherit,latest=latest,package=package,arch=arch,rpmsigs=rpmsigs,owner=owner,type=type) + tag = get_tag_id(tag, strict=True) + return readTaggedRPMS(tag, event=event, inherit=inherit, latest=latest, package=package, arch=arch, rpmsigs=rpmsigs, owner=owner, type=type) def listTaggedArchives(self, tag, event=None, inherit=False, latest=False, package=None, type=None): """List archives and builds within a tag""" if not isinstance(tag, int): - tag = get_tag_id(tag,strict=True) + tag = get_tag_id(tag, strict=True) return readTaggedArchives(tag, event=event, inherit=inherit, latest=latest, package=package, type=type) def listBuilds(self, packageID=None, userID=None, taskID=None, prefix=None, state=None, @@ -9039,9 +9039,9 @@ class RootExports(object): ('build.epoch', 'epoch'), ('build.state', 'state'), ('build.completion_time', 'completion_time'), ('build.start_time', 'start_time'), ('events.id', 'creation_event_id'), ('events.time', 'creation_time'), ('build.task_id', 'task_id'), - ('EXTRACT(EPOCH FROM events.time)','creation_ts'), - ('EXTRACT(EPOCH FROM build.start_time)','start_ts'), - ('EXTRACT(EPOCH FROM build.completion_time)','completion_ts'), + ('EXTRACT(EPOCH FROM events.time)', 'creation_ts'), + ('EXTRACT(EPOCH FROM build.start_time)', 'start_ts'), + ('EXTRACT(EPOCH FROM build.completion_time)', 'completion_ts'), ('package.id', 'package_id'), ('package.name', 'package_name'), ('package.name', 'name'), ('volume.id', 'volume_id'), ('volume.name', 'volume_name'), ("package.name || '-' || build.version || '-' || build.release", 'nvr'), @@ -9120,18 +9120,18 @@ class RootExports(object): return query.iterate() - def getLatestBuilds(self,tag,event=None,package=None,type=None): + def getLatestBuilds(self, tag, event=None, package=None, type=None): """List latest builds for tag (inheritance enabled)""" - if not isinstance(tag,int): + if not isinstance(tag, int): #lookup tag id - tag = get_tag_id(tag,strict=True) - return readTaggedBuilds(tag,event,inherit=True,latest=True,package=package,type=type) + tag = get_tag_id(tag, strict=True) + return readTaggedBuilds(tag, event, inherit=True, latest=True, package=package, type=type) def getLatestRPMS(self, tag, package=None, arch=None, event=None, rpmsigs=False, type=None): """List latest RPMS for tag (inheritance enabled)""" - if not isinstance(tag,int): + if not isinstance(tag, int): #lookup tag id - tag = get_tag_id(tag,strict=True) + tag = get_tag_id(tag, strict=True) return readTaggedRPMS(tag, package=package, arch=arch, event=event, inherit=True, latest=True, rpmsigs=rpmsigs, type=type) def getLatestMavenArchives(self, tag, event=None, inherit=True): @@ -9187,36 +9187,36 @@ class RootExports(object): getGlobalInheritance = staticmethod(readGlobalInheritance) - def getInheritanceData(self,tag,event=None): + def getInheritanceData(self, tag, event=None): """Return inheritance data for tag""" - if not isinstance(tag,int): + if not isinstance(tag, int): #lookup tag id - tag = get_tag_id(tag,strict=True) - return readInheritanceData(tag,event) + tag = get_tag_id(tag, strict=True) + return readInheritanceData(tag, event) - def setInheritanceData(self,tag,data,clear=False): - if not isinstance(tag,int): + def setInheritanceData(self, tag, data, clear=False): + if not isinstance(tag, int): #lookup tag id - tag = get_tag_id(tag,strict=True) + tag = get_tag_id(tag, strict=True) context.session.assertPerm('admin') - return writeInheritanceData(tag,data,clear=clear) + return writeInheritanceData(tag, data, clear=clear) - def getFullInheritance(self,tag,event=None,reverse=False,stops=None,jumps=None): + def getFullInheritance(self, tag, event=None, reverse=False, stops=None, jumps=None): if stops is None: stops = {} if jumps is None: jumps = {} - if not isinstance(tag,int): + if not isinstance(tag, int): #lookup tag id - tag = get_tag_id(tag,strict=True) + tag = get_tag_id(tag, strict=True) for mapping in [stops, jumps]: for key in mapping.keys(): mapping[int(key)] = mapping[key] - return readFullInheritance(tag,event,reverse,stops,jumps) + return readFullInheritance(tag, event, reverse, stops, jumps) listRPMs = staticmethod(list_rpms) - def listBuildRPMs(self,build): + def listBuildRPMs(self, build): """Get information about all the RPMs generated by the build with the given ID. A list of maps is returned, each map containing the following keys: @@ -9265,7 +9265,7 @@ class RootExports(object): results = [] - for dep_name in ['REQUIRE','PROVIDE','CONFLICT','OBSOLETE']: + for dep_name in ['REQUIRE', 'PROVIDE', 'CONFLICT', 'OBSOLETE']: dep_id = getattr(koji, 'DEP_' + dep_name) if depType is None or depType == dep_id: fields = koji.get_header_fields(rpm_path, [dep_name + 'NAME', @@ -9416,11 +9416,11 @@ class RootExports(object): getTagID = staticmethod(get_tag_id) getTag = staticmethod(get_tag) - def getPackageID(self,name): - c=context.cnx.cursor() - q="""SELECT id FROM package WHERE name=%(name)s""" - c.execute(q,locals()) - r=c.fetchone() + def getPackageID(self, name): + c = context.cnx.cursor() + q = """SELECT id FROM package WHERE name=%(name)s""" + c.execute(q, locals()) + r = c.fetchone() if not r: return None return r[0] @@ -9450,14 +9450,14 @@ class RootExports(object): """ if tagID is None and userID is None and pkgID is None: query = """SELECT id, name from package""" - results = _multiRow(query,{},('package_id', 'package_name')) + results = _multiRow(query, {}, ('package_id', 'package_name')) else: if tagID is not None: - tagID = get_tag_id(tagID,strict=True) + tagID = get_tag_id(tagID, strict=True) if userID is not None: - userID = get_user(userID,strict=True)['id'] + userID = get_user(userID, strict=True)['id'] if pkgID is not None: - pkgID = get_package_id(pkgID,strict=True) + pkgID = get_package_id(pkgID, strict=True) result_list = readPackageList(tagID=tagID, userID=userID, pkgID=pkgID, inherit=inherited, with_dups=with_dups, event=event).values() @@ -9476,10 +9476,10 @@ class RootExports(object): return results - def checkTagPackage(self,tag,pkg): + def checkTagPackage(self, tag, pkg): """Check that pkg is in the list for tag. Returns true/false""" - tag_id = get_tag_id(tag,strict=False) - pkg_id = get_package_id(pkg,strict=False) + tag_id = get_tag_id(tag, strict=False) + pkg_id = get_package_id(pkg, strict=False) if pkg_id is None or tag_id is None: return False pkgs = readPackageList(tagID=tag_id, pkgID=pkg_id, inherit=True) @@ -9489,21 +9489,21 @@ class RootExports(object): #still might be blocked return not pkgs[pkg_id]['blocked'] - def getPackageConfig(self,tag,pkg,event=None): + def getPackageConfig(self, tag, pkg, event=None): """Get config for package in tag""" - tag_id = get_tag_id(tag,strict=False) - pkg_id = get_package_id(pkg,strict=False) + tag_id = get_tag_id(tag, strict=False) + pkg_id = get_package_id(pkg, strict=False) if pkg_id is None or tag_id is None: return None pkgs = readPackageList(tagID=tag_id, pkgID=pkg_id, inherit=True, event=event) - return pkgs.get(pkg_id,None) + return pkgs.get(pkg_id, None) getUser = staticmethod(get_user) def grantPermission(self, userinfo, permission, create=False): """Grant a permission to a user""" context.session.assertPerm('admin') - user_id = get_user(userinfo,strict=True)['id'] + user_id = get_user(userinfo, strict=True)['id'] perm = lookup_perm(permission, strict=(not create), create=create) perm_id = perm['id'] if perm['name'] in koji.auth.get_user_perms(user_id): @@ -9581,9 +9581,9 @@ class RootExports(object): values=locals(), opts=queryOpts) return query.execute() - def getBuildConfig(self,tag,event=None): + def getBuildConfig(self, tag, event=None): """Return build configuration associated with a tag""" - taginfo = get_tag(tag,strict=True,event=event) + taginfo = get_tag(tag, strict=True, event=event) order = readFullInheritance(taginfo['id'], event=event) #follow inheritance for arches and extra for link in order: @@ -9597,11 +9597,11 @@ class RootExports(object): taginfo['extra'][key] = ancestor['extra'][key] return taginfo - def getRepo(self,tag,state=None,event=None): - if isinstance(tag,int): + def getRepo(self, tag, state=None, event=None): + if isinstance(tag, int): id = tag else: - id = get_tag_id(tag,strict=True) + id = get_tag_id(tag, strict=True) fields = ['repo.id', 'repo.state', 'repo.create_event', 'events.time', 'EXTRACT(EPOCH FROM events.time)'] aliases = ['id', 'state', 'create_event', 'creation_time', 'create_ts'] @@ -9613,7 +9613,7 @@ class RootExports(object): else: if state is None: state = koji.REPO_READY - clauses.append('repo.state = %(state)s' ) + clauses.append('repo.state = %(state)s') query = QueryProcessor(columns=fields, aliases=aliases, tables=['repo'], joins=joins, clauses=clauses, @@ -9677,7 +9677,7 @@ class RootExports(object): getBuildTargets = staticmethod(get_build_targets) getBuildTarget = staticmethod(get_build_target) - def taskFinished(self,taskId): + def taskFinished(self, taskId): task = Task(taskId) return task.isFinished() @@ -9835,10 +9835,10 @@ class RootExports(object): if queryOpts.get('asList'): keys = [] for n, f in aliases: - if f in ('request','result'): + if f in ('request', 'result'): keys.append(n) else: - keys = ('request','result') + keys = ('request', 'result') tasks = self._decode_tasks(tasks, keys) return tasks @@ -9862,27 +9862,27 @@ class RootExports(object): def taskReport(self, owner=None): """Return data on active or recent tasks""" fields = ( - ('task.id','id'), - ('task.state','state'), - ('task.create_time','create_time'), - ('task.completion_time','completion_time'), - ('task.channel_id','channel_id'), - ('channels.name','channel'), - ('task.host_id','host_id'), - ('host.name','host'), - ('task.parent','parent'), - ('task.waiting','waiting'), - ('task.awaited','awaited'), - ('task.method','method'), - ('task.arch','arch'), - ('task.priority','priority'), - ('task.weight','weight'), - ('task.owner','owner_id'), - ('users.name','owner'), - ('build.id','build_id'), - ('package.name','build_name'), - ('build.version','build_version'), - ('build.release','build_release'), + ('task.id', 'id'), + ('task.state', 'state'), + ('task.create_time', 'create_time'), + ('task.completion_time', 'completion_time'), + ('task.channel_id', 'channel_id'), + ('channels.name', 'channel'), + ('task.host_id', 'host_id'), + ('host.name', 'host'), + ('task.parent', 'parent'), + ('task.waiting', 'waiting'), + ('task.awaited', 'awaited'), + ('task.method', 'method'), + ('task.arch', 'arch'), + ('task.priority', 'priority'), + ('task.weight', 'weight'), + ('task.owner', 'owner_id'), + ('users.name', 'owner'), + ('build.id', 'build_id'), + ('package.name', 'build_name'), + ('build.version', 'build_version'), + ('build.release', 'build_release'), ) q = """SELECT %s FROM task JOIN channels ON task.channel_id = channels.id @@ -9900,8 +9900,8 @@ class RootExports(object): """ #XXX hard-coded interval c = context.cnx.cursor() - c.execute(q,koji.TASK_STATES) - return [dict(zip([f[1] for f in fields],row)) for row in c.fetchall()] + c.execute(q, koji.TASK_STATES) + return [dict(zip([f[1] for f in fields], row)) for row in c.fetchall()] def resubmitTask(self, taskID): """Retry a canceled or failed task, using the same parameter as the original task. @@ -10017,11 +10017,11 @@ class RootExports(object): getAllArches = staticmethod(get_all_arches) getChannel = staticmethod(get_channel) - listChannels=staticmethod(list_channels) + listChannels = staticmethod(list_channels) - getBuildroot=staticmethod(get_buildroot) + getBuildroot = staticmethod(get_buildroot) - def getBuildrootListing(self,id): + def getBuildrootListing(self, id): """Return a list of packages in the buildroot""" br = BuildRoot(id) return br.getList() @@ -10076,7 +10076,7 @@ class RootExports(object): buildid = buildinfo['id'] koji.plugin.run_callbacks('preBuildStateChange', attribute='owner_id', old=buildinfo['owner_id'], new=userid, info=buildinfo) q = """UPDATE build SET owner=%(userid)i WHERE id=%(buildid)i""" - _dml(q,locals()) + _dml(q, locals()) koji.plugin.run_callbacks('postBuildStateChange', attribute='owner_id', old=buildinfo['owner_id'], new=userid, info=buildinfo) def setBuildTimestamp(self, build, ts): @@ -10093,7 +10093,7 @@ class RootExports(object): #not recommended #the xmlrpclib.DateTime class is almost useless try: - ts = time.mktime(time.strptime(str(ts),'%Y%m%dT%H:%M:%S')) + ts = time.mktime(time.strptime(str(ts), '%Y%m%dT%H:%M:%S')) except ValueError: raise koji.GenericError, "Invalid time: %s" % ts elif not isinstance(ts, (int, long, float)): @@ -10103,7 +10103,7 @@ class RootExports(object): q = """UPDATE build SET completion_time=TIMESTAMP 'epoch' AT TIME ZONE 'utc' + '%(ts)f seconds'::interval WHERE id=%%(buildid)i""" % locals() - _dml(q,locals()) + _dml(q, locals()) koji.plugin.run_callbacks('postBuildStateChange', attribute='completion_ts', old=buildinfo['completion_ts'], new=ts, info=buildinfo) def count(self, methodName, *args, **kw): @@ -10345,7 +10345,7 @@ class RootExports(object): class BuildRoot(object): - def __init__(self,id=None): + def __init__(self, id=None): if id is None: #db entry has yet to be created self.id = None @@ -10435,7 +10435,7 @@ class BuildRoot(object): data['extra'] = json.dumps(data['extra']), br_id = _singleValue("SELECT nextval('buildroot_id_seq')", strict=True) insert = InsertProcessor('buildroot') - insert.set(id = br_id, **data) + insert.set(id=br_id, **data) insert.execute() self.load(br_id) return self.id @@ -10454,7 +10454,7 @@ class BuildRoot(object): self.assertStandard() if not self.verifyTask(task_id): raise koji.ActionNotAllowed, 'Task %s does not have lock on buildroot %s' \ - %(task_id,self.id) + %(task_id, self.id) def verifyHost(self, host_id): self.assertStandard() @@ -10464,7 +10464,7 @@ class BuildRoot(object): self.assertStandard() if not self.verifyHost(host_id): raise koji.ActionNotAllowed, "Host %s not owner of buildroot %s" \ - % (host_id,self.id) + % (host_id, self.id) def setState(self, state): self.assertStandard() @@ -10554,13 +10554,13 @@ class BuildRoot(object): if self.is_standard and self.data['state'] != koji.BR_STATES['INIT']: raise koji.GenericError, "buildroot %(id)s in wrong state %(state)s" % self.data - self._setList(rpmlist,update=False) + self._setList(rpmlist, update=False) def updateList(self, rpmlist): """Update the list of packages in a buildroot""" if self.is_standard and self.data['state'] != koji.BR_STATES['BUILDING']: raise koji.GenericError, "buildroot %(id)s in wrong state %(state)s" % self.data - self._setList(rpmlist,update=True) + self._setList(rpmlist, update=True) def getArchiveList(self, queryOpts=None): """Get the list of archives in the buildroot""" @@ -10618,7 +10618,7 @@ class BuildRoot(object): class Host(object): - def __init__(self,id=None): + def __init__(self, id=None): remote_id = context.session.getHostId() if id is None: id = remote_id @@ -10677,7 +10677,7 @@ class Host(object): logger.warning('taskSetWait called on empty task list by parent: %s', parent) - def taskWaitCheck(self,parent): + def taskWaitCheck(self, parent): """Return status of awaited subtask The return value is [finished, unfinished] where each entry @@ -10688,20 +10688,20 @@ class Host(object): SELECT id,state FROM task WHERE parent=%(parent)s AND awaited = TRUE FOR UPDATE""" - c.execute(q,locals()) + c.execute(q, locals()) canceled = koji.TASK_STATES['CANCELED'] closed = koji.TASK_STATES['CLOSED'] failed = koji.TASK_STATES['FAILED'] finished = [] unfinished = [] - for id,state in c.fetchall(): - if state in (canceled,closed,failed): + for id, state in c.fetchall(): + if state in (canceled, closed, failed): finished.append(id) else: unfinished.append(id) return finished, unfinished - def taskWait(self,parent): + def taskWait(self, parent): """Return task results or mark tasks as waited upon""" finished, unfinished = self.taskWaitCheck(parent) # un-await finished tasks @@ -10710,8 +10710,8 @@ class Host(object): for id in finished: c = context.cnx.cursor() q = """UPDATE task SET awaited='false' WHERE id=%(id)s""" - c.execute(q,locals()) - return [finished,unfinished] + c.execute(q, locals()) + return [finished, unfinished] def taskWaitResults(self, parent, tasks): # If we're getting results, we're done waiting @@ -10726,8 +10726,8 @@ class Host(object): if tasks is None: # Query all subtasks tasks = [] - c.execute(q,locals()) - for id,state in c.fetchall(): + c.execute(q, locals()) + for id, state in c.fetchall(): if state == canceled: raise koji.GenericError, "Subtask canceled" elif state in (closed, failed): @@ -10744,14 +10744,14 @@ class Host(object): c = context.cnx.cursor() host_id = self.id #query tasks - fields = ['id','waiting','weight'] + fields = ['id', 'waiting', 'weight'] st_open = koji.TASK_STATES['OPEN'] q = """ SELECT %s FROM task WHERE host_id = %%(host_id)s AND state = %%(st_open)s """ % (",".join(fields)) - c.execute(q,locals()) - tasks = [ dict(zip(fields,x)) for x in c.fetchall() ] + c.execute(q, locals()) + tasks = [dict(zip(fields, x)) for x in c.fetchall()] for task in tasks: id = task['id'] if task['waiting']: @@ -10760,13 +10760,13 @@ class Host(object): task['alert'] = True return tasks - def updateHost(self,task_load,ready): + def updateHost(self, task_load, ready): host_data = get_host(self.id) if task_load != host_data['task_load'] or ready != host_data['ready']: c = context.cnx.cursor() id = self.id q = """UPDATE host SET task_load=%(task_load)s,ready=%(ready)s WHERE id=%(id)s""" - c.execute(q,locals()) + c.execute(q, locals()) context.commit_pending = True def getLoadData(self): @@ -10793,13 +10793,13 @@ class Host(object): q = """ SELECT arches FROM host WHERE id = %(id)s """ - c.execute(q,locals()) + c.execute(q, locals()) arches = c.fetchone()[0].split() q = """ SELECT channel_id FROM host_channels WHERE host_id = %(id)s """ - c.execute(q,locals()) - channels = [ x[0] for x in c.fetchall() ] + c.execute(q, locals()) + channels = [x[0] for x in c.fetchall()] #query tasks fields = ['id', 'state', 'method', 'request', 'channel_id', 'arch', 'parent'] @@ -10811,9 +10811,9 @@ class Host(object): OR (state = %%(st_assigned)s AND host_id = %%(id)s) ORDER BY priority,create_time """ % (",".join(fields)) - c.execute(q,locals()) + c.execute(q, locals()) for data in c.fetchall(): - data = dict(zip(fields,data)) + data = dict(zip(fields, data)) # XXX - we should do some pruning here, but for now... # check arch if data['arch'] not in arches: @@ -10844,10 +10844,10 @@ class HostExports(object): host.verify() return host.id - def updateHost(self,task_load,ready): + def updateHost(self, task_load, ready): host = Host() host.verify() - host.updateHost(task_load,ready) + host.updateHost(task_load, ready) def getLoadData(self): host = Host() @@ -10860,7 +10860,7 @@ class HostExports(object): host.verify() return get_host(host.id) - def openTask(self,task_id): + def openTask(self, task_id): host = Host() host.verify() task = Task(task_id) @@ -10871,21 +10871,21 @@ class HostExports(object): host.verify() return host.getTask() - def closeTask(self,task_id,response): + def closeTask(self, task_id, response): host = Host() host.verify() task = Task(task_id) task.assertHost(host.id) return task.close(response) - def failTask(self,task_id,response): + def failTask(self, task_id, response): host = Host() host.verify() task = Task(task_id) task.assertHost(host.id) return task.fail(response) - def freeTasks(self,tasks): + def freeTasks(self, tasks): host = Host() host.verify() for task_id in tasks: @@ -10898,7 +10898,7 @@ class HostExports(object): #XXX - unfinished #remove any files related to task - def setTaskWeight(self,task_id,weight): + def setTaskWeight(self, task_id, weight): host = Host() host.verify() task = Task(task_id) @@ -10910,22 +10910,22 @@ class HostExports(object): host.verify() return host.getHostTasks() - def taskSetWait(self,parent,tasks): + def taskSetWait(self, parent, tasks): host = Host() host.verify() - return host.taskSetWait(parent,tasks) + return host.taskSetWait(parent, tasks) - def taskWait(self,parent): + def taskWait(self, parent): host = Host() host.verify() return host.taskWait(parent) - def taskWaitResults(self,parent,tasks): + def taskWaitResults(self, parent, tasks): host = Host() host.verify() - return host.taskWaitResults(parent,tasks) + return host.taskWaitResults(parent, tasks) - def subtask(self,method,arglist,parent,**opts): + def subtask(self, method, arglist, parent, **opts): host = Host() host.verify() ptask = Task(parent) @@ -10935,16 +10935,16 @@ class HostExports(object): # first check for existing task with this parent/label q = """SELECT id FROM task WHERE parent=%(parent)s AND label=%(label)s""" - row = _fetchSingle(q,opts) + row = _fetchSingle(q, opts) if row: #return task id return row[0] if opts.has_key('kwargs'): arglist = koji.encode_args(*arglist, **opts['kwargs']) del opts['kwargs'] - return make_task(method,arglist,**opts) + return make_task(method, arglist, **opts) - def subtask2(self,__parent,__taskopts,__method,*args,**opts): + def subtask2(self, __parent, __taskopts, __method, *args, **opts): """A wrapper around subtask with optional signature Parameters: @@ -10955,8 +10955,8 @@ class HostExports(object): Remaining args are passed on to the subtask """ #self.subtask will verify the host - args = koji.encode_args(*args,**opts) - return self.subtask(__method,args,__parent,**__taskopts) + args = koji.encode_args(*args, **opts) + return self.subtask(__method, args, __parent, **__taskopts) def moveBuildToScratch(self, task_id, srpm, rpms, logs=None): "Move a completed scratch build into place (not imported)" @@ -10967,7 +10967,7 @@ class HostExports(object): uploadpath = koji.pathinfo.work() #verify files exist for relpath in [srpm] + rpms: - fn = "%s/%s" % (uploadpath,relpath) + fn = "%s/%s" % (uploadpath, relpath) if not os.path.exists(fn): raise koji.GenericError, "no such file: %s" % fn @@ -10980,10 +10980,10 @@ class HostExports(object): dir = "%s/%s/task_%s" % (scratchdir, username, task_id) koji.ensuredir(dir) for relpath in [srpm] + rpms: - fn = "%s/%s" % (uploadpath,relpath) - dest = "%s/%s" % (dir,os.path.basename(fn)) + fn = "%s/%s" % (uploadpath, relpath) + dest = "%s/%s" % (dir, os.path.basename(fn)) safer_move(fn, dest) - os.symlink(dest,fn) + os.symlink(dest, fn) if logs: for key, files in logs.iteritems(): if key: @@ -10992,10 +10992,10 @@ class HostExports(object): logdir = "%s/logs" % dir koji.ensuredir(logdir) for relpath in files: - fn = "%s/%s" % (uploadpath,relpath) - dest = "%s/%s" % (logdir,os.path.basename(fn)) + fn = "%s/%s" % (uploadpath, relpath) + dest = "%s/%s" % (logdir, os.path.basename(fn)) safer_move(fn, dest) - os.symlink(dest,fn) + os.symlink(dest, fn) def moveMavenBuildToScratch(self, task_id, results, rpm_results): "Move a completed Maven scratch build into place (not imported)" @@ -11087,7 +11087,7 @@ class HostExports(object): safer_move(src, dest) os.symlink(dest, src) - def initBuild(self,data): + def initBuild(self, data): """Create a stub build entry. This is done at the very beginning of the build to inform the @@ -11403,7 +11403,7 @@ class HostExports(object): build_notification(task_id, build_id) koji.plugin.run_callbacks('postBuildStateChange', attribute='state', old=buildinfo['state'], new=st_failed, info=buildinfo) - def tagBuild(self,task_id,tag,build,force=False,fromtag=None): + def tagBuild(self, task_id, tag, build, force=False, fromtag=None): """Tag a build (host version) This tags as the user who owns the task @@ -11429,8 +11429,8 @@ class HostExports(object): if not force or 'admin' not in perms: assert_policy('tag', policy_data) if fromtag: - _untag_build(fromtag,build,user_id=user_id,force=force,strict=True) - _tag_build(tag,build,user_id=user_id,force=force) + _untag_build(fromtag, build, user_id=user_id, force=force, strict=True) + _tag_build(tag, build, user_id=user_id, force=force) def importImage(self, task_id, build_id, results): """ @@ -11476,9 +11476,9 @@ class HostExports(object): if task_id is not None: Task(task_id).assertHost(host.id) br = BuildRoot() - return br.new(host.id,repo,arch,task_id=task_id) + return br.new(host.id, repo, arch, task_id=task_id) - def setBuildRootState(self,brootid,state,task_id=None): + def setBuildRootState(self, brootid, state, task_id=None): host = Host() host.verify() if task_id is not None: @@ -11489,7 +11489,7 @@ class HostExports(object): br.assertTask(task_id) return br.setState(state) - def setBuildRootList(self,brootid,rpmlist,task_id=None): + def setBuildRootList(self, brootid, rpmlist, task_id=None): host = Host() host.verify() if task_id is not None: @@ -11500,7 +11500,7 @@ class HostExports(object): br.assertTask(task_id) return br.setList(rpmlist) - def updateBuildRootList(self,brootid,rpmlist,task_id=None): + def updateBuildRootList(self, brootid, rpmlist, task_id=None): host = Host() host.verify() if task_id is not None: @@ -11671,7 +11671,7 @@ class HostExports(object): filepath = "%s/%s" % (uploadpath, path) if not os.path.exists(filepath): raise koji.GenericError, "no such file: %s" % filepath - rpminfo = koji.get_header_fields(filepath, ('arch','sourcepackage')) + rpminfo = koji.get_header_fields(filepath, ('arch', 'sourcepackage')) dirs = [] if not rpminfo['sourcepackage'] and rpminfo['arch'] != 'noarch': arch = koji.canonArch(rpminfo['arch']) @@ -11725,7 +11725,7 @@ class HostExports(object): datadir = "%s/repodata" % archdir koji.ensuredir(datadir) for fn in files: - src = "%s/%s/%s" % (workdir,uploadpath, fn) + src = "%s/%s/%s" % (workdir, uploadpath, fn) dst = "%s/%s" % (datadir, fn) if not os.path.exists(src): raise koji.GenericError, "uploaded file missing: %s" % src @@ -11871,19 +11871,19 @@ def handle_upload(environ): if __name__ == "__main__": # XXX - testing defaults print "Connecting to DB" - koji.db.setDBopts( database = "test", user = "test") + koji.db.setDBopts(database="test", user="test") context.cnx = koji.db.connect() context.req = {} print "Creating a session" - context.session = koji.auth.Session(None,hostip="127.0.0.1") + context.session = koji.auth.Session(None, hostip="127.0.0.1") print context.session test_user = "host/1" pw = "foobar" print "Logging in as %s" % test_user - session_info = context.session.login(test_user,pw,{'hostip':'127.0.0.1'}) + session_info = context.session.login(test_user, pw, {'hostip':'127.0.0.1'}) for k in session_info.keys(): session_info[k] = [session_info[k]] - s2=koji.auth.Session(session_info,'127.0.0.1') + s2 = koji.auth.Session(session_info, '127.0.0.1') print s2 print s2.getHostId() context.session = s2 diff --git a/hub/kojixmlrpc.py b/hub/kojixmlrpc.py index 52591757..9573ffcf 100644 --- a/hub/kojixmlrpc.py +++ b/hub/kojixmlrpc.py @@ -29,7 +29,7 @@ import types import pprint import resource import xmlrpclib -from xmlrpclib import getparser,dumps,Fault +from xmlrpclib import getparser, dumps, Fault from koji.server import WSGIWrapper import koji @@ -69,7 +69,7 @@ class HandlerRegistry(object): self.register_function(self.system_methodHelp, name="system.methodHelp") self.argspec_cache = {} - def register_function(self, function, name = None): + def register_function(self, function, name=None): if name is None: name = function.__name__ self.funcs[name] = function @@ -91,10 +91,10 @@ class HandlerRegistry(object): if not callable(function): continue if prefix is not None: - name = "%s.%s" %(prefix,name) + name = "%s.%s" %(prefix, name) self.register_function(function, name=name) - def register_instance(self,instance): + def register_instance(self, instance): self.register_module(instance) def register_plugin(self, plugin): @@ -135,7 +135,7 @@ class HandlerRegistry(object): def list_api(self): funcs = [] - for name,func in self.funcs.items(): + for name, func in self.funcs.items(): #the keys in self.funcs determine the name of the method as seen over xmlrpc #func.__name__ might differ (e.g. for dotted method names) args = self._getFuncArgs(func) @@ -242,8 +242,8 @@ class ModXMLRPCRequestHandler(object): self.traceback = True # report exception back to server e_class, e = sys.exc_info()[:2] - faultCode = getattr(e_class,'faultCode',1) - tb_type = context.opts.get('KojiTraceback',None) + faultCode = getattr(e_class, 'faultCode', 1) + tb_type = context.opts.get('KojiTraceback', None) tb_str = ''.join(traceback.format_exception(*sys.exc_info())) if issubclass(e_class, koji.GenericError): if context.opts.get('KojiDebug'): @@ -259,7 +259,7 @@ class ModXMLRPCRequestHandler(object): elif tb_type == "extended": faultString = koji.format_exc_plus() else: - faultString = "%s: %s" % (e_class,e) + faultString = "%s: %s" % (e_class, e) self.logger.warning(tb_str) response = dumps(Fault(faultCode, faultString)) @@ -277,7 +277,7 @@ class ModXMLRPCRequestHandler(object): return self._dispatch(method, params) def check_session(self): - if not hasattr(context,"session"): + if not hasattr(context, "session"): #we may be called again by one of our meta-calls (like multiCall) #so we should only create a session if one does not already exist context.session = koji.auth.Session() @@ -285,7 +285,7 @@ class ModXMLRPCRequestHandler(object): context.session.validate() except koji.AuthLockError: #might be ok, depending on method - if context.method not in ('exclusiveSession','login', 'krbLogin', 'logout'): + if context.method not in ('exclusiveSession', 'login', 'krbLogin', 'logout'): raise def enforce_lockout(self): @@ -350,7 +350,7 @@ class ModXMLRPCRequestHandler(object): return results - def handle_request(self,req): + def handle_request(self, req): """Handle a single XML-RPC request""" pass @@ -393,9 +393,9 @@ def load_config(environ): # to aid in the transition from PythonOptions to hub.conf, we only load # the configfile if it is explicitly configured if cf == '/etc/koji-hub/hub.conf': - cfdir = modpy_opts.get('ConfigDir', '/etc/koji-hub/hub.conf.d') + cfdir = modpy_opts.get('ConfigDir', '/etc/koji-hub/hub.conf.d') else: - cfdir = modpy_opts.get('ConfigDir', None) + cfdir = modpy_opts.get('ConfigDir', None) if not cf and not cfdir: logger.warn('Warning: configuring Koji via PythonOptions is deprecated. Use hub.conf') else: @@ -694,10 +694,10 @@ def server_setup(environ): plugins = load_plugins(opts) registry = get_registry(opts, plugins) policy = get_policy(opts, plugins) - koji.db.provideDBopts(database = opts["DBName"], - user = opts["DBUser"], - password = opts.get("DBPass",None), - host = opts.get("DBHost", None)) + koji.db.provideDBopts(database=opts["DBName"], + user=opts["DBUser"], + password=opts.get("DBPass", None), + host=opts.get("DBHost", None)) except Exception: tb_str = ''.join(traceback.format_exception(*sys.exc_info())) logger.error(tb_str) @@ -774,7 +774,7 @@ def application(environ, start_response): time.time() - start) finally: #make sure context gets cleaned up - if hasattr(context,'cnx'): + if hasattr(context, 'cnx'): try: context.cnx.close() except Exception: @@ -789,7 +789,7 @@ def get_registry(opts, plugins): functions = kojihub.RootExports() hostFunctions = kojihub.HostExports() registry.register_instance(functions) - registry.register_module(hostFunctions,"host") + registry.register_module(hostFunctions, "host") registry.register_function(koji.auth.login) registry.register_function(koji.auth.krbLogin) registry.register_function(koji.auth.sslLogin) diff --git a/koji/__init__.py b/koji/__init__.py index 067ffb59..18100428 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -101,33 +101,33 @@ class Enum(dict): Can quickly map forward or reverse """ - def __init__(self,*args): + def __init__(self, *args): self._order = tuple(*args) - super(Enum,self).__init__([(value,n) for n,value in enumerate(self._order)]) + super(Enum, self).__init__([(value, n) for n, value in enumerate(self._order)]) - def __getitem__(self,key): - if isinstance(key,int) or isinstance(key,slice): + def __getitem__(self, key): + if isinstance(key, int) or isinstance(key, slice): return self._order.__getitem__(key) else: - return super(Enum,self).__getitem__(key) + return super(Enum, self).__getitem__(key) - def get(self,key,default=None): + def get(self, key, default=None): try: return self.__getitem__(key) - except (IndexError,KeyError): + except (IndexError, KeyError): return default - def getnum(self,key,default=None): + def getnum(self, key, default=None): try: value = self.__getitem__(key) - except (IndexError,KeyError): + except (IndexError, KeyError): return default - if isinstance(key,int): + if isinstance(key, int): return key else: return value - def _notImplemented(self,*args,**opts): + def _notImplemented(self, *args, **opts): raise NotImplementedError # deprecated @@ -352,12 +352,12 @@ class MultiCallInProgress(object): #A function to get create an exception from a fault def convertFault(fault): """Convert a fault to the corresponding Exception type, if possible""" - code = getattr(fault,'faultCode',None) + code = getattr(fault, 'faultCode', None) if code is None: return fault for v in globals().values(): - if type(v) == type(Exception) and issubclass(v,GenericError) and \ - code == getattr(v,'faultCode',None): + if type(v) == type(Exception) and issubclass(v, GenericError) and \ + code == getattr(v, 'faultCode', None): ret = v(fault.faultString) ret.fromFault = True return ret @@ -373,22 +373,22 @@ def listFaults(): desc: the description of the exception (docstring) """ ret = [] - for n,v in globals().items(): - if type(v) == type(Exception) and issubclass(v,GenericError): - code = getattr(v,'faultCode',None) + for n, v in globals().items(): + if type(v) == type(Exception) and issubclass(v, GenericError): + code = getattr(v, 'faultCode', None) if code is None: continue info = {} info['faultCode'] = code info['name'] = n - info['desc'] = getattr(v,'__doc__',None) + info['desc'] = getattr(v, '__doc__', None) ret.append(info) - ret.sort(lambda a,b: cmp(a['faultCode'],b['faultCode'])) + ret.sort(lambda a, b: cmp(a['faultCode'], b['faultCode'])) return ret #functions for encoding/decoding optional arguments -def encode_args(*args,**opts): +def encode_args(*args, **opts): """The function encodes optional arguments as regular arguments. This is used to allow optional arguments in xmlrpc calls @@ -408,11 +408,11 @@ def decode_args(*args): opts = {} if len(args) > 0: last = args[-1] - if type(last) == dict and last.get('__starstar',False): + if type(last) == dict and last.get('__starstar', False): del last['__starstar'] opts = last args = args[:-1] - return args,opts + return args, opts def decode_args2(args, names, strict=True): "An alternate form of decode_args, returns a dictionary" @@ -492,9 +492,9 @@ def daemonize(): fd0 = os.open('/dev/null', os.O_RDONLY) fd1 = os.open('/dev/null', os.O_RDWR) fd2 = os.open('/dev/null', os.O_RDWR) - os.dup2(fd0,0) - os.dup2(fd1,1) - os.dup2(fd2,2) + os.dup2(fd0, 0) + os.dup2(fd1, 1) + os.dup2(fd2, 2) os.close(fd0) os.close(fd1) os.close(fd2) @@ -539,7 +539,7 @@ def rpm_hdr_size(f, ofs=None): # now read two 4-byte integers which tell us # - # of index entries # - bytes of data in header - data = [ ord(x) for x in fo.read(8) ] + data = [ord(x) for x in fo.read(8)] il = multibyte(data[0:4]) dl = multibyte(data[4:8]) @@ -547,7 +547,7 @@ def rpm_hdr_size(f, ofs=None): hdrsize = 8 + 16 * il + dl # hdrsize rounded up to nearest 8 bytes - hdrsize = hdrsize + ( 8 - ( hdrsize % 8 ) ) % 8 + hdrsize = hdrsize + (8 - (hdrsize % 8)) % 8 # add eight bytes for section header hdrsize = hdrsize + 8 @@ -575,7 +575,7 @@ class RawHeader(object): # read two 4-byte integers which tell us # - # of index entries (each 16 bytes long) # - bytes of data in header - data = [ ord(x) for x in self.header[8:12] ] + data = [ord(x) for x in self.header[8:12]] il = multibyte(data[:4]) dl = multibyte(data[4:8]) @@ -585,7 +585,7 @@ class RawHeader(object): entry = [] for j in xrange(4): ofs = 16 + i*16 + j*4 - data = [ ord(x) for x in self.header[ofs:ofs+4] ] + data = [ord(x) for x in self.header[ofs:ofs+4]] entry.append(multibyte(data)) #print "Tag: %d, Type: %d, Offset: %x, Count: %d" % tuple(entry) index[entry[0]] = entry @@ -599,7 +599,7 @@ class RawHeader(object): store = 16 + il * 16 #print "start is: %d" % start #print "index length: %d" % il - print "Store at offset %d (%0x)" % (store,store) + print "Store at offset %d (%0x)" % (store, store) #sort entries by offset, dtype #also rearrange: tag, dtype, offset, count -> offset, dtype, tag, count order = [(x[2], x[1], x[0], x[3]) for x in self.index.itervalues()] @@ -637,7 +637,7 @@ class RawHeader(object): #integer n = 1 << (dtype - 2) for i in xrange(count): - data = [ ord(x) for x in self.header[pos:pos+n] ] + data = [ord(x) for x in self.header[pos:pos+n]] print "%r" % data num = multibyte(data) print "Int(%d): %d" % (n, num) @@ -690,7 +690,7 @@ class RawHeader(object): if dtype >= 2 and dtype <= 5: n = 1 << (dtype - 2) # n-byte integer - data = [ ord(x) for x in self.header[pos:pos+n] ] + data = [ord(x) for x in self.header[pos:pos+n]] return multibyte(data) elif dtype == 6: # string (null terminated) @@ -743,7 +743,7 @@ def __parse_packet_header(pgp_packet): offset = 1 length = len(pgp_packet) - offset else: - (fmt, offset) = { 0:('>B', 2), 1:('>H', 3), 2:('>I', 5) }[len_type] + (fmt, offset) = {0:('>B', 2), 1:('>H', 3), 2:('>I', 5)}[len_type] length = struct.unpack(fmt, pgp_packet[1:offset])[0] else: tag = byte0 & 0x3F @@ -852,14 +852,14 @@ def get_rpm_header(f, ts=None): fo.close() return hdr -def get_header_field(hdr,name): +def get_header_field(hdr, name): """Extract named field from an rpm header""" - idx = getattr(rpm,"RPMTAG_%s" % name.upper(),None) + idx = getattr(rpm, "RPMTAG_%s" % name.upper(), None) if idx is None: raise GenericError, "No such rpm header field: %s" % name return hdr[idx] -def get_header_fields(X,fields): +def get_header_fields(X, fields): """Extract named fields from an rpm header and return as a dictionary X may be either the rpm header or the rpm filename @@ -870,16 +870,16 @@ def get_header_fields(X,fields): hdr = X ret = {} for f in fields: - ret[f] = get_header_field(hdr,f) + ret[f] = get_header_field(hdr, f) return ret def parse_NVR(nvr): """split N-V-R into dictionary of data""" ret = {} - p2 = nvr.rfind("-",0) + p2 = nvr.rfind("-", 0) if p2 == -1 or p2 == len(nvr) - 1: raise GenericError("invalid format: %s" % nvr) - p1 = nvr.rfind("-",0,p2) + p1 = nvr.rfind("-", 0, p2) if p1 == -1 or p1 == p2 - 1: raise GenericError("invalid format: %s" % nvr) ret['release'] = nvr[p2+1:] @@ -927,23 +927,23 @@ def canonArch(arch): """Given an arch, return the "canonical" arch""" #XXX - this could stand to be smarter, and we should probably # have some other related arch-mangling functions. - if fnmatch(arch,'i?86') or arch == 'athlon': + if fnmatch(arch, 'i?86') or arch == 'athlon': return 'i386' elif arch == 'ia32e': return 'x86_64' - elif fnmatch(arch,'ppc64le'): + elif fnmatch(arch, 'ppc64le'): return 'ppc64le' - elif fnmatch(arch,'ppc64*'): + elif fnmatch(arch, 'ppc64*'): return 'ppc64' - elif fnmatch(arch,'sparc64*'): + elif fnmatch(arch, 'sparc64*'): return 'sparc64' - elif fnmatch(arch,'sparc*'): + elif fnmatch(arch, 'sparc*'): return 'sparc' elif fnmatch(arch, 'alpha*'): return 'alpha' - elif fnmatch(arch,'arm*h*'): + elif fnmatch(arch, 'arm*h*'): return 'armhfp' - elif fnmatch(arch,'arm*'): + elif fnmatch(arch, 'arm*'): return 'arm' else: return arch @@ -1058,13 +1058,13 @@ def mavenLabel(maveninfo): def hex_string(s): """Converts a string to a string of hex digits""" - return ''.join([ '%02x' % ord(x) for x in s ]) + return ''.join(['%02x' % ord(x) for x in s]) -def make_groups_spec(grplist,name='buildsys-build',buildgroup=None): +def make_groups_spec(grplist, name='buildsys-build', buildgroup=None): """Return specfile contents representing the group""" if buildgroup is None: - buildgroup=name + buildgroup = name data = [ """# # This specfile represents buildgroups for mock @@ -1087,7 +1087,7 @@ BuildArch: noarch seen_grp = {} seen_pkg = {} #index groups - groups = dict([(g['name'],g) for g in grplist]) + groups = dict([(g['name'], g) for g in grplist]) for group_name in need: if seen_grp.has_key(group_name): continue @@ -1098,7 +1098,7 @@ BuildArch: noarch continue data.append("#Group: %s\n" % group_name) pkglist = list(group['packagelist']) - pkglist.sort(lambda a,b: cmp(a['package'], b['package'])) + pkglist.sort(lambda a, b: cmp(a['package'], b['package'])) for pkg in pkglist: pkg_name = pkg['package'] if seen_pkg.has_key(pkg_name): @@ -1137,10 +1137,10 @@ def generate_comps(groups, expand_groups=False): -""" ] +"""] groups = list(groups) - group_idx = dict([(g['name'],g) for g in groups]) - groups.sort(lambda a,b:cmp(a['name'],b['name'])) + group_idx = dict([(g['name'], g) for g in groups]) + groups.sort(lambda a, b: cmp(a['name'], b['name'])) for g in groups: group_id = g['name'] name = g['display_name'] @@ -1167,7 +1167,7 @@ def generate_comps(groups, expand_groups=False): """ """) grouplist = list(g['grouplist']) - grouplist.sort(lambda a,b:cmp(a['name'],b['name'])) + grouplist.sort(lambda a, b: cmp(a['name'], b['name'])) for x in grouplist: #['req_id','type','is_metapkg','name'] name = x['name'] @@ -1203,7 +1203,7 @@ def generate_comps(groups, expand_groups=False): """) if g['packagelist']: packagelist = list(g['packagelist']) - packagelist.sort(lambda a,b:cmp(a['package'],b['package'])) + packagelist.sort(lambda a, b: cmp(a['package'], b['package'])) for p in packagelist: data.append( """ %s @@ -1212,7 +1212,7 @@ def generate_comps(groups, expand_groups=False): if expand_groups and g['grouplist']: #add a requires entry for all packages in groups required by buildgroup need = [req['name'] for req in g['grouplist']] - seen_grp = { g['name'] : 1} + seen_grp = {g['name'] : 1} seen_pkg = {} for p in g['packagelist']: seen_pkg[p['package']] = 1 @@ -1230,7 +1230,7 @@ def generate_comps(groups, expand_groups=False): """ """ % group_name) pkglist = list(group['packagelist']) - pkglist.sort(lambda a,b: cmp(a['package'], b['package'])) + pkglist.sort(lambda a, b: cmp(a['package'], b['package'])) for pkg in pkglist: pkg_name = pkg['package'] if seen_pkg.has_key(pkg_name): @@ -1278,11 +1278,11 @@ def genMockConfig(name, arch, managed=False, repoid=None, tag_name=None, **opts) if topurls: #XXX - PathInfo isn't quite right for this, but it will do for now pathinfos = [PathInfo(topdir=_u) for _u in topurls] - urls = ["%s/%s" % (_p.repo(repoid,tag_name), arch) for _p in pathinfos] + urls = ["%s/%s" % (_p.repo(repoid, tag_name), arch) for _p in pathinfos] else: pathinfo = PathInfo(topdir=opts.get('topdir', '/mnt/koji')) - repodir = pathinfo.repo(repoid,tag_name) - urls = ["file://%s/%s" % (repodir,arch)] + repodir = pathinfo.repo(repoid, tag_name) + urls = ["file://%s/%s" % (repodir, arch)] if managed: buildroot_id = opts.get('buildroot_id') @@ -1639,7 +1639,7 @@ class PathInfo(object): #else return self.topdir + ("/vol/%s" % volume) - def build(self,build): + def build(self, build): """Return the directory where a build belongs""" return self.volumedir(build.get('volume_name')) + ("/packages/%(name)s/%(version)s/%(release)s" % build) @@ -1674,7 +1674,7 @@ class PathInfo(object): """Return the directory where the image for the build are stored""" return self.build(build) + '/images' - def rpm(self,rpminfo): + def rpm(self, rpminfo): """Return the path (relative to build_dir) where an rpm belongs""" return "%(arch)s/%(name)s-%(version)s-%(release)s.%(arch)s.rpm" % rpminfo @@ -1690,11 +1690,11 @@ class PathInfo(object): """Return the path for build logs""" return "%s/data/logs" % self.build(build) - def repo(self,repo_id,tag_str): + def repo(self, repo_id, tag_str): """Return the directory where a repo belongs""" return self.topdir + ("/repos/%(tag_str)s/%(repo_id)s" % locals()) - def repocache(self,tag_str): + def repocache(self, tag_str): """Return the directory where a repo belongs""" return self.topdir + ("/repos/%(tag_str)s/cache" % locals()) @@ -1733,7 +1733,7 @@ class VirtualMethod(object): def __getattr__(self, name): return type(self)(self.__func, "%s.%s" % (self.__name, name)) def __call__(self, *args, **opts): - return self.__func(self.__name,args,opts) + return self.__func(self.__name, args, opts) class ClientSession(object): @@ -1783,7 +1783,7 @@ class ClientSession(object): # set a default 12 hour connection timeout. # Some Koji operations can take a long time to return, but after 12 # hours we can assume something is seriously wrong. - timeout = self.opts.setdefault('timeout', 60 * 60 * 12) + timeout = self.opts.setdefault('timeout', 60 * 60 * 12) self._timeout_compat = False if timeout: if sys.version_info[:3] < (2, 6, 0) and 'ssl_context' not in cnxOpts: @@ -1795,7 +1795,7 @@ class ClientSession(object): self._cnxClass = cnxClass self._close_connection() - def setSession(self,sinfo): + def setSession(self, sinfo): """Set the session info If sinfo is None, logout.""" @@ -1810,8 +1810,8 @@ class ClientSession(object): self.callnum = 0 self.sinfo = sinfo - def login(self,opts=None): - sinfo = self.callMethod('login',self.opts['user'], self.opts['password'],opts) + def login(self, opts=None): + sinfo = self.callMethod('login', self.opts['user'], self.opts['password'], opts) if not sinfo: return False self.setSession(sinfo) @@ -1821,7 +1821,7 @@ class ClientSession(object): def subsession(self): "Create a subsession" sinfo = self.callMethod('subsession') - return type(self)(self.baseurl,self.opts,sinfo) + return type(self)(self.baseurl, self.opts, sinfo) def krb_login(self, principal=None, keytab=None, ccache=None, proxyuser=None): """Log in using Kerberos. If principal is not None and keytab is @@ -1974,7 +1974,7 @@ class ClientSession(object): except: pass - def callMethod(self,name,*args,**opts): + def callMethod(self, name, *args, **opts): """compatibility wrapper for _callMethod""" return self._callMethod(name, args, opts) @@ -1984,7 +1984,7 @@ class ClientSession(object): kwargs = {} if name == 'rawUpload': return self._prepUpload(*args, **kwargs) - args = encode_args(*args,**kwargs) + args = encode_args(*args, **kwargs) if self.logged_in: sinfo = self.sinfo.copy() sinfo['callnum'] = self.callnum @@ -2089,9 +2089,9 @@ class ClientSession(object): handler, headers, request = self._prepCall(name, args, kwargs) tries = 0 self.retries = 0 - debug = self.opts.get('debug',False) - max_retries = self.opts.get('max_retries',30) - interval = self.opts.get('retry_interval',20) + debug = self.opts.get('debug', False) + max_retries = self.opts.get('max_retries', 30) + interval = self.opts.get('retry_interval', 20) while True: tries += 1 self.retries += 1 @@ -2107,7 +2107,7 @@ class ClientSession(object): #try to convert the fault to a known exception err = convertFault(fault) if isinstance(err, ServerOffline): - if self.opts.get('offline_retry',False): + if self.opts.get('offline_retry', False): secs = self.opts.get('offline_retry_interval', interval) self.logger.debug("Server offline. Retrying in %i seconds", secs) time.sleep(secs) @@ -2130,7 +2130,7 @@ class ClientSession(object): if not self.logged_in: #in the past, non-logged-in sessions did not retry. For compatibility purposes #this behavior is governed by the anon_retry opt. - if not self.opts.get('anon_retry',False): + if not self.opts.get('anon_retry', False): raise if tries > max_retries: raise @@ -2174,10 +2174,10 @@ class ClientSession(object): raise err return ret - def __getattr__(self,name): + def __getattr__(self, name): #if name[:1] == '_': # raise AttributeError, "no attribute %r" % name - return VirtualMethod(self._callMethod,name) + return VirtualMethod(self._callMethod, name) def fastUpload(self, localfile, path, name=None, callback=None, blocksize=None, overwrite=False): if blocksize is None: @@ -2278,14 +2278,14 @@ class ClientSession(object): self.fastUpload(localfile, path, name, callback, blocksize, overwrite) return - start=time.time() + start = time.time() # XXX - stick in a config or something - retries=3 + retries = 3 fo = file(localfile, "r") #specify bufsize? totalsize = os.path.getsize(localfile) ofs = 0 md5sum = md5_constructor() - debug = self.opts.get('debug',False) + debug = self.opts.get('debug', False) if callback: callback(0, totalsize, 0, 0, 0) while True: @@ -2307,7 +2307,7 @@ class ClientSession(object): tries = 0 while True: if debug: - self.logger.debug("uploadFile(%r,%r,%r,%r,%r,...)" %(path,name,sz,digest,offset)) + self.logger.debug("uploadFile(%r,%r,%r,%r,%r,...)" %(path, name, sz, digest, offset)) if self.callMethod('uploadFile', path, name, encode_int(sz), digest, encode_int(offset), data): break if tries <= retries: @@ -2326,9 +2326,9 @@ class ClientSession(object): if t2 <= 0: t2 = 1 if debug: - self.logger.debug("Uploaded %d bytes in %f seconds (%f kbytes/sec)" % (size,t1,size/t1/1024)) + self.logger.debug("Uploaded %d bytes in %f seconds (%f kbytes/sec)" % (size, t1, size/t1/1024)) if debug: - self.logger.debug("Total: %d bytes in %f seconds (%f kbytes/sec)" % (ofs,t2,ofs/t2/1024)) + self.logger.debug("Total: %d bytes in %f seconds (%f kbytes/sec)" % (ofs, t2, ofs/t2/1024)) if callback: callback(ofs, totalsize, size, t1, t2) fo.close() @@ -2359,7 +2359,7 @@ class DBHandler(logging.Handler): self.cnx = cnx self.table = table if mapping is None: - self.mapping = { 'message': '%(message)s' } + self.mapping = {'message': '%(message)s'} else: self.mapping = mapping @@ -2391,7 +2391,7 @@ class DBHandler(logging.Handler): values = ",".join(values) command = "INSERT INTO %s (%s) VALUES (%s)" % (self.table, columns, values) #note we're letting cursor.execute do the escaping - cursor.execute(command,data) + cursor.execute(command, data) cursor.close() #self.cnx.commit() #XXX - commiting here is most likely wrong, but we need to set commit_pending or something @@ -2405,7 +2405,7 @@ TIMESTAMP_RE = re.compile("(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)") def parse_timestamp(ts): """Parse a timestamp returned from a query""" m = TIMESTAMP_RE.search(ts) - t = tuple([int(x) for x in m.groups()]) + (0,0,0) + t = tuple([int(x) for x in m.groups()]) + (0, 0, 0) return time.mktime(t) def formatTime(value): @@ -2609,7 +2609,7 @@ def add_file_logger(logger, fn): return if not os.path.isfile(fn): return - if not os.access(fn,os.W_OK): + if not os.access(fn, os.W_OK): return handler = logging.handlers.RotatingFileHandler(fn, maxBytes=1024*1024*10, backupCount=5) handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(name)s: %(message)s')) diff --git a/koji/auth.py b/koji/auth.py index 710f3477..3dbe1ccc 100644 --- a/koji/auth.py +++ b/koji/auth.py @@ -51,7 +51,7 @@ RetryWhitelist = [ class Session(object): - def __init__(self,args=None,hostip=None): + def __init__(self, args=None, hostip=None): self.logged_in = False self.id = None self.master = None @@ -66,12 +66,12 @@ class Session(object): self.callnum = None #get session data from request if args is None: - environ = getattr(context,'environ',{}) - args = environ.get('QUERY_STRING','') + environ = getattr(context, 'environ', {}) + args = environ.get('QUERY_STRING', '') if not args: self.message = 'no session args' return - args = cgi.parse_qs(args,strict_parsing=True) + args = cgi.parse_qs(args, strict_parsing=True) if hostip is None: hostip = context.environ['REMOTE_ADDR'] #XXX - REMOTE_ADDR not promised by wsgi spec @@ -108,7 +108,7 @@ class Session(object): AND hostip = %%(hostip)s FOR UPDATE """ % ",".join(fields) - c.execute(q,locals()) + c.execute(q, locals()) row = c.fetchone() if not row: raise koji.AuthError, 'Invalid session or bad credentials' @@ -120,13 +120,13 @@ class Session(object): if callnum is not None: try: callnum = int(callnum) - except (ValueError,TypeError): + except (ValueError, TypeError): raise koji.AuthError, "Invalid callnum: %r" % callnum lastcall = session_data['callnum'] if lastcall is not None: if lastcall > callnum: raise koji.SequenceError, "%d > %d (session %d)" \ - % (lastcall,callnum,id) + % (lastcall, callnum, id) elif lastcall == callnum: #Some explanation: #This function is one of the few that performs its own commit. @@ -147,10 +147,10 @@ class Session(object): # we used to get a row lock here as an attempt to maintain sanity of exclusive # sessions, but it was an imperfect approach and the lock could cause some # performance issues. - fields = ('name','status','usertype') + fields = ('name', 'status', 'usertype') q = """SELECT %s FROM users WHERE id=%%(user_id)s""" % ','.join(fields) - c.execute(q,session_data) - user_data = dict(zip(fields,c.fetchone())) + c.execute(q, session_data) + user_data = dict(zip(fields, c.fetchone())) if user_data['status'] != koji.USER_STATUS['NORMAL']: raise koji.AuthError, 'logins by %s are not allowed' % user_data['name'] @@ -163,7 +163,7 @@ class Session(object): q = """SELECT id FROM sessions WHERE user_id=%(user_id)s AND "exclusive" = TRUE AND expired = FALSE""" #should not return multiple rows (unique constraint) - c.execute(q,session_data) + c.execute(q, session_data) row = c.fetchone() if row: (excl_id,) = row @@ -180,7 +180,7 @@ class Session(object): # update timestamp q = """UPDATE sessions SET update_time=NOW() WHERE id = %(id)i""" - c.execute(q,locals()) + c.execute(q, locals()) #save update time context.cnx.commit() @@ -188,7 +188,7 @@ class Session(object): #see earlier note near RetryError if callnum is not None: q = """UPDATE sessions SET callnum=%(callnum)i WHERE id = %(id)i""" - c.execute(q,locals()) + c.execute(q, locals()) # record the login data self.id = id @@ -211,7 +211,7 @@ class Session(object): if name == 'perms': if self._perms is None: #in a dict for quicker lookup - self._perms = dict([[name,1] for name in get_user_perms(self.user_id)]) + self._perms = dict([[name, 1] for name in get_user_perms(self.user_id)]) return self._perms elif name == 'groups': if self._groups is None: @@ -252,11 +252,11 @@ class Session(object): if status != koji.USER_STATUS['NORMAL']: raise koji.AuthError, 'logins by %s are not allowed' % name - def login(self,user,password,opts=None): + def login(self, user, password, opts=None): """create a login session""" if opts is None: opts = {} - if not isinstance(password,str) or len(password) == 0: + if not isinstance(password, str) or len(password) == 0: raise koji.AuthError, 'invalid username or password' if self.logged_in: raise koji.GenericError, "Already logged in" @@ -271,7 +271,7 @@ class Session(object): c = context.cnx.cursor() q = """SELECT id FROM users WHERE name = %(user)s AND password = %(password)s""" - c.execute(q,locals()) + c.execute(q, locals()) r = c.fetchone() if not r: raise koji.AuthError, 'invalid username or password' @@ -419,7 +419,7 @@ class Session(object): sinfo = self.createSession(user_id, hostip, koji.AUTHTYPE_SSL) return sinfo - def makeExclusive(self,force=False): + def makeExclusive(self, force=False): """Make this session exclusive""" c = context.cnx.cursor() if self.master is not None: @@ -431,24 +431,24 @@ class Session(object): session_id = self.id #acquire a row lock on the user entry q = """SELECT id FROM users WHERE id=%(user_id)s FOR UPDATE""" - c.execute(q,locals()) + c.execute(q, locals()) # check that no other sessions for this user are exclusive q = """SELECT id FROM sessions WHERE user_id=%(user_id)s AND expired = FALSE AND "exclusive" = TRUE FOR UPDATE""" - c.execute(q,locals()) + c.execute(q, locals()) row = c.fetchone() if row: if force: #expire the previous exclusive session and try again (excl_id,) = row q = """UPDATE sessions SET expired=TRUE,"exclusive"=NULL WHERE id=%(excl_id)s""" - c.execute(q,locals()) + c.execute(q, locals()) else: raise koji.AuthLockError, "Cannot get exclusive session" #mark this session exclusive q = """UPDATE sessions SET "exclusive"=TRUE WHERE id=%(session_id)s""" - c.execute(q,locals()) + c.execute(q, locals()) context.cnx.commit() def makeShared(self): @@ -456,7 +456,7 @@ class Session(object): c = context.cnx.cursor() session_id = self.id q = """UPDATE sessions SET "exclusive"=NULL WHERE id=%(session_id)s""" - c.execute(q,locals()) + c.execute(q, locals()) context.cnx.commit() def logout(self): @@ -497,7 +497,7 @@ class Session(object): # generate a random key alnum = string.ascii_letters + string.digits key = "%s-%s" %(user_id, - ''.join([ random.choice(alnum) for x in range(1,20) ])) + ''.join([random.choice(alnum) for x in range(1, 20)])) # use sha? sha.new(phrase).hexdigest() # get a session id @@ -510,7 +510,7 @@ class Session(object): INSERT INTO sessions (id, user_id, key, hostip, authtype, master) VALUES (%(session_id)i, %(user_id)i, %(key)s, %(hostip)s, %(authtype)i, %(master)s) """ - c.execute(q,locals()) + c.execute(q, locals()) context.cnx.commit() #return session info @@ -522,7 +522,7 @@ class Session(object): raise koji.AuthError, "Not logged in" master = self.master if master is None: - master=self.id + master = self.id return self.createSession(self.user_id, self.hostip, self.authtype, master=master) @@ -553,7 +553,7 @@ class Session(object): def isUser(self, user_id): if not self.logged_in: return False - return ( self.user_id == user_id or self.hasGroup(user_id) ) + return (self.user_id == user_id or self.hasGroup(user_id)) def assertUser(self, user_id): if not self.isUser(user_id) and not self.hasPerm('admin'): @@ -563,10 +563,10 @@ class Session(object): '''Using session data, find host id (if there is one)''' if self.user_id is None: return None - c=context.cnx.cursor() - q="""SELECT id FROM host WHERE user_id = %(uid)d""" - c.execute(q,{'uid' : self.user_id }) - r=c.fetchone() + c = context.cnx.cursor() + q = """SELECT id FROM host WHERE user_id = %(uid)d""" + c.execute(q, {'uid' : self.user_id}) + r = c.fetchone() c.close() if r: return r[0] @@ -582,7 +582,7 @@ class Session(object): If no user with the given princpal if found, return None.""" c = context.cnx.cursor() q = """SELECT id FROM users WHERE krb_principal = %(krb_principal)s""" - c.execute(q,locals()) + c.execute(q, locals()) r = c.fetchone() c.close() if r: @@ -647,7 +647,7 @@ class Session(object): c = context.cnx.cursor() q = """SELECT krb_principal FROM users WHERE name = %(user_name)s""" - c.execute(q,locals()) + c.execute(q, locals()) r = c.fetchone() if not r: return self.createUser(user_name, krb_principal=krb_principal) @@ -668,7 +668,7 @@ def get_user_groups(user_id): FROM user_groups JOIN users ON group_id = users.id WHERE active = TRUE AND users.usertype=%(t_group)i AND user_id=%(user_id)i""" - c.execute(q,locals()) + c.execute(q, locals()) return dict(c.fetchall()) def get_user_perms(user_id): @@ -676,22 +676,22 @@ def get_user_perms(user_id): q = """SELECT name FROM user_perms JOIN permissions ON perm_id = permissions.id WHERE active = TRUE AND user_id=%(user_id)s""" - c.execute(q,locals()) + c.execute(q, locals()) #return a list of permissions by name return [row[0] for row in c.fetchall()] def get_user_data(user_id): c = context.cnx.cursor() - fields = ('name','status','usertype') + fields = ('name', 'status', 'usertype') q = """SELECT %s FROM users WHERE id=%%(user_id)s""" % ','.join(fields) - c.execute(q,locals()) + c.execute(q, locals()) row = c.fetchone() if not row: return None - return dict(zip(fields,row)) + return dict(zip(fields, row)) -def login(*args,**opts): - return context.session.login(*args,**opts) +def login(*args, **opts): + return context.session.login(*args, **opts) def krbLogin(*args, **opts): return context.session.krbLogin(*args, **opts) @@ -708,9 +708,9 @@ def subsession(): def logoutChild(session_id): return context.session.logoutChild(session_id) -def exclusiveSession(*args,**opts): +def exclusiveSession(*args, **opts): """Make this session exclusive""" - return context.session.makeExclusive(*args,**opts) + return context.session.makeExclusive(*args, **opts) def sharedSession(): """Drop out of exclusive mode""" @@ -720,18 +720,18 @@ def sharedSession(): if __name__ == '__main__': # XXX - testing defaults import db - db.setDBopts( database = "test", user = "test") + db.setDBopts(database="test", user="test") print "Connecting to db" context.cnx = db.connect() print "starting session 1" - sess = Session(None,hostip='127.0.0.1') + sess = Session(None, hostip='127.0.0.1') print "Session 1: %s" % sess print "logging in with session 1" - session_info = sess.login('host/1','foobar',{'hostip':'127.0.0.1'}) + session_info = sess.login('host/1', 'foobar', {'hostip':'127.0.0.1'}) #wrap values in lists - session_info = dict([ [k,[v]] for k,v in session_info.iteritems()]) + session_info = dict([[k, [v]] for k, v in session_info.iteritems()]) print "Session 1: %s" % sess print "Session 1 info: %r" % session_info print "Creating session 2" - s2 = Session(session_info,'127.0.0.1') + s2 = Session(session_info, '127.0.0.1') print "Session 2: %s " % s2 diff --git a/koji/context.py b/koji/context.py index b05e3a3c..df93c35c 100755 --- a/koji/context.py +++ b/koji/context.py @@ -48,7 +48,7 @@ class ThreadLocal(object): if not tdict.has_key(id): tdict[id] = _data() data = tdict[id] - return object.__setattr__(data,key,value) + return object.__setattr__(data, key, value) def __delattr__(self, key): id = thread.get_ident() @@ -65,7 +65,7 @@ class ThreadLocal(object): id = thread.get_ident() tdict = object.__getattribute__(self, '_tdict') return "(current thread: %s) {" % id + \ - ", ".join([ "%s : %s" %(k,v.__dict__) for (k,v) in tdict.iteritems() ]) + \ + ", ".join(["%s : %s" %(k, v.__dict__) for (k, v) in tdict.iteritems()]) + \ "}" def _threadclear(self): @@ -92,13 +92,13 @@ if __name__ == '__main__': import random import time def test(): - context.foo=random.random() + context.foo = random.random() time.sleep(1.5+random.random()) context._threadclear() print context - for x in xrange(1,10): - thread.start_new_thread(test,()) + for x in xrange(1, 10): + thread.start_new_thread(test, ()) time.sleep(4) print @@ -106,7 +106,7 @@ if __name__ == '__main__': context.foo = 1 context.bar = 2 - print context.foo,context.bar + print context.foo, context.bar print context context._threadclear() print context diff --git a/koji/daemon.py b/koji/daemon.py index 0570faa5..a53b48d3 100644 --- a/koji/daemon.py +++ b/koji/daemon.py @@ -163,12 +163,12 @@ def log_output(session, path, args, outfile, uploadpath, cwd=None, logerror=0, a class SCM(object): "SCM abstraction class" - types = { 'CVS': ('cvs://',), - 'CVS+SSH': ('cvs+ssh://',), - 'GIT': ('git://', 'git+http://', 'git+https://', 'git+rsync://'), - 'GIT+SSH': ('git+ssh://',), - 'SVN': ('svn://', 'svn+http://', 'svn+https://'), - 'SVN+SSH': ('svn+ssh://',) } + types = {'CVS': ('cvs://',), + 'CVS+SSH': ('cvs+ssh://',), + 'GIT': ('git://', 'git+http://', 'git+https://', 'git+rsync://'), + 'GIT+SSH': ('git+ssh://',), + 'SVN': ('svn://', 'svn+http://', 'svn+https://'), + 'SVN+SSH': ('svn+ssh://',)} def is_scm_url(url): """ @@ -265,15 +265,15 @@ class SCM(object): query = query[:-1] # check for validity: params should be empty, query may be empty, everything else should be populated - if params : + if params: raise koji.GenericError, 'Unable to parse SCM URL: %s . Params element %s should be empty.' % (self.url, params) - if not scheme : + if not scheme: raise koji.GenericError, 'Unable to parse SCM URL: %s . Could not find the scheme element.' % self.url - if not netloc : + if not netloc: raise koji.GenericError, 'Unable to parse SCM URL: %s . Could not find the netloc element.' % self.url - if not path : + if not path: raise koji.GenericError, 'Unable to parse SCM URL: %s . Could not find the path element.' % self.url - if not fragment : + if not fragment: raise koji.GenericError, 'Unable to parse SCM URL: %s . Could not find the fragment element.' % self.url # return parsed values @@ -445,8 +445,8 @@ class SCM(object): # Currently only required for GIT checkouts # Run the command in the directory the source was checked out into if self.scmtype.startswith('GIT') and globals().get('KOJIKAMID'): - _run(['git', 'config', 'core.autocrlf', 'true'], chdir=update_checkout_dir, fatal=True) - _run(['git', 'config', 'core.safecrlf', 'true'], chdir=update_checkout_dir, fatal=True) + _run(['git', 'config', 'core.autocrlf', 'true'], chdir=update_checkout_dir, fatal=True) + _run(['git', 'config', 'core.safecrlf', 'true'], chdir=update_checkout_dir, fatal=True) _run(update_checkout_cmd, chdir=update_checkout_dir, fatal=True) if self.use_common and not globals().get('KOJIKAMID'): @@ -484,7 +484,7 @@ class TaskManager(object): def findHandlers(self, vars): """Find and index task handlers""" for v in vars.values(): - if type(v) == type(koji.tasks.BaseTaskHandler) and issubclass(v,koji.tasks.BaseTaskHandler): + if type(v) == type(koji.tasks.BaseTaskHandler) and issubclass(v, koji.tasks.BaseTaskHandler): for method in v.Methods: self.handlers[method] = v @@ -497,7 +497,7 @@ class TaskManager(object): for task_id in self.pids.keys(): self.cleanupTask(task_id) self.session.host.freeTasks(self.tasks.keys()) - self.session.host.updateHost(task_load=0.0,ready=False) + self.session.host.updateHost(task_load=0.0, ready=False) def updateBuildroots(self, nolocal=False): """Handle buildroot cleanup/maintenance @@ -511,10 +511,10 @@ class TaskManager(object): If nolocal is True, do not try to scan local buildroots. """ #query buildroots in db that are not expired - states = [ koji.BR_STATES[x] for x in ('INIT','WAITING','BUILDING') ] - db_br = self.session.listBuildroots(hostID=self.host_id,state=tuple(states)) + states = [koji.BR_STATES[x] for x in ('INIT', 'WAITING', 'BUILDING')] + db_br = self.session.listBuildroots(hostID=self.host_id, state=tuple(states)) # index by id - db_br = dict([(row['id'],row) for row in db_br]) + db_br = dict([(row['id'], row) for row in db_br]) st_expired = koji.BR_STATES['EXPIRED'] for id, br in db_br.items(): task_id = br['task_id'] @@ -522,13 +522,13 @@ class TaskManager(object): # not associated with a task # this makes no sense now, but may in the future self.logger.warn("Expiring taskless buildroot: %(id)i/%(tag_name)s/%(arch)s" % br) - self.session.host.setBuildRootState(id,st_expired) + self.session.host.setBuildRootState(id, st_expired) elif not self.tasks.has_key(task_id): #task not running - expire the buildroot #TODO - consider recycling hooks here (with strong sanity checks) self.logger.info("Expiring buildroot: %(id)i/%(tag_name)s/%(arch)s" % br) - self.logger.debug("Buildroot task: %r, Current tasks: %r" % (task_id,self.tasks.keys())) - self.session.host.setBuildRootState(id,st_expired) + self.logger.debug("Buildroot task: %r, Current tasks: %r" % (task_id, self.tasks.keys())) + self.session.host.setBuildRootState(id, st_expired) continue if nolocal: return @@ -544,8 +544,8 @@ class TaskManager(object): if task_id: tasks.append(task_id) #index - missed_br = dict([(row['id'],row) for row in missed_br]) - tasks = dict([(row['id'],row) for row in self.session.getTaskInfo(tasks)]) + missed_br = dict([(row['id'], row) for row in missed_br]) + tasks = dict([(row['id'], row) for row in self.session.getTaskInfo(tasks)]) for id in local_only: # Cleaning options # - wait til later @@ -611,13 +611,13 @@ class TaskManager(object): if flist: self.logger.info("%s: clearing rootdir" % desc) for fn in flist: - safe_rmtree("%s/%s" % (rootdir,fn), unmount=True, strict=False) + safe_rmtree("%s/%s" % (rootdir, fn), unmount=True, strict=False) resultdir = "%s/result" % topdir if os.path.isdir(resultdir): self.logger.info("%s: clearing resultdir" % desc) safe_rmtree(resultdir, unmount=True, strict=False) else: - self.logger.debug("Recent buildroot: %s: %i seconds" % (desc,age)) + self.logger.debug("Recent buildroot: %s: %i seconds" % (desc, age)) self.logger.debug("Local buildroots: %d" % len(local_br)) self.logger.debug("Active buildroots: %d" % len(db_br)) self.logger.debug("Expired/stray buildroots: %d" % len(local_only)) @@ -629,10 +629,10 @@ class TaskManager(object): for f in os.listdir(configdir): if not f.endswith('.cfg'): continue - fn = "%s/%s" % (configdir,f) + fn = "%s/%s" % (configdir, f) if not os.path.isfile(fn): continue - fo = file(fn,'r') + fo = file(fn, 'r') id = None name = None for n in xrange(10): @@ -687,10 +687,10 @@ class TaskManager(object): stale.append(id) continue tasks[id] = task - if task.get('alert',False): + if task.get('alert', False): #wake up the process self.logger.info("Waking up task: %r" % task) - os.kill(self.pids[id],signal.SIGUSR2) + os.kill(self.pids[id], signal.SIGUSR2) if not task['waiting']: task_load += task['weight'] self.logger.debug("Task Load: %s" % task_load) @@ -719,21 +719,21 @@ class TaskManager(object): # - task is forcibly reassigned/unassigned tinfo = self.session.getTaskInfo(id) if tinfo is None: - raise koji.GenericError, "Invalid task %r (pid %r)" % (id,pid) + raise koji.GenericError, "Invalid task %r (pid %r)" % (id, pid) elif tinfo['state'] == koji.TASK_STATES['CANCELED']: - self.logger.info("Killing canceled task %r (pid %r)" % (id,pid)) + self.logger.info("Killing canceled task %r (pid %r)" % (id, pid)) if self.cleanupTask(id): del self.pids[id] elif tinfo['host_id'] != self.host_id: - self.logger.info("Killing reassigned task %r (pid %r)" % (id,pid)) + self.logger.info("Killing reassigned task %r (pid %r)" % (id, pid)) if self.cleanupTask(id): del self.pids[id] else: - self.logger.info("Lingering task %r (pid %r)" % (id,pid)) + self.logger.info("Lingering task %r (pid %r)" % (id, pid)) def getNextTask(self): self.ready = self.readyForTask() - self.session.host.updateHost(self.task_load,self.ready) + self.session.host.updateHost(self.task_load, self.ready) if not self.ready: self.logger.info("Not ready for task") return False @@ -753,8 +753,8 @@ class TaskManager(object): our_avail = host['capacity'] - host['task_load'] for chan in host['channels']: for arch in host['arches'].split() + ['noarch']: - bin = "%s:%s" % (chan,arch) - bin_hosts.setdefault(bin,[]).append(host) + bin = "%s:%s" % (chan, arch) + bin_hosts.setdefault(bin, []).append(host) if host['id'] == self.host_id: bins[bin] = 1 self.logger.debug("bins: %r" % bins) @@ -1069,7 +1069,7 @@ class TaskManager(object): #XXX - add more checks return True - def takeTask(self,task): + def takeTask(self, task): """Attempt to open the specified task Returns True if successful, False otherwise @@ -1089,7 +1089,7 @@ class TaskManager(object): if hasattr(handler, 'checkHost'): try: valid_host = handler.checkHost(self.hostdata) - except (SystemExit,KeyboardInterrupt): + except (SystemExit, KeyboardInterrupt): raise except: valid_host = False @@ -1129,7 +1129,7 @@ class TaskManager(object): self.subsessions[task_id] = session_id return True - def forkTask(self,handler): + def forkTask(self, handler): #get the subsession before we fork newhub = self.session.subsession() session_id = newhub.sinfo['session-id'] @@ -1147,7 +1147,7 @@ class TaskManager(object): self.session = newhub handler.session = self.session #set a do-nothing handler for sigusr2 - signal.signal(signal.SIGUSR2,lambda *args: None) + signal.signal(signal.SIGUSR2, lambda *args: None) self.runTask(handler) finally: #diediedie @@ -1156,7 +1156,7 @@ class TaskManager(object): finally: os._exit(0) - def runTask(self,handler): + def runTask(self, handler): try: response = (handler.run(),) # note that we wrap response in a singleton tuple @@ -1168,7 +1168,7 @@ class TaskManager(object): response = xmlrpclib.dumps(fault) tb = ''.join(traceback.format_exception(*sys.exc_info())).replace(r"\n", "\n") self.logger.warn("FAULT:\n%s" % tb) - except (SystemExit,koji.tasks.ServerExit,KeyboardInterrupt): + except (SystemExit, koji.tasks.ServerExit, KeyboardInterrupt): #we do not trap these raise except koji.tasks.ServerRestart: @@ -1180,7 +1180,7 @@ class TaskManager(object): self.logger.warn("TRACEBACK: %s" % tb) # report exception back to server e_class, e = sys.exc_info()[:2] - faultCode = getattr(e_class,'faultCode',1) + faultCode = getattr(e_class, 'faultCode', 1) if issubclass(e_class, koji.GenericError): #just pass it through tb = str(e) diff --git a/koji/db.py b/koji/db.py index dcd24610..817d3880 100644 --- a/koji/db.py +++ b/koji/db.py @@ -81,15 +81,15 @@ class CursorWrapper: def _timed_call(self, method, args, kwargs): start = time.time() - ret = getattr(self.cursor,method)(*args,**kwargs) + ret = getattr(self.cursor, method)(*args, **kwargs) self.logger.debug("%s operation completed in %.4f seconds", method, time.time() - start) return ret - def fetchone(self,*args,**kwargs): - return self._timed_call('fetchone',args,kwargs) + def fetchone(self, *args, **kwargs): + return self._timed_call('fetchone', args, kwargs) - def fetchall(self,*args,**kwargs): - return self._timed_call('fetchall',args,kwargs) + def fetchall(self, *args, **kwargs): + return self._timed_call('fetchall', args, kwargs) def quote(self, operation, parameters): if _quoteparams is not None: @@ -97,7 +97,7 @@ class CursorWrapper: elif hasattr(self.cursor, "_quoteparams"): quote = self.cursor._quoteparams else: - quote = lambda a,b: a % b + quote = lambda a, b: a % b try: return quote(operation, parameters) except Exception: @@ -167,5 +167,5 @@ def connect(): return DBWrapper(conn) if __name__ == "__main__": - setDBopts( database = "test", user = "test") + setDBopts(database="test", user="test") print "This is a Python library" diff --git a/koji/policy.py b/koji/policy.py index 653f4143..32633706 100644 --- a/koji/policy.py +++ b/koji/policy.py @@ -268,7 +268,7 @@ class SimpleRuleSet(object): return tests, negate, action def get_test_handler(self, str): - name = str.split(None,1)[0] + name = str.split(None, 1)[0] try: return self.tests[name](str) except KeyError: @@ -284,7 +284,7 @@ class SimpleRuleSet(object): if isinstance(action, list): _recurse(action, index) else: - name = action.split(None,1)[0] + name = action.split(None, 1)[0] index[name] = 1 index = {} _recurse(self.ruleset, index) diff --git a/koji/ssl/SSLConnection.py b/koji/ssl/SSLConnection.py index e80bf444..de77d0d3 100644 --- a/koji/ssl/SSLConnection.py +++ b/koji/ssl/SSLConnection.py @@ -31,10 +31,10 @@ class SSLConnection: def __del__(self): self.__dict__["conn"].close() - def __getattr__(self,name): + def __getattr__(self, name): return getattr(self.__dict__["conn"], name) - def __setattr__(self,name, value): + def __setattr__(self, name, value): setattr(self.__dict__["conn"], name, value) def settimeout(self, timeout): @@ -61,7 +61,7 @@ class SSLConnection: c, a = self.__dict__["conn"].accept() return (SSLConnection(c), a) - def makefile(self, mode='r', bufsize=-1): + def makefile(self, mode='r', bufsize=-1): """ We need to use socket._fileobject Because SSL.Connection doesn't have a 'dup'. Not exactly sure WHY this is, but diff --git a/koji/tasks.py b/koji/tasks.py index d9dced3a..4567eed0 100644 --- a/koji/tasks.py +++ b/koji/tasks.py @@ -36,7 +36,7 @@ def scan_mounts(topdir): """Search path for mountpoints""" mplist = [] topdir = os.path.normpath(topdir) - fo = open('/proc/mounts','r') + fo = open('/proc/mounts', 'r') for line in fo.readlines(): path = line.split()[1] if path.startswith(topdir): @@ -53,9 +53,9 @@ def umount_all(topdir): for path in scan_mounts(topdir): logger.debug('Unmounting %s' % path) cmd = ['umount', '-l', path] - rv = os.spawnvp(os.P_WAIT,cmd[0],cmd) + rv = os.spawnvp(os.P_WAIT, cmd[0], cmd) if rv != 0: - raise koji.GenericError, 'umount failed (exit code %r) for %s' % (rv,path) + raise koji.GenericError, 'umount failed (exit code %r) for %s' % (rv, path) #check mounts again remain = scan_mounts(topdir) if remain: @@ -83,7 +83,7 @@ def safe_rmtree(path, unmount=False, strict=True): #first rm -f non-directories logger.debug('Scrubbing files in %s' % path) rv = os.system("find '%s' -xdev \\! -type d -print0 |xargs -0 rm -f" % path) - msg = 'file removal failed (code %r) for %s' % (rv,path) + msg = 'file removal failed (code %r) for %s' % (rv, path) if rv != 0: logger.warn(msg) if strict: @@ -94,7 +94,7 @@ def safe_rmtree(path, unmount=False, strict=True): #with -depth, we start at the bottom and work up logger.debug('Scrubbing directories in %s' % path) rv = os.system("find '%s' -xdev -depth -type d -print0 |xargs -0 rmdir" % path) - msg = 'dir removal failed (code %r) for %s' % (rv,path) + msg = 'dir removal failed (code %r) for %s' % (rv, path) if rv != 0: logger.warn(msg) if strict: @@ -128,7 +128,7 @@ class BaseTaskHandler(object): raise koji.GenericError, 'method "%s" is not supported' % method self.method = method # handle named parameters - self.params,self.opts = koji.decode_args(*params) + self.params, self.opts = koji.decode_args(*params) self.session = session self.options = options if workdir is None: @@ -137,7 +137,7 @@ class BaseTaskHandler(object): self.logger = logging.getLogger("koji.build.BaseTaskHandler") self.manager = None - def setManager(self,manager): + def setManager(self, manager): """Set the manager attribute This is only used for foreground tasks to give them access @@ -173,7 +173,7 @@ class BaseTaskHandler(object): Note that task weight is partially ignored while the task is sleeping. """ - return getattr(self,'_taskWeight',1.0) + return getattr(self, '_taskWeight', 1.0) def createWorkdir(self): if self.workdir is None: @@ -206,10 +206,10 @@ class BaseTaskHandler(object): the database and will send the subprocess corresponding to the subtask a SIGUSR2 to wake it up when subtasks complete. """ - if isinstance(subtasks,int): + if isinstance(subtasks, int): # allow single integer w/o enclosing list subtasks = [subtasks] - self.session.host.taskSetWait(self.id,subtasks) + self.session.host.taskSetWait(self.id, subtasks) self.logger.debug("Waiting on %r" % subtasks) while True: finished, unfinished = self.session.host.taskWait(self.id) @@ -387,12 +387,12 @@ class ForkTask(BaseTaskHandler): Methods = ['fork'] def handler(self, n=5, m=37): for i in xrange(n): - os.spawnvp(os.P_NOWAIT, 'sleep', ['sleep',str(m)]) + os.spawnvp(os.P_NOWAIT, 'sleep', ['sleep', str(m)]) class WaitTestTask(BaseTaskHandler): Methods = ['waittest'] _taskWeight = 0.1 - def handler(self,count,seconds=10): + def handler(self, count, seconds=10): tasks = [] for i in xrange(count): task_id = self.session.host.subtask(method='sleep', @@ -407,7 +407,7 @@ class WaitTestTask(BaseTaskHandler): class SubtaskTask(BaseTaskHandler): Methods = ['subtask'] _taskWeight = 0.1 - def handler(self,n=4): + def handler(self, n=4): if n > 0: task_id = self.session.host.subtask(method='subtask', arglist=[n-1], @@ -426,7 +426,7 @@ class DefaultTask(BaseTaskHandler): """Used when no matching method is found""" Methods = ['default'] _taskWeight = 0.1 - def handler(self,*args,**opts): + def handler(self, *args, **opts): raise koji.GenericError, "Invalid method: %s" % self.method @@ -523,7 +523,7 @@ class DependantTask(BaseTaskHandler): for task in wait_list[:]: if self.session.taskFinished(task): info = self.session.getTaskInfo(task) - if info and koji.TASK_STATES[info['state']] in ['CANCELED','FAILED']: + if info and koji.TASK_STATES[info['state']] in ['CANCELED', 'FAILED']: raise koji.GenericError, "Dependency %s failed to complete." % info['id'] wait_list.remove(task) # let the system rest before polling again @@ -532,7 +532,7 @@ class DependantTask(BaseTaskHandler): subtasks = [] for task in task_list: # **((len(task)>2 and task[2]) or {}) expands task[2] into opts if it exists, allows for things like 'priority=15' - task_id = self.session.host.subtask(method=task[0], arglist=task[1], parent=self.id, **((len(task)>2 and task[2]) or {})) + task_id = self.session.host.subtask(method=task[0], arglist=task[1], parent=self.id, **((len(task) > 2 and task[2]) or {})) if task_id: subtasks.append(task_id) if subtasks: diff --git a/koji/util.py b/koji/util.py index 79039798..3fe20eb0 100644 --- a/koji/util.py +++ b/koji/util.py @@ -375,7 +375,7 @@ def eventFromOpts(session, opts): rinfo = session.repoInfo(repo) if rinfo: return {'id' : rinfo['create_event'], - 'ts' : rinfo['create_ts'] } + 'ts' : rinfo['create_ts']} return None def filedigestAlgo(hdr): @@ -427,7 +427,7 @@ def setup_rlimits(opts, logger=None): except ValueError: logger.error("Invalid resource limit: %s=%s", key, opts[key]) continue - if len(limits) not in (1,2): + if len(limits) not in (1, 2): logger.error("Invalid resource limit: %s=%s", key, opts[key]) continue if len(limits) == 1: diff --git a/tests/test_hub/test_import_image_internal.py b/tests/test_hub/test_import_image_internal.py index 212d3684..6e889004 100644 --- a/tests/test_hub/test_import_image_internal.py +++ b/tests/test_hub/test_import_image_internal.py @@ -80,7 +80,7 @@ class TestImportImageInternal(unittest.TestCase): cursor = mock.MagicMock() context.cnx.cursor.return_value = cursor context.session.host_id = 42 - get_build.return_value = {'id': 2 } + get_build.return_value = {'id': 2} get_rpm.return_value = rpm get_archive_type.return_value = 4 work.return_value = self.tempdir