diff options
| author | 2011-02-12 21:47:23 +0100 | |
|---|---|---|
| committer | 2011-02-12 21:47:23 +0100 | |
| commit | 21aa78672f76da16716e163c950b63fd3a46e2fd (patch) | |
| tree | 8804a23d94b85f4b6415e49fba5c696799fe79f3 | |
| parent | basic thrift client (diff) | |
| download | pyload-21aa78672f76da16716e163c950b63fd3a46e2fd.tar.xz | |
cleanup
| -rw-r--r-- | module/Utils.py | 14 | ||||
| -rw-r--r-- | module/plugins/Account.py | 4 | ||||
| -rw-r--r-- | module/remote/thriftbackend/ThriftClient.py | 2 | ||||
| -rwxr-xr-x | pyLoadCore.py | 48 | 
4 files changed, 23 insertions, 45 deletions
| diff --git a/module/Utils.py b/module/Utils.py index 2d8a0423e..5f36c2d77 100644 --- a/module/Utils.py +++ b/module/Utils.py @@ -37,17 +37,27 @@ def compare_time(start, end):      elif start < now and end < now and start > end: return True      else: return False +def formatSize(size): +    """formats size of bytes""" +    size = int(size) +    steps = 0 +    sizes = ["B", "KiB", "MiB", "GiB", "TiB"] +    while size > 1000: +        size /= 1024.0 +        steps += 1 +    return "%.2f %s" % (size, sizes[steps]) +  def freeSpace(folder):      if sys.platform == 'nt':          import ctypes          free_bytes = ctypes.c_ulonglong(0)          ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) -        return free_bytes.value / 1024 / 1024 #megabyte +        return free_bytes.value      else:          from os import statvfs          s = statvfs(folder) -        return s.f_bsize * s.f_bavail / 1024 / 1024 #megabyte +        return s.f_bsize * s.f_bavail  def uniqify(seq, idfun=None):        # order preserving diff --git a/module/plugins/Account.py b/module/plugins/Account.py index ae9038eed..b8de4ddf0 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -22,6 +22,8 @@ from random import choice  from time import time  from traceback import print_exc +from module.utils import compare_time +  class WrongPassword(Exception):      pass @@ -164,7 +166,7 @@ class Account():                  try:                      time_data = data["options"]["time"][0]                      start, end = time_data.split("-") -                    if not self.core.compare_time(start.split(":"), end.split(":")): +                    if not compare_time(start.split(":"), end.split(":")):                          continue                  except:                      self.core.log.warning(_("Your Time %s has wrong format, use: 1:22-3:44") % time_data) diff --git a/module/remote/thriftbackend/ThriftClient.py b/module/remote/thriftbackend/ThriftClient.py index 68c2d25ed..9fcabc4e7 100644 --- a/module/remote/thriftbackend/ThriftClient.py +++ b/module/remote/thriftbackend/ThriftClient.py @@ -24,7 +24,7 @@ class NoConnection(Exception):  class NoSSL(Exception):      pass -class ThriftClient(): +class ThriftClient:      def __init__(self, host="localhost", port=7228, user="", password=""):          self.createConnection(host, port) diff --git a/pyLoadCore.py b/pyLoadCore.py index fd48748ba..ace86b899 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -64,6 +64,7 @@ from module.remote.RemoteManager import RemoteManager  from module.database import DatabaseBackend  from module.database import FileHandler +from module.utils import freeSpace, formatSize, compare_time  from codecs import getwriter  if os.name == "nt": @@ -346,17 +347,9 @@ class Core(object):          #linkFile = self.config['general']['link_file'] -        freeSpace = self.freeSpace() -        def formatSize(size): -            """formats size of bytes""" -            size = int(size) -            steps = 0 -            sizes = ["B", "KiB", "MiB", "GiB", "TiB"] -            while size > 1000: -                size /= 1024.0 -                steps += 1 -            return "%.2f %s" % (size, sizes[steps]) -        self.log.info(_("Free space: %s") % formatSize(freeSpace)) +        spaceLeft = freeSpace(self.config["general"]["download_folder"]) +         +        self.log.info(_("Free space: %s") % formatSize(spaceLeft))          self.threadManager.pause = False          #self.threadManager.start() @@ -491,19 +484,6 @@ class Core(object):          self.shutdown()          execv(executable, [executable, "pyLoadCore.py"]) -    def compare_time(self, start, end): -        start = map(int, start) -        end = map(int, end) - -        if start == end: return True - -        now = list(time.localtime()[3:5]) -        if start < now and end > now: return True -        elif start > end and (now > start or now < end): return True -        elif start < now and end < now and start > end: return True -        else: return False - -      def shutdown(self):          self.log.info(_("shutting down..."))          try: @@ -532,20 +512,6 @@ class Core(object):      def path(self, * args):          return join(pypath, * args) -    def freeSpace(self): -        folder = self.config['general']['download_folder'] -        if platform == 'nt': -            import ctypes - -            free_bytes = ctypes.c_ulonglong(0) -            ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) -            return free_bytes.value -        else: -            from os import statvfs - -            s = statvfs(folder) -            return s.f_bsize * s.f_bavail -          ####################################          ########## XMLRPC Methods ########## @@ -649,7 +615,7 @@ class ServerMethods():          return status      def free_space(self): -        return self.core.freeSpace() / 1024 / 1024 #mb +        return freeSpace(self.core.config["general"]["download_folder"]) / 1024 / 1024 #mb      def get_server_version(self):          return CURRENT_VERSION @@ -858,12 +824,12 @@ class ServerMethods():      def is_time_download(self):          start = self.core.config['downloadTime']['start'].split(":")          end = self.core.config['downloadTime']['end'].split(":") -        return self.core.compare_time(start, end) +        return compare_time(start, end)      def is_time_reconnect(self):          start = self.core.config['reconnect']['startTime'].split(":")          end = self.core.config['reconnect']['endTime'].split(":") -        return self.core.compare_time(start, end) +        return compare_time(start, end)      def delete_finished(self):          """ delete all finished links + packages, returns deleted packages """ | 
