📄 scheduler.py
字号:
if not self.flag.isSet():
wx.PostEvent(self, InvokeEvent(func, args, kwargs))
def updateAndInvoke(self, updateCounters = True, invokeLater = True):
if updateCounters:
# Update counter for running torrents
self.UpdateRunningTorrentCounters()
# Only invoke the scheduler if we're not shutting down
if invokeLater:
self.invokeLater(self.Scheduler)
def updateTorrentList(self):
torrentconfig = self.utility.torrentconfig
torrentconfig.DeleteGroup()
for ABCTorrentTemp in self.utility.torrents["all"]:
ABCTorrentTemp.torrentconfig.writeSrc(False)
# try:
# torrentconfig.DeleteGroup("dummygroup")
# except:
# pass
torrentconfig.Flush()
def getInactiveTorrents(self, numtorrents):
if numtorrents < 0:
numtorrents = 0
torrents_inactive = self.utility.torrents["inactive"].keys()
# Find which torrents are queued:
inactivetorrents = [ABCTorrentTemp for ABCTorrentTemp in torrents_inactive if (ABCTorrentTemp.status.value == STATUS_QUEUE)]
inactivelength = len(inactivetorrents)
if inactivelength > numtorrents:
# Sort first by listindex
inactivetorrents.sort(key = attrgetter('listindex'))
# Sort second by priority
inactivetorrents.sort(key = attrgetter('prio'))
# Slice off the number of torrents we need to start
inactivetorrents = inactivetorrents[0:numtorrents]
return inactivetorrents
# Find new processes to start
def Scheduler(self):
if self.flag.isSet():
return
self.flag.set()
numsimdownload = self.utility.config.Read('numsimdownload', "int")
# Max number of torrents to start
torrentstostart = numsimdownload - self.getProcCount()
if torrentstostart < 0:
torrentstostart = 0
inactivestarted = 0
# Start torrents
inactivetorrents = self.getInactiveTorrents(torrentstostart)
for ABCTorrentTemp in inactivetorrents:
change = ABCTorrentTemp.actions.resume()
if change:
inactivestarted += 1
torrentstostart = torrentstostart - inactivestarted
if inactivestarted > 0:
self.UpdateRunningTorrentCounters()
self.flag.clear()
def changeABCParams(self):
self.utility.bottomline2.changeSpinners()
for ABCTorrentTemp in self.utility.torrents["all"]:
#Local doesn't need to affect with change ABC Params
ABCTorrentTemp.connection.resetUploadParams()
self.updateAndInvoke()
# Move a line of the list from index1 to index2
def MoveItems(self, listtomove, direction = 1):
listtomove.sort()
if direction == 1:
# Moving items down, need to reverse the list
listtomove.reverse()
# Start offset will be one greater than the
# first item in the resulting set
startoffset = -1
endoffset = 0
# We're only going to allow moving up or down
else:
direction = -1
# End offset will be one greater than the
# last item in the set
startoffset = 0
endoffset = 1
newloc = []
for index in listtomove:
if (direction == 1) and (index == len(self.utility.torrents["all"]) - 1):
#Last Item can't move down anymore
newloc.append(index)
elif (direction == -1) and (index == 0):
# First Item can't move up anymore
newloc.append(index)
elif newloc.count(index + direction) != 0 :
#Don't move if we've already moved the next item
newloc.append(index)
else:
ABCTorrentTemp = self.utility.torrents["all"].pop(index)
self.utility.torrents["all"].insert(index + direction, ABCTorrentTemp)
newloc.append(index + direction)
# Only need update if something has changed
if newloc:
newloc.sort()
start = newloc[0] + startoffset
end = newloc[-1] + endoffset
self.updateListIndex(startindex = start, endindex = end)
return newloc
def MoveItemsTop(self, selected):
for index in selected:
if index != 0: # First Item can't move up anymore
ABCTorrentTemp = self.utility.torrents["all"].pop(index)
self.utility.torrents["all"].insert(0, ABCTorrentTemp)
if selected:
self.updateListIndex(startindex = 0, endindex = selected[0])
return True
def MoveItemsBottom(self, selected):
for index in selected:
if index < len(self.utility.torrents["all"]) - 1:
ABCTorrentTemp = self.utility.torrents["all"].pop(index)
self.utility.torrents["all"].append(ABCTorrentTemp)
if selected:
self.updateListIndex(startindex = selected[0])
return True
# Clear all completed torrents from the list
#
# Passing in a list of torrents to remove + move
# allows for a torrent to auto-clear itself when
# completed
def clearAllCompleted(self, removelist = None):
if removelist is None:
removelist = [ABCTorrentTemp for ABCTorrentTemp in self.utility.torrents["inactive"].keys() if ABCTorrentTemp.status.isDoneUploading()]
# See if we need to move the completed torrents
# before we remove them from the list
if self.utility.config.Read('movecompleted', "boolean"):
self.utility.actionhandler.procMOVE(removelist)
# Remove the torrents
self.utility.actionhandler.procREMOVE(removelist)
def clearScheduler(self):
# Stop frequent timer
try:
if self.timers['frequent'] is not None:
self.timers['frequent'].cancel()
except:
pass
torrents_inactive = self.utility.torrents["inactive"].keys()
# Call shutdown on inactive torrents
# (controller.stop will take care of the rest)
for ABCTorrentTemp in torrents_inactive:
ABCTorrentTemp.shutdown()
# Stop all active torrents
self.utility.controller.stop()
# Update the torrent list
self.updateTorrentList()
# sys.stderr.write("\nDone clearing scheduler")
# Stop the timer for updating the torrent list
try:
if self.timers['infrequent'] is not None:
self.timers['infrequent'].cancel()
del self.timers['infrequent']
except:
pass
def getABCTorrent(self, index = -1, info_hash = None):
# Find it by the index
if index >= 0 and index < len(self.utility.torrents["all"]):
return self.utility.torrents["all"][index]
# Can't find it by index and the hash is none
# We're out of luck
elif info_hash is None:
return None
# Look for the hash value
for ABCTorrentTemp in self.utility.torrents["all"]:
if ABCTorrentTemp.infohash == info_hash:
return ABCTorrentTemp
def sortList(self, colid = 4, reverse = False):
# Sort by uprate first
self.utility.torrents["all"].sort(key = lambda x: x.getColumnValue(colid, -1.0), reverse = reverse)
self.updateListIndex()
def updateListIndex(self, startindex = 0, endindex = None):
# Can't update indexes for things that aren't in the list anymore
if startindex >= len(self.utility.torrents["all"]):
return
if startindex < 0:
startindex = 0
if endindex is None or endindex >= len(self.utility.torrents["all"]):
endindex = len(self.utility.torrents["all"]) - 1
for i in range(startindex, endindex + 1):
ABCTorrentTemp = self.utility.torrents["all"][i]
ABCTorrentTemp.listindex = i
ABCTorrentTemp.updateColumns()
ABCTorrentTemp.updateColor(force = True)
ABCTorrentTemp.torrentconfig.writeSrc(False)
self.utility.torrentconfig.Flush()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -