diff options
| author | 2014-01-29 18:51:38 +0100 | |
|---|---|---|
| committer | 2014-01-29 18:51:38 +0100 | |
| commit | 3401bcfd5ed57dec9e0f78553d627d7608170cb6 (patch) | |
| tree | c36ac6fe4581379ed03f72409244aa40414b9580 | |
| parent | fixed new waiting dl rule (diff) | |
| download | pyload-3401bcfd5ed57dec9e0f78553d627d7608170cb6.tar.xz | |
added connection flags to download status
| -rw-r--r-- | pyload/__init__.py | 4 | ||||
| -rw-r--r-- | pyload/datatypes/PyFile.py | 43 | ||||
| -rw-r--r-- | pyload/plugins/Request.py | 1 | ||||
| -rw-r--r-- | pyload/plugins/network/CurlDownload.py | 2 | ||||
| -rw-r--r-- | pyload/remote/apitypes.py | 12 | ||||
| -rw-r--r-- | pyload/remote/apitypes_debug.py | 3 | ||||
| -rw-r--r-- | pyload/remote/create_apitypes.py | 7 | ||||
| -rw-r--r-- | pyload/remote/pyload.thrift | 11 | ||||
| -rw-r--r-- | pyload/utils/__init__.py | 54 | ||||
| -rw-r--r-- | pyload/web/app/scripts/utils/apitypes.js | 1 | 
10 files changed, 98 insertions, 40 deletions
| diff --git a/pyload/__init__.py b/pyload/__init__.py index 0fb52399b..395c3d15f 100644 --- a/pyload/__init__.py +++ b/pyload/__init__.py @@ -1,5 +1,5 @@  # -*- coding: utf-8 -*-  __dev__ = True -__version_info__ = ('0', '4', '9', '9') -__version__ = '.'.join(__version_info__) + ("-dev" if __dev__ else "")
\ No newline at end of file +__version_info__ = (0, 4, 9, 9) +__version__ = '.'.join(str(v) for v in __version_info__) + ("-dev" if __dev__ else "")
\ No newline at end of file diff --git a/pyload/datatypes/PyFile.py b/pyload/datatypes/PyFile.py index 5e5d56d17..80926ae11 100644 --- a/pyload/datatypes/PyFile.py +++ b/pyload/datatypes/PyFile.py @@ -20,7 +20,7 @@ from time import sleep, time  from ReadWriteLock import ReadWriteLock  from pyload.Api import ProgressInfo, ProgressType, DownloadProgress, FileInfo, DownloadInfo, DownloadStatus -from pyload.utils import lock, read_lock +from pyload.utils import lock, read_lock, try_catch  from pyload.utils.fs import safe_filename  from pyload.utils.filetypes import guess_type @@ -48,7 +48,6 @@ statusMap = {      "unknown": 20,  } -  class PyFile(object):      """      Represents a file object at runtime @@ -192,8 +191,7 @@ class PyFile(object):      def toInfoData(self):          return FileInfo(self.fid, self.getName(), self.packageid, self.owner, self.getSize(), self.filestatus,                          self.media, self.added, self.fileorder, DownloadInfo( -                self.url, self.pluginname, self.hash, self.status, self.getStatusName(), self.error -            ) +                self.url, self.pluginname, self.hash, self.status, self.getStatusName(), self.error)          )      def getPath(self): @@ -204,7 +202,6 @@ class PyFile(object):      def abortDownload(self):          """abort pyfile if possible""" -        # TODO: abort timeout, currently dead locks          while self.fid in self.m.core.dlm.processingIds():              self.lock.acquire(shared=True) @@ -236,36 +233,28 @@ class PyFile(object):      def checkIfProcessed(self):          self.m.checkAllLinksProcessed(self.id) +    @try_catch(0)      def getSpeed(self):          """ calculates speed """ -        try: -            return self.plugin.dl.speed -        except: -            return 0 +        return self.plugin.dl.speed +    @try_catch(0)      def getETA(self): -        """ gets established time of arrival / or waiting time""" -        try: -            if self.status == DownloadStatus.Waiting: -                return self.waitUntil - time() +        """ gets estimated time of arrival / or waiting time""" +        if self.status == DownloadStatus.Waiting: +            return self.waitUntil - time() -            return self.getBytesLeft() / self.getSpeed() -        except: -            return 0 +        return self.getBytesLeft() / self.getSpeed() +    @try_catch(0)      def getBytesArrived(self):          """ gets bytes arrived """ -        try: -            return self.plugin.dl.arrived -        except: -            return 0 +        return self.plugin.dl.arrived +    @try_catch(0)      def getBytesLeft(self):          """ gets bytes left """ -        try: -            return self.plugin.dl.size - self.plugin.dl.arrived -        except: -            return 0 +        return self.plugin.dl.size - self.plugin.dl.arrived      def getSize(self):          """ get size of download """ @@ -277,7 +266,11 @@ class PyFile(object):          except:              return self.size +    @try_catch(0) +    def getFlags(self): +        return self.plugin.dl.flags +      def getProgressInfo(self):          return ProgressInfo(self.pluginname, self.name, self.getStatusName(), self.getETA(),                              self.getBytesArrived(), self.getSize(), self.owner, ProgressType.Download, -                            DownloadProgress(self.fid, self.packageid, self.getSpeed(), self.status)) +                            DownloadProgress(self.fid, self.packageid, self.getSpeed(), self.getFlags(), self.status)) diff --git a/pyload/plugins/Request.py b/pyload/plugins/Request.py index 9f6fe8c2b..651da09f9 100644 --- a/pyload/plugins/Request.py +++ b/pyload/plugins/Request.py @@ -33,6 +33,7 @@ class Request(object):          # Last response code          self.code = 0 +        self.flags = 0          self.doAbort = False          self.initContext() diff --git a/pyload/plugins/network/CurlDownload.py b/pyload/plugins/network/CurlDownload.py index e23f193e7..819c6cfb9 100644 --- a/pyload/plugins/network/CurlDownload.py +++ b/pyload/plugins/network/CurlDownload.py @@ -23,6 +23,7 @@ from shutil import move  import pycurl +from pyload.Api import Connection  from pyload.plugins.Base import Abort  from pyload.network.CookieJar import CookieJar  from pyload.utils.fs import save_join, fs_encode @@ -170,6 +171,7 @@ class CurlDownload(Download):              #need to create chunks              if not chunksCreated and self.chunkSupport and self.size: #will be set later by first chunk +                self.flags ^= Connection.Resumable                  if not resume:                      self.info.setSize(self.size)                      self.info.createChunks(chunks) diff --git a/pyload/remote/apitypes.py b/pyload/remote/apitypes.py index 4c66800c6..704d3b876 100644 --- a/pyload/remote/apitypes.py +++ b/pyload/remote/apitypes.py @@ -4,14 +4,21 @@  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING  class BaseObject(object): +	__version__ = (0, 4, 9, 9)  	__slots__ = []  	def __str__(self):  		return "<%s %s>" % (self.__class__.__name__, ", ".join("%s=%s" % (k,getattr(self,k)) for k in self.__slots__))  class ExceptionObject(Exception): +	__version__ = (0, 4, 9, 9)  	__slots__ = [] +class Connection: +	All = 0 +	Resumable = 1 +	Secure = 2 +  class DownloadState:  	All = 0  	Finished = 1 @@ -194,12 +201,13 @@ class DownloadInfo(BaseObject):  		self.error = error  class DownloadProgress(BaseObject): -	__slots__ = ['fid', 'pid', 'speed', 'status'] +	__slots__ = ['fid', 'pid', 'speed', 'conn', 'status'] -	def __init__(self, fid=None, pid=None, speed=None, status=None): +	def __init__(self, fid=None, pid=None, speed=None, conn=None, status=None):  		self.fid = fid  		self.pid = pid  		self.speed = speed +		self.conn = conn  		self.status = status  class EventInfo(BaseObject): diff --git a/pyload/remote/apitypes_debug.py b/pyload/remote/apitypes_debug.py index a30009bad..6c959e56a 100644 --- a/pyload/remote/apitypes_debug.py +++ b/pyload/remote/apitypes_debug.py @@ -6,6 +6,7 @@  from apitypes import *  enums = [ +	"Connection",  	"DownloadState",  	"DownloadStatus",  	"FileStatus", @@ -26,7 +27,7 @@ classes = {  	'ConfigInfo' : [basestring, basestring, basestring, basestring, bool, (None, bool)],  	'ConfigItem' : [basestring, basestring, basestring, Input, basestring],  	'DownloadInfo' : [basestring, basestring, basestring, int, basestring, basestring], -	'DownloadProgress' : [int, int, int, int], +	'DownloadProgress' : [int, int, int, int, int],  	'EventInfo' : [basestring, (list, basestring)],  	'FileDoesNotExist' : [int],  	'FileInfo' : [int, basestring, int, int, int, int, int, int, int, (None, DownloadInfo)], diff --git a/pyload/remote/create_apitypes.py b/pyload/remote/create_apitypes.py index 61063fa3b..80fdb7848 100644 --- a/pyload/remote/create_apitypes.py +++ b/pyload/remote/create_apitypes.py @@ -12,8 +12,7 @@ from thrift.Thrift import TType  from thriftgen.pyload import ttypes  from thriftgen.pyload import Pyload -# TODO: import and add version -# from pyload import CURRENT_VERSION +from pyload import __version_info__  type_map = {      TType.BOOL: 'bool', @@ -80,15 +79,17 @@ def main():  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING  class BaseObject(object): +\t__version__ = {0}  \t__slots__ = []  \tdef __str__(self):  \t\treturn "<%s %s>" % (self.__class__.__name__, ", ".join("%s=%s" % (k,getattr(self,k)) for k in self.__slots__))  class ExceptionObject(Exception): +\t__version__ = {0}  \t__slots__ = [] -""") +""".format(__version_info__))      dev = open(join(path, "apitypes_debug.py"), "wb")      dev.write("""#!/usr/bin/env python diff --git a/pyload/remote/pyload.thrift b/pyload/remote/pyload.thrift index 9d400c4e2..8c85fbd00 100644 --- a/pyload/remote/pyload.thrift +++ b/pyload/remote/pyload.thrift @@ -129,6 +129,12 @@ enum ProgressType {      FileOperation = 32,  } +enum Connection { +    All = 0, +    Resumable = 1, +    Secure = 2, +} +  struct Input {      1: InputType type,      2: optional JSONString default_value, @@ -139,7 +145,8 @@ struct DownloadProgress {      1: FileID fid,      2: PackageID pid,      3: ByteCount speed, // per second -    4: DownloadStatus status, +    4: Connection conn, +    5: DownloadStatus status,  }  struct ProgressInfo { @@ -315,7 +322,7 @@ struct AccountInfo {    9: bool premium,    10: bool activated,    11: bool shared, -  13: list <ConfigItem> config, +  12: list <ConfigItem> config,  }  struct OnlineCheck { diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py index 1badfbdd2..510664b05 100644 --- a/pyload/utils/__init__.py +++ b/pyload/utils/__init__.py @@ -18,6 +18,7 @@ except ImportError: #use system simplejson if available  json_loads = json.loads  json_dumps = json.dumps +  def decode(string):      """ decode string to unicode with utf8 """      if type(string) == str: @@ -25,6 +26,7 @@ def decode(string):      else:          return string +  def encode(string):      """ decode string to utf8 """      if type(string) == unicode: @@ -51,6 +53,7 @@ def get_console_encoding(enc):      return enc +  def compare_time(start, end):      start = map(int, start)      end = map(int, end) @@ -58,18 +61,26 @@ def compare_time(start, end):      if start == end: return True      now = list(time.localtime()[3:5]) -    if start < now < end: return True -    elif start > end and (now > start or now < end): return True -    elif start < now > end < start: return True -    else: return False +    if start < now < end: +        return True +    elif start > end and (now > start or now < end): +        return True +    elif start < now > end < start: +        return True +    else: +        return False +  def to_list(value): -    return value if type(value) == list else list(value) if type(value) == set else ([value] if value is not None else []) +    return value if type(value) == list else list(value) if type(value) == set else ( +    [value] if value is not None else []) +  def formatSize(size):      print "Deprecated formatSize, use format_size"      return format_size(size) +  def format_size(bytes):      bytes = int(bytes)      steps = 0 @@ -79,28 +90,34 @@ def format_size(bytes):          steps += 1      return "%.2f %s" % (bytes, sizes[steps]) +  def formatSpeed(speed):      print "Deprecated formatSpeed, use format_speed"      return format_speed(speed) +  def format_speed(speed):      return format_size(speed) + "/s" +  def format_time(seconds):      if seconds < 0: return "00:00:00"      hours, seconds = divmod(seconds, 3600)      minutes, seconds = divmod(seconds, 60)      return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) +  def parse_time(timestamp, pattern):      """ Parse a string representing a time according to a pattern and      return a time in seconds suitable for an account plugin. """      return int(time.mktime(time.strptime(timestamp, pattern))) +  def parseFileSize(string, unit=None):      print "Deprecated parseFileSize, use parse_size"      return parse_size(string, unit) +  def parse_size(string, unit=None):      """ Parses file size from a string. Tries to parse unit if not given. @@ -131,15 +148,18 @@ def parse_size(string, unit=None):      return traffic +  def uniqify(seq): #by Dave Kirby      """ removes duplicates from list, preserve order """      seen = set()      return [x for x in seq if x not in seen and not seen.add(x)] +  def bits_set(bits, compare):      """ checks if all bits are set in compare, or bits is 0 """      return bits == (bits & compare) +  def lock(func):      def new(*args, **kwargs):          #print "Handler: %s args: %s" % (func,args[1:]) @@ -151,6 +171,7 @@ def lock(func):      return new +  def read_lock(func):      def new(*args, **kwargs):          args[0].lock.acquire(shared=True) @@ -161,6 +182,7 @@ def read_lock(func):      return new +  def chunks(iterable, size):      it = iter(iterable)      item = list(islice(it, size)) @@ -195,6 +217,7 @@ def has_method(obj, name):      """ checks if 'name' was defined in obj, (false if it was inhereted) """      return hasattr(obj, '__dict__') and name in obj.__dict__ +  def accumulate(it, inv_map=None):      """ accumulate (key, value) data to {value : [keylist]} dictionary """      if inv_map is None: @@ -208,13 +231,16 @@ def accumulate(it, inv_map=None):      return inv_map +  def to_string(value):      return str(value) if not isinstance(value, basestring) else value +  def to_bool(value):      if not isinstance(value, basestring): return True if value else False      return True if value.lower() in ("1", "true", "on", "an", "yes") else False +  def to_int(string, default=0):      """ return int from string or default """      try: @@ -222,6 +248,7 @@ def to_int(string, default=0):      except ValueError:          return default +  def get_index(l, value):      """ .index method that also works on tuple and python 2.5 """      for pos, t in enumerate(l): @@ -231,14 +258,31 @@ def get_index(l, value):      # Matches behavior of list.index      raise ValueError("list.index(x): x not in list") +  def primary_uid(user):      """ Gets primary user id for user instances or ints """      if type(user) == int: return user      return user.primary if user else None +  def html_unescape(text):      """Removes HTML or XML character references and entities from a text string"""      return re.sub("&#?\w+;", fixup, text) + +def try_catch(fallback): +    """ Decorator that executes the function and returns the value or fallback on any exception """ +    def wrap(f): +        def new(*args, **kwargs): +            try: +                return f(*args, **kwargs) +            except: +                return fallback + +        return new + +    return wrap + +  if __name__ == "__main__":      print remove_chars("ab'cdgdsf''ds'", "'ghd") diff --git a/pyload/web/app/scripts/utils/apitypes.js b/pyload/web/app/scripts/utils/apitypes.js index 88123f7ea..08bdfd200 100644 --- a/pyload/web/app/scripts/utils/apitypes.js +++ b/pyload/web/app/scripts/utils/apitypes.js @@ -3,6 +3,7 @@  define([], function() {  	'use strict';  	return { +		Connection: {'All': 0, 'Resumable': 1, 'Secure': 2},  		DownloadState: {'Failed': 3, 'All': 0, 'Unmanaged': 4, 'Finished': 1, 'Unfinished': 2},  		DownloadStatus: {'NotPossible': 13, 'FileMismatch': 15, 'Downloading': 10, 'Missing': 14, 'NA': 0, 'Processing': 18, 'Waiting': 9, 'Decrypting': 17, 'Paused': 4, 'Failed': 7, 'Finished': 5, 'Skipped': 6, 'Unknown': 20, 'Aborted': 12, 'Online': 2, 'Starting': 8, 'TempOffline': 11, 'Offline': 1, 'Custom': 19, 'Occupied': 16, 'Queued': 3},  		FileStatus: {'Remote': 2, 'Ok': 0, 'Missing': 1}, | 
