diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-10-09 22:09:16 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-10-09 22:09:16 +0200 |
commit | 49c4088ceb02da735d549014aaa9cba8c729ba54 (patch) | |
tree | 9ae70f02f4c548b7e7d2409eef89505cbd1924db /module/Api.py | |
parent | added nodejs as usuable js engine (diff) | |
download | pyload-49c4088ceb02da735d549014aaa9cba8c729ba54.tar.xz |
modified Api: filter downloads by state
Diffstat (limited to 'module/Api.py')
-rw-r--r-- | module/Api.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/module/Api.py b/module/Api.py index cf28fda5f..d8e7c537e 100644 --- a/module/Api.py +++ b/module/Api.py @@ -25,7 +25,6 @@ from dis import opmap from remote.ttypes import * -from datatypes.PyFile import PyFile from utils import compare_time, to_string, bits_set, get_index from utils.fs import free_space from common.packagetools import parseNames @@ -88,6 +87,19 @@ class UserContext(object): urlmatcher = re.compile(r"((https?|ftps?|xdcc|sftp):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+\-=\\\.&]*)", re.IGNORECASE) +stateMap = { + DownloadState.All: frozenset(getattr(DownloadStatus, x) for x in dir(DownloadStatus) if not x.startswith("_")), + DownloadState.Finished : frozenset((DownloadStatus.Finished, DownloadStatus.Skipped)), + DownloadState.Unfinished : None, + DownloadState.Failed : frozenset((DownloadStatus.Failed, DownloadStatus.TempOffline, DownloadStatus.Aborted)), + DownloadState.Unmanaged: None, #TODO +} + +stateMap[DownloadState.Unfinished] = frozenset(stateMap[DownloadState.All].difference(stateMap[DownloadState.Finished])) + +def state_string(state): + return ",".join(str(x) for x in stateMap[state]) + def has_permission(userPermission, Permission): return bits_set(Permission, userPermission) @@ -618,9 +630,9 @@ class Api(Iface): return self.getFileTree(-1, True) @RequirePerm(Permission.All) - def getAllUnfinishedFiles(self): - """ same as `getUnfinishedFileTree for toplevel root and full tree""" - return self.getUnfinishedFileTree(-1, True) + def getFilteredFiles(self, state): + """ same as `getFilteredFileTree` for toplevel root and full tree""" + return self.getFilteredFileTree(-1, state, True) @RequirePerm(Permission.All) def getFileTree(self, pid, full): @@ -631,17 +643,18 @@ class Api(Iface): :param full: go down the complete tree or only the first layer :return: :class:`TreeCollection` """ - return self.core.files.getTree(pid, full, False) + return self.core.files.getTree(pid, full, DownloadState.All) @RequirePerm(Permission.All) - def getUnfinishedFileTree(self, pid, full): - """ Same as `getFileTree` but only contains unfinished files. + def getFilteredFileTree(self, pid, full, state): + """ Same as `getFileTree` but only contains files with specific download state. :param pid: package id :param full: go down the complete tree or only the first layer + :param state: :class:`DownloadState`, the attributes used for filtering :return: :class:`TreeCollection` """ - return self.core.files.getTree(pid, full, False) + return self.core.files.getTree(pid, full, state) @RequirePerm(Permission.All) def getPackageContent(self, pid): |