diff options
Diffstat (limited to 'pyload')
| -rw-r--r-- | pyload/Api.py | 6 | ||||
| -rw-r--r-- | pyload/Core.py | 5 | ||||
| -rw-r--r-- | pyload/DownloadManager.py | 9 | ||||
| -rw-r--r-- | pyload/api/DownloadApi.py | 6 | ||||
| -rw-r--r-- | pyload/datatypes/PyFile.py | 1 | ||||
| -rw-r--r-- | pyload/datatypes/User.py | 6 | 
6 files changed, 20 insertions, 13 deletions
diff --git a/pyload/Api.py b/pyload/Api.py index e6bd74a02..c1b16ad96 100644 --- a/pyload/Api.py +++ b/pyload/Api.py @@ -81,6 +81,12 @@ class Api(Iface):      def primaryUID(self):          return self.user.primary if self.user else None + +    def hasAccess(self, obj): +        """ Helper method to determine if a user has access to a resource. +         Works for obj that provides .owner attribute. Core admin has always access.""" +        return self.user is None or self.user.hasAccess(obj) +      @classmethod      def initComponents(cls):          # Allow extending the api diff --git a/pyload/Core.py b/pyload/Core.py index 04a77f45f..f921188c5 100644 --- a/pyload/Core.py +++ b/pyload/Core.py @@ -36,6 +36,7 @@ from time import time, sleep  from traceback import print_exc  import locale +  locale.locale_alias = locale.windows_locale = {} #save ~100kb ram, no known sideeffects for now  import subprocess @@ -43,6 +44,7 @@ import subprocess  subprocess.__doc__ = None # the module with the largest doc we are using  from InitHomeDir import init_dir +  init_dir()  from AccountManager import AccountManager @@ -533,6 +535,7 @@ class Core(object):              if os.name == "nt":                  try:                      import colorama +                      colorama.init()                  except:                      color = False @@ -591,8 +594,8 @@ class Core(object):                  pass # TODO: quit webserver?                  #                self.webserver.quit() -            self.dlm.abort()              self.dlm.shutdown() +            self.api.stopAllDownloads()              self.addonManager.deactivateAddons()          except: diff --git a/pyload/DownloadManager.py b/pyload/DownloadManager.py index f014ab776..abb61a4fd 100644 --- a/pyload/DownloadManager.py +++ b/pyload/DownloadManager.py @@ -126,16 +126,11 @@ class DownloadManager:          """get a id list of all pyfiles processed"""          return [x.fid for x in self.activeDownloads(None)] -    @read_lock -    def abort(self): -        """ Cancels all downloads """ -        # TODO: may dead lock -        for t in self.working: -            t.active.abortDownload()      @read_lock      def shutdown(self):          """  End all threads """ +        self.paused = True          for thread in self.working + self.free:              thread.put("quit") @@ -168,7 +163,7 @@ class DownloadManager:          # check for waiting dl rule          if limit <= 0:              # increase limit if there are waiting downloads -            limit += min(self.waitingDownloads(), self.core.config['download']['wait_downloads'] + +            limit += min(len(self.waitingDownloads()), self.core.config['download']['wait_downloads'] +                                                    self.core.config['download']['max_downloads'] - len(                  self.activeDownloads())) diff --git a/pyload/api/DownloadApi.py b/pyload/api/DownloadApi.py index 71d112e44..299609e35 100644 --- a/pyload/api/DownloadApi.py +++ b/pyload/api/DownloadApi.py @@ -148,7 +148,9 @@ class DownloadApi(ApiComponent):      @RequirePerm(Permission.Modify)      def stopAllDownloads(self):          """Aborts all running downloads.""" -        self.core.dlm.abort() +        for pyfile in self.core.files.cachedFiles(): +            if self.hasAccess(pyfile): +                pyfile.abortDownload()      @RequirePerm(Permission.Modify)      def stopDownloads(self, fids): @@ -159,7 +161,7 @@ class DownloadApi(ApiComponent):          """          pyfiles = self.core.files.cachedFiles()          for pyfile in pyfiles: -            if pyfile.id in fids: +            if pyfile.id in fids and self.hasAccess(pyfile):                  pyfile.abortDownload() diff --git a/pyload/datatypes/PyFile.py b/pyload/datatypes/PyFile.py index 8f33b09fd..5e5d56d17 100644 --- a/pyload/datatypes/PyFile.py +++ b/pyload/datatypes/PyFile.py @@ -218,6 +218,7 @@ class PyFile(object):              sleep(0.5)          self.abort = False +        self.setStatus("aborted")          self.release()      def finishIfDone(self): diff --git a/pyload/datatypes/User.py b/pyload/datatypes/User.py index fbfb24378..ca5ac1813 100644 --- a/pyload/datatypes/User.py +++ b/pyload/datatypes/User.py @@ -51,12 +51,12 @@ class User(UserData):          return self.role == role +    def hasAccess(self, obj): +        return self.primary is None or obj.owner == self.true_primary +      def isAdmin(self):          return self.hasRole(Role.Admin) -    def isOwner(self, obj): -        return self.primary is None or obj.owner == self.true_primary -      @property      def primary(self):          """ Primary user id, Internal user handle used for most operations  | 
