def filterJobs(self, db, limit, filterWs=False, filterPane=False, useCp=False): # pylint: disable=too-many-arguments jobList = self.getDbSorted(db, limit, useCp) if filterWs: curWs = utils.workspaceIdentity() if curWs: jobList = [j for j in jobList if curWs == j.workspace] if filterPane: curPane = os.getenv('TMUX_PANE', None) if curPane: jobList = [ j for j in jobList if j.matchEnv( 'TMUX_PANE', curPane)] return jobList
def getDbSorted(db, _limit, useCp=False, filterWs=False): if useCp: cpUtc = db.checkpoint if filterWs: curWs = utils.workspaceIdentity() jobList = [] for k in db.keys(): if db.filterJobs(k): try: job = db[k] except KeyError: continue if useCp: refTime = job.createTime if not refTime or refTime < cpUtc: continue if filterWs: if job.workspace != curWs: continue jobList.append(job) # if _limit and len( jobList ) > _limit: # break jobList.sort(reverse=False) return jobList
def getJobMatch(self, key, thisWs, skipReminders=False): # pylint: disable=too-many-return-statements,too-many-branches if key == '.': lastJob = self.active.lastJob if lastJob: return self.getJobMatch(lastJob, thisWs) if key is None: jobList = filter( lambda x: self.filterJobsWith(x, skipReminders=skipReminders), self.getDbSorted(self.active, None, filterWs=thisWs)) if not jobList: jobList = filter( lambda x: self.filterJobsWith( x, skipReminders=skipReminders), self.getDbSorted(self.inactive, None, filterWs=thisWs)) if not jobList: jobList = self.getDbSorted( self.inactive, None, filterWs=thisWs) return jobList[-1] elif key in self.active.db: # Exact match, try active first return self.active[key] elif key in self.inactive.db: # Exact match, try inactive return self.inactive[key] else: # Search in active jobs candidates = [] curWs = utils.workspaceIdentity() for k in self.active.keys(): j = self.active[k] if j.mailJob: continue if skipReminders and j.reminder: continue jobWs = j.workspace if thisWs and curWs != jobWs: continue if j.cmdStr.find(key) >= 0: if curWs and jobWs == curWs: return j else: candidates.append(j) if candidates: return candidates[0] candidates = [] for k in self.inactive.recent: if k not in self.inactive: continue j = self.inactive[k] if isinstance(j, str): continue if j.mailJob: continue if skipReminders and j.reminder: continue jobWs = j.workspace if thisWs and curWs != jobWs: continue if j.cmdStr.find(key) >= 0: if curWs and jobWs == curWs: return j else: candidates.append(j) elif k.startswith(key): candidates.append(j) if candidates: return candidates[0] raise KeyError("No job for key '%s'" % key)