summaryrefslogtreecommitdiffstats
path: root/pyload/api
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2014-01-18 18:45:13 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2014-01-18 18:45:13 +0100
commit453c1e55c71a96c9529ecdca1d55278cc41088d6 (patch)
tree7a516a84e5590ce5f1f3def71c24bcb14f209023 /pyload/api
parentsmall fixes and improvements for download engine (diff)
downloadpyload-453c1e55c71a96c9529ecdca1d55278cc41088d6.tar.xz
rewritten download scheduling, improved account manager, db version increased all data will be overwritten
Diffstat (limited to 'pyload/api')
-rw-r--r--pyload/api/AccountApi.py27
-rw-r--r--pyload/api/CoreApi.py29
-rw-r--r--pyload/api/DownloadApi.py5
-rw-r--r--pyload/api/StatisticsApi.py28
-rw-r--r--pyload/api/__init__.py2
5 files changed, 62 insertions, 29 deletions
diff --git a/pyload/api/AccountApi.py b/pyload/api/AccountApi.py
index d4b39c12b..6b89a2aad 100644
--- a/pyload/api/AccountApi.py
+++ b/pyload/api/AccountApi.py
@@ -27,12 +27,12 @@ class AccountApi(ApiComponent):
return [acc.toInfoData() for acc in accounts]
@RequirePerm(Permission.Accounts)
- def getAccountInfo(self, plugin, loginname, refresh=False):
+ def getAccountInfo(self, aid, plugin, refresh=False):
""" Returns :class:`AccountInfo` for a specific account
:param refresh: reload account info
"""
- account = self.core.accountManager.getAccount(plugin, loginname)
+ account = self.core.accountManager.getAccount(aid, plugin)
# Admins can see and refresh accounts
if not account or (self.primaryUID and self.primaryUID != account.owner):
@@ -45,20 +45,27 @@ class AccountApi(ApiComponent):
return account.toInfoData()
@RequirePerm(Permission.Accounts)
- def updateAccount(self, plugin, loginname, password):
- """Creates an account if not existent or updates the password
+ def createAccount(self, plugin, loginname, password):
+ """ Creates a new account
- :return: newly created or updated account info
+ :return class:`AccountInfo`
"""
- # TODO: None pointer
- return self.core.accountManager.updateAccount(plugin, loginname, password, self.user).toInfoData()
+ return self.core.accountManager.createAccount(plugin, loginname, password, self.user.true_primary).toInfoData()
+
+ @RequirePerm(Permission.Accounts)
+ def updateAccount(self, aid, plugin, loginname, password):
+ """Updates loginname and password of an existent account
+
+ :return: updated account info
+ """
+ return self.core.accountManager.updateAccount(aid, plugin, loginname, password, self.user).toInfoData()
@RequirePerm(Permission.Accounts)
def updateAccountInfo(self, account):
""" Update account settings from :class:`AccountInfo` """
- inst = self.core.accountManager.getAccount(account.plugin, account.loginname, self.user)
- if not account:
+ inst = self.core.accountManager.getAccount(account.aid, account.plugin, self.user)
+ if not inst:
return
inst.activated = to_bool(account.activated)
@@ -72,7 +79,7 @@ class AccountApi(ApiComponent):
:param account: :class:`ÀccountInfo` instance
"""
- self.core.accountManager.removeAccount(account.plugin, account.loginname, self.primaryUID)
+ self.core.accountManager.removeAccount(account.aid, account.plugin, self.primaryUID)
if Api.extend(AccountApi):
diff --git a/pyload/api/CoreApi.py b/pyload/api/CoreApi.py
index 187286b48..b15272196 100644
--- a/pyload/api/CoreApi.py
+++ b/pyload/api/CoreApi.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from pyload.Api import Api, RequirePerm, Permission, ServerStatus, Interaction
+from pyload.Api import Api, RequirePerm, Permission, StatusInfo, Interaction
from pyload.utils.fs import join, free_space, exists
from pyload.utils import compare_time
@@ -37,24 +37,24 @@ class CoreApi(ApiComponent):
return "%s://%%s:%d" % (ws, self.core.config['webUI']['wsPort'])
@RequirePerm(Permission.All)
- def getServerStatus(self):
+ def getStatusInfo(self):
"""Some general information about the current status of pyLoad.
- :return: `ServerStatus`
+ :return: `StatusInfo`
"""
queue = self.core.files.getQueueStats(self.primaryUID)
total = self.core.files.getDownloadStats(self.primaryUID)
- serverStatus = ServerStatus(0,
+ serverStatus = StatusInfo(0,
total[0], queue[0],
total[1], queue[1],
self.isInteractionWaiting(Interaction.All),
- not self.core.threadManager.pause and self.isTimeDownload(),
- self.core.threadManager.pause,
- self.core.config['reconnect']['activated'] and self.isTimeReconnect())
+ not self.core.dlm.paused and self.isTimeDownload(),
+ self.core.dlm.paused,
+ self.core.config['reconnect']['activated'] and self.isTimeReconnect(),
+ self.getQuota())
-
- for pyfile in self.core.threadManager.getActiveDownloads(self.primaryUID):
+ for pyfile in self.core.dlm.activeDownloads(self.primaryUID):
serverStatus.speed += pyfile.getSpeed() #bytes/s
return serverStatus
@@ -65,23 +65,24 @@ class CoreApi(ApiComponent):
:rtype: list of :class:`ProgressInfo`
"""
- return self.core.threadManager.getProgressList(self.primaryUID)
+ return self.core.dlm.getProgressList(self.primaryUID) +\
+ self.core.threadManager.getProgressList(self.primaryUID)
def pauseServer(self):
"""Pause server: It won't start any new downloads, but nothing gets aborted."""
- self.core.threadManager.pause = True
+ self.core.dlm.paused = True
def unpauseServer(self):
"""Unpause server: New Downloads will be started."""
- self.core.threadManager.pause = False
+ self.core.dlm.paused = False
def togglePause(self):
"""Toggle pause state.
:return: new pause state
"""
- self.core.threadManager.pause ^= True
- return self.core.threadManager.pause
+ self.core.dlm.paused ^= True
+ return self.core.dlm.paused
def toggleReconnect(self):
"""Toggle reconnect activation.
diff --git a/pyload/api/DownloadApi.py b/pyload/api/DownloadApi.py
index b29f9c06c..71d112e44 100644
--- a/pyload/api/DownloadApi.py
+++ b/pyload/api/DownloadApi.py
@@ -148,10 +148,7 @@ class DownloadApi(ApiComponent):
@RequirePerm(Permission.Modify)
def stopAllDownloads(self):
"""Aborts all running downloads."""
-
- pyfiles = self.core.files.cachedFiles()
- for pyfile in pyfiles:
- pyfile.abortDownload()
+ self.core.dlm.abort()
@RequirePerm(Permission.Modify)
def stopDownloads(self, fids):
diff --git a/pyload/api/StatisticsApi.py b/pyload/api/StatisticsApi.py
new file mode 100644
index 000000000..d313e4d0e
--- /dev/null
+++ b/pyload/api/StatisticsApi.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from pyload.Api import Api, RequirePerm, Permission
+
+from ApiComponent import ApiComponent
+
+CACHE = {}
+QUOTA_UNLIMITED = -1
+
+
+class StatisticsApi(ApiComponent):
+ """ Retrieve download statistics and quota """
+
+ def recordDownload(self, pyfile):
+ """ Add download record to the statistics """
+ del CACHE[:]
+
+ def calcQuota(self, uid):
+ return QUOTA_UNLIMITED
+
+ def getQuota(self):
+ """ Number of bytes the user has left for download """
+ return self.calcQuota(self.user.true_primary)
+
+
+if Api.extend(StatisticsApi):
+ del StatisticsApi \ No newline at end of file
diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py
index a2b292a27..e25c82a52 100644
--- a/pyload/api/__init__.py
+++ b/pyload/api/__init__.py
@@ -1,5 +1,5 @@
__all__ = ["CoreApi", "ConfigApi", "DownloadApi", "DownloadPreparingApi", "FileApi",
- "UserInteractionApi", "AccountApi", "AddonApi", "UserApi"]
+ "UserInteractionApi", "AccountApi", "AddonApi", "UserApi", "StatisticsApi"]
# Import all components
# from .import *