summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-02-14 19:14:10 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-02-14 19:14:10 +0100
commit4aaa1dd526013e01775b1b07e757a33b328659a6 (patch)
tree00a81f3be666021fa435bd24fb896cb65fa77899
parentcloses #232 (diff)
downloadpyload-4aaa1dd526013e01775b1b07e757a33b328659a6.tar.xz
finished cli
-rw-r--r--module/remote/thriftbackend/Handler.py44
-rw-r--r--module/remote/thriftbackend/ThriftClient.py6
-rw-r--r--module/remote/thriftbackend/pyload.thrift4
-rwxr-xr-xmodule/remote/thriftbackend/thriftgen/pyload/Pyload-remote14
-rw-r--r--module/remote/thriftbackend/thriftgen/pyload/Pyload.py408
-rw-r--r--module/remote/thriftbackend/thriftgen/pyload/ttypes.py16
-rwxr-xr-xpyLoadCli.py149
7 files changed, 533 insertions, 108 deletions
diff --git a/module/remote/thriftbackend/Handler.py b/module/remote/thriftbackend/Handler.py
index 51764a0f5..1a9625394 100644
--- a/module/remote/thriftbackend/Handler.py
+++ b/module/remote/thriftbackend/Handler.py
@@ -137,7 +137,7 @@ class Handler(Iface):
if not isinstance(pyfile, PyFile):
continue
status = DownloadInfo()
- status.id = pyfile.id
+ status.fid = pyfile.id
status.name = pyfile.name
status.speed = pyfile.getSpeed() #bytes
status.eta = pyfile.getETA()
@@ -220,8 +220,7 @@ class Handler(Iface):
def getQueue(self):
packs = self.serverMethods.get_queue()
ret = []
- for pid in packs:
- pack = self.serverMethods.get_package_data(pid)
+ for pid, pack in packs.iteritems():
pdata = PackageInfo()
pdata.pid = pack["id"]
pdata.name = pack["name"]
@@ -235,11 +234,27 @@ class Handler(Iface):
ret.append(pdata)
return ret
- def getCollector(self):
+ def getQueueData(self):
packs = self.serverMethods.get_queue()
ret = []
- for pid in packs:
- pack = self.serverMethods.get_package_data(pid)
+ for pid, pack in packs.iteritems():
+ pdata = PackageData()
+ pdata.pid = pack["id"]
+ pdata.name = pack["name"]
+ pdata.folder = pack["folder"]
+ pdata.site = pack["site"]
+ pdata.password = pack["password"]
+ pdata.dest = pack["queue"]
+ pdata.order = pack["order"]
+ pdata.priority = pack["priority"]
+ pdata.links = [self._convertPyFile(x) for x in pack["links"].values()]
+ ret.append(pdata)
+ return ret
+
+ def getCollector(self):
+ packs = self.serverMethods.get_collector()
+ ret = []
+ for pid, pack in packs.iteritems():
pdata = PackageInfo()
pdata.pid = pack["id"]
pdata.name = pack["name"]
@@ -249,6 +264,23 @@ class Handler(Iface):
pdata.dest = pack["queue"]
pdata.order = pack["order"]
pdata.priority = pack["priority"]
+ pdata.links = [self._convertPyFile(x) for x in pack["links"].values()]
+ ret.append(pdata)
+ return ret
+
+ def getCollectorData(self):
+ packs = self.serverMethods.get_collector()
+ ret = []
+ for pid, pack in packs.iteritems():
+ pdata = PackageData()
+ pdata.pid = pack["id"]
+ pdata.name = pack["name"]
+ pdata.folder = pack["folder"]
+ pdata.site = pack["site"]
+ pdata.password = pack["password"]
+ pdata.dest = pack["queue"]
+ pdata.order = pack["order"]
+ pdata.priority = pack["priority"]
pdata.links = [int(x) for x in pack["links"].keys()]
ret.append(pdata)
return ret
diff --git a/module/remote/thriftbackend/ThriftClient.py b/module/remote/thriftbackend/ThriftClient.py
index c5beec96e..d5c203cf0 100644
--- a/module/remote/thriftbackend/ThriftClient.py
+++ b/module/remote/thriftbackend/ThriftClient.py
@@ -57,6 +57,10 @@ class ThriftClient:
correct = self.client.login(user, password)
finally:
self.socket.setTimeout(None)
+ elif e.args and e.args[0] == 32:
+ raise NoConnection
+ else:
+ raise
if not correct:
self.transport.close()
@@ -77,7 +81,7 @@ class ThriftClient:
if __name__ == "__main__":
- client = ThriftClient(user="User", password="pyloadweb")
+ client = ThriftClient(user="User", password="")
print client.getServerVersion()
print client.statusServer()
diff --git a/module/remote/thriftbackend/pyload.thrift b/module/remote/thriftbackend/pyload.thrift
index a8c295339..7ea1d5f94 100644
--- a/module/remote/thriftbackend/pyload.thrift
+++ b/module/remote/thriftbackend/pyload.thrift
@@ -34,7 +34,7 @@ enum ElementType {
}
struct DownloadInfo {
- 1: FileID id,
+ 1: FileID fid,
2: string name,
3: i64 speed,
4: i32 eta,
@@ -188,6 +188,8 @@ service Pyload {
void deletePackages(1: list<PackageID> pids),
list<PackageInfo> getQueue(),
list<PackageInfo> getCollector(),
+ list<PackageData> getQueueData(),
+ list<PackageData> getCollectorData(),
void addFiles(1: PackageID pid, 2: LinkList links),
void pushToQueue(1: PackageID pid),
void pullFromQueue(1: PackageID pid),
diff --git a/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote b/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote
index f8e047e49..92edffa14 100755
--- a/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote
+++ b/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote
@@ -45,6 +45,8 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print ' void deletePackages( pids)'
print ' getQueue()'
print ' getCollector()'
+ print ' getQueueData()'
+ print ' getCollectorData()'
print ' void addFiles(PackageID pid, LinkList links)'
print ' void pushToQueue(PackageID pid)'
print ' void pullFromQueue(PackageID pid)'
@@ -269,6 +271,18 @@ elif cmd == 'getCollector':
sys.exit(1)
pp.pprint(client.getCollector())
+elif cmd == 'getQueueData':
+ if len(args) != 0:
+ print 'getQueueData requires 0 args'
+ sys.exit(1)
+ pp.pprint(client.getQueueData())
+
+elif cmd == 'getCollectorData':
+ if len(args) != 0:
+ print 'getCollectorData requires 0 args'
+ sys.exit(1)
+ pp.pprint(client.getCollectorData())
+
elif cmd == 'addFiles':
if len(args) != 2:
print 'addFiles requires 2 args'
diff --git a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py
index 7c2372745..92220471b 100644
--- a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py
+++ b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py
@@ -131,6 +131,12 @@ class Iface:
def getCollector(self, ):
pass
+ def getQueueData(self, ):
+ pass
+
+ def getCollectorData(self, ):
+ pass
+
def addFiles(self, pid, links):
"""
Parameters:
@@ -985,6 +991,56 @@ class Client(Iface):
return result.success
raise TApplicationException(TApplicationException.MISSING_RESULT, "getCollector failed: unknown result");
+ def getQueueData(self, ):
+ self.send_getQueueData()
+ return self.recv_getQueueData()
+
+ def send_getQueueData(self, ):
+ self._oprot.writeMessageBegin('getQueueData', TMessageType.CALL, self._seqid)
+ args = getQueueData_args()
+ args.write(self._oprot)
+ self._oprot.writeMessageEnd()
+ self._oprot.trans.flush()
+
+ def recv_getQueueData(self, ):
+ (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+ if mtype == TMessageType.EXCEPTION:
+ x = TApplicationException()
+ x.read(self._iprot)
+ self._iprot.readMessageEnd()
+ raise x
+ result = getQueueData_result()
+ result.read(self._iprot)
+ self._iprot.readMessageEnd()
+ if result.success != None:
+ return result.success
+ raise TApplicationException(TApplicationException.MISSING_RESULT, "getQueueData failed: unknown result");
+
+ def getCollectorData(self, ):
+ self.send_getCollectorData()
+ return self.recv_getCollectorData()
+
+ def send_getCollectorData(self, ):
+ self._oprot.writeMessageBegin('getCollectorData', TMessageType.CALL, self._seqid)
+ args = getCollectorData_args()
+ args.write(self._oprot)
+ self._oprot.writeMessageEnd()
+ self._oprot.trans.flush()
+
+ def recv_getCollectorData(self, ):
+ (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+ if mtype == TMessageType.EXCEPTION:
+ x = TApplicationException()
+ x.read(self._iprot)
+ self._iprot.readMessageEnd()
+ raise x
+ result = getCollectorData_result()
+ result.read(self._iprot)
+ self._iprot.readMessageEnd()
+ if result.success != None:
+ return result.success
+ raise TApplicationException(TApplicationException.MISSING_RESULT, "getCollectorData failed: unknown result");
+
def addFiles(self, pid, links):
"""
Parameters:
@@ -1866,6 +1922,8 @@ class Processor(Iface, TProcessor):
self._processMap["deletePackages"] = Processor.process_deletePackages
self._processMap["getQueue"] = Processor.process_getQueue
self._processMap["getCollector"] = Processor.process_getCollector
+ self._processMap["getQueueData"] = Processor.process_getQueueData
+ self._processMap["getCollectorData"] = Processor.process_getCollectorData
self._processMap["addFiles"] = Processor.process_addFiles
self._processMap["pushToQueue"] = Processor.process_pushToQueue
self._processMap["pullFromQueue"] = Processor.process_pullFromQueue
@@ -2182,6 +2240,28 @@ class Processor(Iface, TProcessor):
oprot.writeMessageEnd()
oprot.trans.flush()
+ def process_getQueueData(self, seqid, iprot, oprot):
+ args = getQueueData_args()
+ args.read(iprot)
+ iprot.readMessageEnd()
+ result = getQueueData_result()
+ result.success = self._handler.getQueueData()
+ oprot.writeMessageBegin("getQueueData", TMessageType.REPLY, seqid)
+ result.write(oprot)
+ oprot.writeMessageEnd()
+ oprot.trans.flush()
+
+ def process_getCollectorData(self, seqid, iprot, oprot):
+ args = getCollectorData_args()
+ args.read(iprot)
+ iprot.readMessageEnd()
+ result = getCollectorData_result()
+ result.success = self._handler.getCollectorData()
+ oprot.writeMessageBegin("getCollectorData", TMessageType.REPLY, seqid)
+ result.write(oprot)
+ oprot.writeMessageEnd()
+ oprot.trans.flush()
+
def process_addFiles(self, seqid, iprot, oprot):
args = addFiles_args()
args.read(iprot)
@@ -5142,6 +5222,222 @@ class getCollector_result:
def __ne__(self, other):
return not (self == other)
+class getQueueData_args:
+
+ thrift_spec = (
+ )
+
+ def read(self, iprot):
+ if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+ fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+ return
+ iprot.readStructBegin()
+ while True:
+ (fname, ftype, fid) = iprot.readFieldBegin()
+ if ftype == TType.STOP:
+ break
+ else:
+ iprot.skip(ftype)
+ iprot.readFieldEnd()
+ iprot.readStructEnd()
+
+ def write(self, oprot):
+ if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+ oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+ return
+ oprot.writeStructBegin('getQueueData_args')
+ oprot.writeFieldStop()
+ oprot.writeStructEnd()
+ def validate(self):
+ return
+
+
+ def __repr__(self):
+ L = ['%s=%r' % (key, value)
+ for key, value in self.__dict__.iteritems()]
+ return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+ def __ne__(self, other):
+ return not (self == other)
+
+class getQueueData_result:
+ """
+ Attributes:
+ - success
+ """
+
+ thrift_spec = (
+ (0, TType.LIST, 'success', (TType.STRUCT,(PackageData, PackageData.thrift_spec)), None, ), # 0
+ )
+
+ def __init__(self, success=None,):
+ self.success = success
+
+ def read(self, iprot):
+ if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+ fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+ return
+ iprot.readStructBegin()
+ while True:
+ (fname, ftype, fid) = iprot.readFieldBegin()
+ if ftype == TType.STOP:
+ break
+ if fid == 0:
+ if ftype == TType.LIST:
+ self.success = []
+ (_etype121, _size118) = iprot.readListBegin()
+ for _i122 in xrange(_size118):
+ _elem123 = PackageData()
+ _elem123.read(iprot)
+ self.success.append(_elem123)
+ iprot.readListEnd()
+ else:
+ iprot.skip(ftype)
+ else:
+ iprot.skip(ftype)
+ iprot.readFieldEnd()
+ iprot.readStructEnd()
+
+ def write(self, oprot):
+ if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+ oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+ return
+ oprot.writeStructBegin('getQueueData_result')
+ if self.success != None:
+ oprot.writeFieldBegin('success', TType.LIST, 0)
+ oprot.writeListBegin(TType.STRUCT, len(self.success))
+ for iter124 in self.success:
+ iter124.write(oprot)
+ oprot.writeListEnd()
+ oprot.writeFieldEnd()
+ oprot.writeFieldStop()
+ oprot.writeStructEnd()
+ def validate(self):
+ return
+
+
+ def __repr__(self):
+ L = ['%s=%r' % (key, value)
+ for key, value in self.__dict__.iteritems()]
+ return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+ def __ne__(self, other):
+ return not (self == other)
+
+class getCollectorData_args:
+
+ thrift_spec = (
+ )
+
+ def read(self, iprot):
+ if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+ fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+ return
+ iprot.readStructBegin()
+ while True:
+ (fname, ftype, fid) = iprot.readFieldBegin()
+ if ftype == TType.STOP:
+ break
+ else:
+ iprot.skip(ftype)
+ iprot.readFieldEnd()
+ iprot.readStructEnd()
+
+ def write(self, oprot):
+ if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+ oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+ return
+ oprot.writeStructBegin('getCollectorData_args')
+ oprot.writeFieldStop()
+ oprot.writeStructEnd()
+ def validate(self):
+ return
+
+
+ def __repr__(self):
+ L = ['%s=%r' % (key, value)
+ for key, value in self.__dict__.iteritems()]
+ return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+ def __ne__(self, other):
+ return not (self == other)
+
+class getCollectorData_result:
+ """
+ Attributes:
+ - success
+ """
+
+ thrift_spec = (
+ (0, TType.LIST, 'success', (TType.STRUCT,(PackageData, PackageData.thrift_spec)), None, ), # 0
+ )
+
+ def __init__(self, success=None,):
+ self.success = success
+
+ def read(self, iprot):
+ if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+ fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+ return
+ iprot.readStructBegin()
+ while True:
+ (fname, ftype, fid) = iprot.readFieldBegin()
+ if ftype == TType.STOP:
+ break
+ if fid == 0:
+ if ftype == TType.LIST:
+ self.success = []
+ (_etype128, _size125) = iprot.readListBegin()
+ for _i129 in xrange(_size125):
+ _elem130 = PackageData()
+ _elem130.read(iprot)
+ self.success.append(_elem130)
+ iprot.readListEnd()
+ else:
+ iprot.skip(ftype)
+ else:
+ iprot.skip(ftype)
+ iprot.readFieldEnd()
+ iprot.readStructEnd()
+
+ def write(self, oprot):
+ if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+ oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+ return
+ oprot.writeStructBegin('getCollectorData_result')
+ if self.success != None:
+ oprot.writeFieldBegin('success', TType.LIST, 0)
+ oprot.writeListBegin(TType.STRUCT, len(self.success))
+ for iter131 in self.success:
+ iter131.write(oprot)
+ oprot.writeListEnd()
+ oprot.writeFieldEnd()
+ oprot.writeFieldStop()
+ oprot.writeStructEnd()
+ def validate(self):
+ return
+
+
+ def __repr__(self):
+ L = ['%s=%r' % (key, value)
+ for key, value in self.__dict__.iteritems()]
+ return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+ def __ne__(self, other):
+ return not (self == other)
+
class addFiles_args:
"""
Attributes:
@@ -5176,10 +5472,10 @@ class addFiles_args:
elif fid == 2:
if ftype == TType.LIST:
self.links = []
- (_etype121, _size118) = iprot.readListBegin()
- for _i122 in xrange(_size118):
- _elem123 = iprot.readString();
- self.links.append(_elem123)
+ (_etype135, _size132) = iprot.readListBegin()
+ for _i136 in xrange(_size132):
+ _elem137 = iprot.readString();
+ self.links.append(_elem137)
iprot.readListEnd()
else:
iprot.skip(ftype)
@@ -5200,8 +5496,8 @@ class addFiles_args:
if self.links != None:
oprot.writeFieldBegin('links', TType.LIST, 2)
oprot.writeListBegin(TType.STRING, len(self.links))
- for iter124 in self.links:
- oprot.writeString(iter124)
+ for iter138 in self.links:
+ oprot.writeString(iter138)
oprot.writeListEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
@@ -5870,10 +6166,10 @@ class stopDownloads_args:
if fid == 1:
if ftype == TType.LIST:
self.fids = []
- (_etype128, _size125) = iprot.readListBegin()
- for _i129 in xrange(_size125):
- _elem130 = iprot.readI32();
- self.fids.append(_elem130)
+ (_etype142, _size139) = iprot.readListBegin()
+ for _i143 in xrange(_size139):
+ _elem144 = iprot.readI32();
+ self.fids.append(_elem144)
iprot.readListEnd()
else:
iprot.skip(ftype)
@@ -5890,8 +6186,8 @@ class stopDownloads_args:
if self.fids != None:
oprot.writeFieldBegin('fids', TType.LIST, 1)
oprot.writeListBegin(TType.I32, len(self.fids))
- for iter131 in self.fids:
- oprot.writeI32(iter131)
+ for iter145 in self.fids:
+ oprot.writeI32(iter145)
oprot.writeListEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
@@ -6658,11 +6954,11 @@ class setPackageData_args:
elif fid == 2:
if ftype == TType.MAP:
self.data = {}
- (_ktype133, _vtype134, _size132 ) = iprot.readMapBegin()
- for _i136 in xrange(_size132):
- _key137 = iprot.readString();
- _val138 = iprot.readString();
- self.data[_key137] = _val138
+ (_ktype147, _vtype148, _size146 ) = iprot.readMapBegin()
+ for _i150 in xrange(_size146):
+ _key151 = iprot.readString();
+ _val152 = iprot.readString();
+ self.data[_key151] = _val152
iprot.readMapEnd()
else:
iprot.skip(ftype)
@@ -6683,9 +6979,9 @@ class setPackageData_args:
if self.data != None:
oprot.writeFieldBegin('data', TType.MAP, 2)
oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.data))
- for kiter139,viter140 in self.data.items():
- oprot.writeString(kiter139)
- oprot.writeString(viter140)
+ for kiter153,viter154 in self.data.items():
+ oprot.writeString(kiter153)
+ oprot.writeString(viter154)
oprot.writeMapEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
@@ -6994,11 +7290,11 @@ class getPackageOrder_result:
if fid == 0:
if ftype == TType.MAP:
self.success = {}
- (_ktype142, _vtype143, _size141 ) = iprot.readMapBegin()
- for _i145 in xrange(_size141):
- _key146 = iprot.readI16();
- _val147 = iprot.readI32();
- self.success[_key146] = _val147
+ (_ktype156, _vtype157, _size155 ) = iprot.readMapBegin()
+ for _i159 in xrange(_size155):
+ _key160 = iprot.readI16();
+ _val161 = iprot.readI32();
+ self.success[_key160] = _val161
iprot.readMapEnd()
else:
iprot.skip(ftype)
@@ -7015,9 +7311,9 @@ class getPackageOrder_result:
if self.success != None:
oprot.writeFieldBegin('success', TType.MAP, 0)
oprot.writeMapBegin(TType.I16, TType.I32, len(self.success))
- for kiter148,viter149 in self.success.items():
- oprot.writeI16(kiter148)
- oprot.writeI32(viter149)
+ for kiter162,viter163 in self.success.items():
+ oprot.writeI16(kiter162)
+ oprot.writeI32(viter163)
oprot.writeMapEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
@@ -7121,11 +7417,11 @@ class getFileOrder_result:
if fid == 0:
if ftype == TType.MAP:
self.success = {}
- (_ktype151, _vtype152, _size150 ) = iprot.readMapBegin()
- for _i154 in xrange(_size150):
- _key155 = iprot.readI16();
- _val156 = iprot.readI32();
- self.success[_key155] = _val156
+ (_ktype165, _vtype166, _size164 ) = iprot.readMapBegin()
+ for _i168 in xrange(_size164):
+ _key169 = iprot.readI16();
+ _val170 = iprot.readI32();
+ self.success[_key169] = _val170
iprot.readMapEnd()
else:
iprot.skip(ftype)
@@ -7142,9 +7438,9 @@ class getFileOrder_result:
if self.success != None:
oprot.writeFieldBegin('success', TType.MAP, 0)
oprot.writeMapBegin(TType.I16, TType.I32, len(self.success))
- for kiter157,viter158 in self.success.items():
- oprot.writeI16(kiter157)
- oprot.writeI32(viter158)
+ for kiter171,viter172 in self.success.items():
+ oprot.writeI16(kiter171)
+ oprot.writeI32(viter172)
oprot.writeMapEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
@@ -7694,11 +7990,11 @@ class getEvents_result:
if fid == 0:
if ftype == TType.LIST:
self.success = []
- (_etype162, _size159) = iprot.readListBegin()
- for _i163 in xrange(_size159):
- _elem164 = Event()
- _elem164.read(iprot)
- self.success.append(_elem164)
+ (_etype176, _size173) = iprot.readListBegin()
+ for _i177 in xrange(_size173):
+ _elem178 = Event()
+ _elem178.read(iprot)
+ self.success.append(_elem178)
iprot.readListEnd()
else:
iprot.skip(ftype)
@@ -7715,8 +8011,8 @@ class getEvents_result:
if self.success != None:
oprot.writeFieldBegin('success', TType.LIST, 0)
oprot.writeListBegin(TType.STRUCT, len(self.success))
- for iter165 in self.success:
- iter165.write(oprot)
+ for iter179 in self.success:
+ iter179.write(oprot)
oprot.writeListEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
@@ -7820,11 +8116,11 @@ class getAccounts_result:
if fid == 0:
if ftype == TType.LIST:
self.success = []
- (_etype169, _size166) = iprot.readListBegin()
- for _i170 in xrange(_size166):
- _elem171 = AccountInfo()
- _elem171.read(iprot)
- self.success.append(_elem171)
+ (_etype183, _size180) = iprot.readListBegin()
+ for _i184 in xrange(_size180):
+ _elem185 = AccountInfo()
+ _elem185.read(iprot)
+ self.success.append(_elem185)
iprot.readListEnd()
else:
iprot.skip(ftype)
@@ -7841,8 +8137,8 @@ class getAccounts_result:
if self.success != None:
oprot.writeFieldBegin('success', TType.LIST, 0)
oprot.writeListBegin(TType.STRUCT, len(self.success))
- for iter172 in self.success:
- iter172.write(oprot)
+ for iter186 in self.success:
+ iter186.write(oprot)
oprot.writeListEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
@@ -7928,10 +8224,10 @@ class getAccountTypes_result:
if fid == 0:
if ftype == TType.LIST:
self.success = []
- (_etype176, _size173) = iprot.readListBegin()
- for _i177 in xrange(_size173):
- _elem178 = iprot.readString();
- self.success.append(_elem178)
+ (_etype190, _size187) = iprot.readListBegin()
+ for _i191 in xrange(_size187):
+ _elem192 = iprot.readString();
+ self.success.append(_elem192)
iprot.readListEnd()
else:
iprot.skip(ftype)
@@ -7948,8 +8244,8 @@ class getAccountTypes_result:
if self.success != None:
oprot.writeFieldBegin('success', TType.LIST, 0)
oprot.writeListBegin(TType.STRING, len(self.success))
- for iter179 in self.success:
- oprot.writeString(iter179)
+ for iter193 in self.success:
+ oprot.writeString(iter193)
oprot.writeListEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
diff --git a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py
index 370858d4e..8af392d0a 100644
--- a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py
+++ b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py
@@ -99,7 +99,7 @@ class ElementType:
class DownloadInfo:
"""
Attributes:
- - id
+ - fid
- name
- speed
- eta
@@ -117,7 +117,7 @@ class DownloadInfo:
thrift_spec = (
None, # 0
- (1, TType.I32, 'id', None, None, ), # 1
+ (1, TType.I32, 'fid', None, None, ), # 1
(2, TType.STRING, 'name', None, None, ), # 2
(3, TType.I64, 'speed', None, None, ), # 3
(4, TType.I32, 'eta', None, None, ), # 4
@@ -133,8 +133,8 @@ class DownloadInfo:
(14, TType.I32, 'packageID', None, None, ), # 14
)
- def __init__(self, id=None, name=None, speed=None, eta=None, format_eta=None, bleft=None, size=None, format_size=None, percent=None, status=None, statusmsg=None, format_wait=None, wait_until=None, packageID=None,):
- self.id = id
+ def __init__(self, fid=None, name=None, speed=None, eta=None, format_eta=None, bleft=None, size=None, format_size=None, percent=None, status=None, statusmsg=None, format_wait=None, wait_until=None, packageID=None,):
+ self.fid = fid
self.name = name
self.speed = speed
self.eta = eta
@@ -160,7 +160,7 @@ class DownloadInfo:
break
if fid == 1:
if ftype == TType.I32:
- self.id = iprot.readI32();
+ self.fid = iprot.readI32();
else:
iprot.skip(ftype)
elif fid == 2:
@@ -238,9 +238,9 @@ class DownloadInfo:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
return
oprot.writeStructBegin('DownloadInfo')
- if self.id != None:
- oprot.writeFieldBegin('id', TType.I32, 1)
- oprot.writeI32(self.id)
+ if self.fid != None:
+ oprot.writeFieldBegin('fid', TType.I32, 1)
+ oprot.writeI32(self.fid)
oprot.writeFieldEnd()
if self.name != None:
oprot.writeFieldBegin('name', TType.STRING, 2)
diff --git a/pyLoadCli.py b/pyLoadCli.py
index 8a31b7efe..415025fa0 100755
--- a/pyLoadCli.py
+++ b/pyLoadCli.py
@@ -35,6 +35,7 @@ from codecs import getwriter
sys.stdout = getwriter("utf8")(sys.stdout, errors="replace")
from module import InitHomeDir
+from module.utils import formatSize
from module.ConfigParser import ConfigParser
from module.remote.thriftbackend.ThriftClient import ThriftClient, NoConnection, NoSSL, WrongLogin, PackageDoesNotExists, ConnectionClosed
@@ -42,27 +43,30 @@ class Cli:
def __init__(self, client, command):
self.client = client
self.command = command
-
- self.getch = _Getch()
- self.input = ""
- self.pos = [0, 0, 0]
- self.inputline = 0
- self.menuline = 0
- self.new_package = {}
+ if not self.command:
+ self.getch = _Getch()
+ self.input = ""
+ self.pos = [0, 0, 0]
+ self.inputline = 0
+ self.menuline = 0
- self.links_added = 0
+ self.new_package = {}
- os.system("clear")
- self.println(1, blue("py") + yellow("Load") + white(_(" Command Line Interface")))
- self.println(2, "")
+ self.links_added = 0
- self.file_list = {}
+ os.system("clear")
+ self.println(1, blue("py") + yellow("Load") + white(_(" Command Line Interface")))
+ self.println(2, "")
- self.thread = RefreshThread(self)
- self.thread.start()
+ self.file_list = {}
- self.start()
+ self.thread = RefreshThread(self)
+ self.thread.start()
+
+ self.start()
+ else:
+ self.processCommand()
def start(self):
while True:
@@ -124,9 +128,9 @@ class Cli:
line += 1
self.println(line,
blue("[") + yellow(z * "#" + (25 - z) * " ") + blue("] ") + green(str(percent) + "%") + _(
- " Speed: ") + green(str(int(download.speed)) + " kb/s") + _(" Size: ") + green(
+ " Speed: ") + green(formatSize(speed)+ "/s") + _(" Size: ") + green(
download.format_size) + _(" Finished in: ") + green(download.format_eta) + _(
- " ID: ") + green(download.id))
+ " ID: ") + green(download.fid))
line += 1
if download.status == 5:
self.println(line, cyan(download.name))
@@ -138,11 +142,11 @@ class Cli:
status = self.client.statusServer()
if status.pause:
self.println(line,
- _("Status: ") + red("paused") + _(" total Speed: ") + red(str(int(speed)) + " kb/s") + _(
+ _("Status: ") + red("paused") + _(" total Speed: ") + red(formatSize(speed)+ "/s") + _(
" Files in queue: ") + red(status.queue))
else:
self.println(line,
- _("Status: ") + red("running") + _(" total Speed: ") + red(str(int(speed)) + " kb/s") + _(
+ _("Status: ") + red("running") + _(" total Speed: ") + red(formatSize(speed) + "/s") + _(
" Files in queue: ") + red(status.queue))
line += 1
self.println(line, "")
@@ -324,6 +328,59 @@ class Cli:
self.build_menu()
+ def processCommand(self):
+ command = self.command[0]
+ args = []
+ if len(self.command) > 1:
+ args = self.command[1:]
+
+ if command == "status":
+ files = self.client.statusDownloads()
+
+ for download in files:
+ if download.status == 12: # downloading
+ print print_status(download)
+ print "\tDownloading: %s @ %s/s\t %s (%s%%)" % (download.format_eta, formatSize(download.speed), formatSize(download.size - download.bleft), download.percent)
+ if download.status == 5:
+ print print_status(download)
+ print "\tWaiting: %s" % download.format_wait
+
+ elif command == "queue":
+ print_packages(self.client.getQueueData())
+
+ elif command == "collector":
+ print_packages(self.client.getCollectorData())
+
+ elif command == "add":
+ if len(args) < 2:
+ print _("Please use this syntax: add <Package name> <link> <link2> ...")
+ return
+
+ self.client.addPackage(args[0], args[1:], 1)
+
+ elif command == "del_file":
+ self.client.deleteFiles([int(x) for x in args])
+ print "Files deleted."
+
+ elif command == "del_package":
+ self.client.deletePackages([int(x) for x in args])
+ print "Packages deleted."
+
+ elif command == "pause":
+ self.client.pause()
+
+ elif command == "unpause":
+ self.client.unpause()
+
+ elif command == "toggle":
+ self.client.togglePause()
+
+ elif command == "kill":
+ self.client.kill()
+ else:
+ print_commands()
+
+
class RefreshThread(threading.Thread):
def __init__(self, cli):
threading.Thread.__init__(self)
@@ -467,23 +524,44 @@ def print_help():
def print_packages(data):
- for pid, pack in data.iteritems():
- print "Package %s (#%s):" % (pack["name"], pid)
- for download in pack["links"].itervalues():
- print " #%(id)-6d %(name)-20s %(statusmsg)-10s %(plugin)-8s" % download
+ for pack in data:
+ print "Package %s (#%s):" % (pack.name, pack.pid)
+ for download in pack.links:
+ print "\t" + print_file(download)
+ print
+
+def print_file(download):
+ return "#%(id)-6d %(name)-30s %(statusmsg)-10s %(plugin)-8s" % {
+ "id": download.fid,
+ "name": download.name,
+ "statusmsg": download.statusmsg,
+ "plugin": download.plugin
+ }
+
+def print_status(download):
+ return "#%(id)-6s %(name)-40s Status: %(statusmsg)-10s Size: %(size)s" % {
+ "id": download.fid,
+ "name": download.name,
+ "statusmsg": download.statusmsg,
+ "size": download.format_size
+ }
def print_commands():
- commands = [(_("status"), _("prints server status")),
- (_("queue"), _("prints downloads in queue")),
- (_("collector"), _("prints downloads in collector")),
- (_("pause"), _("pause the server")),
- (_("unpause"), _("continue downloads")),
- (_("toggle"), _("toggle pause/unpause")),
- (_("kill"), _("kill server")), ]
-
- print "Use one of:\n"
+ commands = [("status", _("Prints server status")),
+ ("queue", _("Prints downloads in queue")),
+ ("collector", _("Prints downloads in collector")),
+ ("add <name> <link1> <link2>...", _("Adds package to queue")),
+ ("del_file <fid> <fid2>...", _("Delete Files from Queue/Collector")),
+ ("del_package <pid> <pid2>...", _("Delete Packages from Queue/Collector")),
+ ("pause", _("Pause the server")),
+ ("unpause", _("continue downloads")),
+ ("toggle", _("Toggle pause/unpause")),
+ ("kill", _("kill server")), ]
+
+ print _("List of commands:")
+ print
for c in commands:
- print "%-15s %s" % c
+ print "%-30s %s" % c
if __name__ == "__main__":
config = ConfigParser()
@@ -528,9 +606,8 @@ if __name__ == "__main__":
print_help()
exit()
- if len(extraparams) == 1:
- command = sys.argv[1]
-
+ if len(extraparams) >= 1:
+ command = extraparams
client = False