diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/remote/ThriftBackend.py | 5 | ||||
-rw-r--r-- | module/remote/thriftbackend/Handler.py | 12 | ||||
-rw-r--r-- | module/remote/thriftbackend/Processor.py | 2 | ||||
-rw-r--r-- | module/remote/thriftbackend/Protocol.py | 30 | ||||
-rw-r--r-- | module/remote/thriftbackend/ThriftTest.py | 10 | ||||
-rw-r--r-- | module/remote/thriftbackend/pyload.thrift | 8 | ||||
-rw-r--r-- | module/remote/thriftbackend/thriftgen/pyload/ttypes.py | 47 | ||||
-rw-r--r-- | module/web/json_app.py | 6 |
8 files changed, 81 insertions, 39 deletions
diff --git a/module/remote/ThriftBackend.py b/module/remote/ThriftBackend.py index bbad7e7d6..9e645b07e 100644 --- a/module/remote/ThriftBackend.py +++ b/module/remote/ThriftBackend.py @@ -19,10 +19,11 @@ from module.remote.RemoteManager import BackendBase from thriftbackend.Handler import Handler from thriftbackend.Processor import Processor +from thriftbackend.Protocol import ProtocolFactory from thrift.transport import TSocket from thrift.transport import TTransport -from thrift.protocol import TBinaryProtocol + from thrift.server import TServer class ThriftBackend(BackendBase): @@ -32,7 +33,7 @@ class ThriftBackend(BackendBase): transport = TSocket.TServerSocket(7228) #@TODO unicode encoding tfactory = TTransport.TBufferedTransportFactory() - pfactory = TBinaryProtocol.TBinaryProtocolFactory() + pfactory = ProtocolFactory() #self.server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) self.server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) diff --git a/module/remote/thriftbackend/Handler.py b/module/remote/thriftbackend/Handler.py index de7232758..da77b8ed2 100644 --- a/module/remote/thriftbackend/Handler.py +++ b/module/remote/thriftbackend/Handler.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from thriftgen.pyload.ttypes import * from thriftgen.pyload.Pyload import Iface @@ -130,7 +132,7 @@ class Handler(Iface): x.active and x.active != "quit"]: if not isinstance(pyfile, PyFile): continue - status = DownloadStatus() + status = DownloadInfo() status.id = pyfile.id status.name = pyfile.name status.speed = pyfile.getSpeed() / 1024 @@ -165,19 +167,19 @@ class Handler(Iface): """ pdata = PackageData() rawData = self.serverMethods.get_package_data(pid) - print rawData pdata.pid = rawData["id"] pdata.name = rawData["name"] pdata.folder = rawData["folder"] pdata.site = rawData["site"] pdata.password = rawData["password"] - pdata.queue = rawData["queue"] + pdata.dest = rawData["queue"] pdata.order = rawData["order"] pdata.priority = rawData["priority"] pdata.links = [] for id, pyfile in rawData["links"].iteritems(): pdata.links.append(self._convertPyFile(pyfile)) + return pdata def getFileData(self, fid): @@ -215,7 +217,7 @@ class Handler(Iface): pdata.folder = pack["folder"] pdata.site = pack["site"] pdata.password = pack["password"] - pdata.queue = pack["queue"] + pdata.dest = pack["queue"] pdata.order = pack["order"] pdata.priority = pack["priority"] pdata.links = [int(x) for x in pack["links"].keys()] @@ -233,7 +235,7 @@ class Handler(Iface): pdata.folder = pack["folder"] pdata.site = pack["site"] pdata.password = pack["password"] - pdata.queue = pack["queue"] + pdata.dest = pack["queue"] pdata.order = pack["order"] pdata.priority = pack["priority"] pdata.links = [int(x) for x in pack["links"].keys()] diff --git a/module/remote/thriftbackend/Processor.py b/module/remote/thriftbackend/Processor.py index b3a0991dd..53c6e404d 100644 --- a/module/remote/thriftbackend/Processor.py +++ b/module/remote/thriftbackend/Processor.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from thriftgen.pyload import Pyload class Processor(Pyload.Processor): diff --git a/module/remote/thriftbackend/Protocol.py b/module/remote/thriftbackend/Protocol.py new file mode 100644 index 000000000..c42d01459 --- /dev/null +++ b/module/remote/thriftbackend/Protocol.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from thrift.protocol import TBinaryProtocol + +class Protocol(TBinaryProtocol.TBinaryProtocol): + def writeString(self, str): + try: + str = str.encode("utf8", "ignore") + except Exception, e: + pass + + self.writeI32(len(str)) + self.trans.write(str) + + def readString(self): + len = self.readI32() + str = self.trans.readAll(len) + try: + str = str.decode("utf8", "ignore") + except: + pass + + return str + + +class ProtocolFactory(TBinaryProtocol.TBinaryProtocolFactory): + + def getProtocol(self, trans): + prot = Protocol(trans, self.strictRead, self.strictWrite) + return prot
\ No newline at end of file diff --git a/module/remote/thriftbackend/ThriftTest.py b/module/remote/thriftbackend/ThriftTest.py index 9bbb8cbb9..7fe790cd9 100644 --- a/module/remote/thriftbackend/ThriftTest.py +++ b/module/remote/thriftbackend/ThriftTest.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- import sys from os.path import join,abspath,dirname @@ -12,7 +13,8 @@ from thriftgen.pyload.ttypes import * from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport -from thrift.protocol import TBinaryProtocol + +from Protocol import Protocol from time import sleep, time @@ -52,7 +54,7 @@ try: transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol - protocol = TBinaryProtocol.TBinaryProtocol(transport) + protocol = Protocol(transport) # Create a client to use the protocol encoder client = Pyload.Client(protocol) @@ -75,7 +77,9 @@ try: q = client.getQueue() for p in q: - print client.getPackageData(p.pid) + data = client.getPackageData(p.pid) + print data + print "Package Name: ", data.name # Close! transport.close() diff --git a/module/remote/thriftbackend/pyload.thrift b/module/remote/thriftbackend/pyload.thrift index 7bbdaffd0..aaa843808 100644 --- a/module/remote/thriftbackend/pyload.thrift +++ b/module/remote/thriftbackend/pyload.thrift @@ -33,7 +33,7 @@ enum ElementType { File } -struct DownloadStatus { +struct DownloadInfo { 1: FileID id, 2: string name, 3: i32 speed, @@ -95,7 +95,7 @@ struct PackageData { 3: string folder, 4: string site, 5: string password, - 6: Destination destination, + 6: Destination dest, 7: i16 order, 8: Priority priority, 9: list<FileData> links @@ -107,7 +107,7 @@ struct PackageInfo { 3: string folder, 4: string site, 5: string password, - 6: Destination destination, + 6: Destination dest, 7: i16 order, 8: Priority priority, 9: list<FileID> links @@ -172,7 +172,7 @@ service Pyload { bool isTimeReconnect(), //downloads - list<DownloadStatus> statusDownloads(), + list<DownloadInfo> statusDownloads(), PackageID addPackage(1: string name, 2: LinkList links, 3: Destination dest), PackageData getPackageData(1: PackageID pid), FileData getFileData(1: FileID fid), diff --git a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py index 91062df33..2b51e1467 100644 --- a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py +++ b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py @@ -96,7 +96,7 @@ class ElementType: } -class DownloadStatus: +class DownloadInfo: """ Attributes: - id @@ -245,7 +245,7 @@ class DownloadStatus: 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('DownloadStatus') + oprot.writeStructBegin('DownloadInfo') if self.id != None: oprot.writeFieldBegin('id', TType.I32, 1) oprot.writeI32(self.id) @@ -666,7 +666,7 @@ class FileData: (4, TType.STRING, 'plugin', None, None, ), # 4 (5, TType.I64, 'size', None, None, ), # 5 (6, TType.STRING, 'format_size', None, None, ), # 6 - (7, TType.STRUCT, 'status', (DownloadStatus, DownloadStatus.thrift_spec), None, ), # 7 + (7, TType.I32, 'status', None, None, ), # 7 (8, TType.STRING, 'statusmsg', None, None, ), # 8 (9, TType.I32, 'package', None, None, ), # 9 (10, TType.STRING, 'error', None, None, ), # 10 @@ -728,9 +728,8 @@ class FileData: else: iprot.skip(ftype) elif fid == 7: - if ftype == TType.STRUCT: - self.status = DownloadStatus() - self.status.read(iprot) + if ftype == TType.I32: + self.status = iprot.readI32(); else: iprot.skip(ftype) elif fid == 8: @@ -793,8 +792,8 @@ class FileData: oprot.writeString(self.format_size) oprot.writeFieldEnd() if self.status != None: - oprot.writeFieldBegin('status', TType.STRUCT, 7) - self.status.write(oprot) + oprot.writeFieldBegin('status', TType.I32, 7) + oprot.writeI32(self.status) oprot.writeFieldEnd() if self.statusmsg != None: oprot.writeFieldBegin('statusmsg', TType.STRING, 8) @@ -841,7 +840,7 @@ class PackageData: - folder - site - password - - destination + - dest - order - priority - links @@ -854,19 +853,19 @@ class PackageData: (3, TType.STRING, 'folder', None, None, ), # 3 (4, TType.STRING, 'site', None, None, ), # 4 (5, TType.STRING, 'password', None, None, ), # 5 - (6, TType.I32, 'destination', None, None, ), # 6 + (6, TType.I32, 'dest', None, None, ), # 6 (7, TType.I16, 'order', None, None, ), # 7 (8, TType.BYTE, 'priority', None, None, ), # 8 (9, TType.LIST, 'links', (TType.STRUCT,(FileData, FileData.thrift_spec)), None, ), # 9 ) - def __init__(self, pid=None, name=None, folder=None, site=None, password=None, destination=None, order=None, priority=None, links=None,): + def __init__(self, pid=None, name=None, folder=None, site=None, password=None, dest=None, order=None, priority=None, links=None,): self.pid = pid self.name = name self.folder = folder self.site = site self.password = password - self.destination = destination + self.dest = dest self.order = order self.priority = priority self.links = links @@ -907,7 +906,7 @@ class PackageData: iprot.skip(ftype) elif fid == 6: if ftype == TType.I32: - self.destination = iprot.readI32(); + self.dest = iprot.readI32(); else: iprot.skip(ftype) elif fid == 7: @@ -961,9 +960,9 @@ class PackageData: oprot.writeFieldBegin('password', TType.STRING, 5) oprot.writeString(self.password) oprot.writeFieldEnd() - if self.destination != None: - oprot.writeFieldBegin('destination', TType.I32, 6) - oprot.writeI32(self.destination) + if self.dest != None: + oprot.writeFieldBegin('dest', TType.I32, 6) + oprot.writeI32(self.dest) oprot.writeFieldEnd() if self.order != None: oprot.writeFieldBegin('order', TType.I16, 7) @@ -1005,7 +1004,7 @@ class PackageInfo: - folder - site - password - - destination + - dest - order - priority - links @@ -1018,19 +1017,19 @@ class PackageInfo: (3, TType.STRING, 'folder', None, None, ), # 3 (4, TType.STRING, 'site', None, None, ), # 4 (5, TType.STRING, 'password', None, None, ), # 5 - (6, TType.I32, 'destination', None, None, ), # 6 + (6, TType.I32, 'dest', None, None, ), # 6 (7, TType.I16, 'order', None, None, ), # 7 (8, TType.BYTE, 'priority', None, None, ), # 8 (9, TType.LIST, 'links', (TType.I32,None), None, ), # 9 ) - def __init__(self, pid=None, name=None, folder=None, site=None, password=None, destination=None, order=None, priority=None, links=None,): + def __init__(self, pid=None, name=None, folder=None, site=None, password=None, dest=None, order=None, priority=None, links=None,): self.pid = pid self.name = name self.folder = folder self.site = site self.password = password - self.destination = destination + self.dest = dest self.order = order self.priority = priority self.links = links @@ -1071,7 +1070,7 @@ class PackageInfo: iprot.skip(ftype) elif fid == 6: if ftype == TType.I32: - self.destination = iprot.readI32(); + self.dest = iprot.readI32(); else: iprot.skip(ftype) elif fid == 7: @@ -1124,9 +1123,9 @@ class PackageInfo: oprot.writeFieldBegin('password', TType.STRING, 5) oprot.writeString(self.password) oprot.writeFieldEnd() - if self.destination != None: - oprot.writeFieldBegin('destination', TType.I32, 6) - oprot.writeI32(self.destination) + if self.dest != None: + oprot.writeFieldBegin('dest', TType.I32, 6) + oprot.writeI32(self.dest) oprot.writeFieldEnd() if self.order != None: oprot.writeFieldBegin('order', TType.I16, 7) diff --git a/module/web/json_app.py b/module/web/json_app.py index 12b7fa8ce..f10c09498 100644 --- a/module/web/json_app.py +++ b/module/web/json_app.py @@ -212,7 +212,8 @@ def link_order(ids): def add_package(): name = request.forms['add_name'] queue = int(request.forms['add_dest']) - links = request.forms['add_links'].split("\n") + links = request.forms['add_links'].decode("utf8", "ignore") + links = links.split("\n") pw = request.forms.get("add_password", "").strip("\n\r") try: @@ -232,11 +233,14 @@ def add_package(): if name is None or name == "": return HTTPError() + name = name.decode("utf8", "ignore") + links = map(lambda x: x.strip(), links) links = filter(lambda x: x != "", links) pack = PYLOAD.add_package(name, links, queue) if pw: + pw = pw.decode("utf8", "ignore") data = {"password": pw} PYLOAD.set_package_data(pack, data) |