diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-14 14:26:29 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-14 14:26:29 +0100 |
commit | e811e55a8e8e451c6fc7b723f26a6351f997a14e (patch) | |
tree | 026b350bd54b40aa73ec115ff9b83800351e1a8d /module/remote/thriftbackend | |
parent | little SO fix (diff) | |
download | pyload-e811e55a8e8e451c6fc7b723f26a6351f997a14e.tar.xz |
some parts of cli working again
Diffstat (limited to 'module/remote/thriftbackend')
-rw-r--r-- | module/remote/thriftbackend/Handler.py | 8 | ||||
-rw-r--r-- | module/remote/thriftbackend/ThriftClient.py | 5 | ||||
-rw-r--r-- | module/remote/thriftbackend/pyload.thrift | 13 | ||||
-rw-r--r-- | module/remote/thriftbackend/thriftgen/pyload/Pyload.py | 44 | ||||
-rw-r--r-- | module/remote/thriftbackend/thriftgen/pyload/ttypes.py | 124 |
5 files changed, 186 insertions, 8 deletions
diff --git a/module/remote/thriftbackend/Handler.py b/module/remote/thriftbackend/Handler.py index 91848941b..b1a7349bc 100644 --- a/module/remote/thriftbackend/Handler.py +++ b/module/remote/thriftbackend/Handler.py @@ -74,7 +74,7 @@ class Handler(Iface): self.serverMethods.unpause_server() def togglePause(self): - return self.serverMethods.toggle_server() + return self.serverMethods.toggle_pause() def statusServer(self): status = self.serverMethods.status_server() @@ -172,6 +172,9 @@ class Handler(Iface): pdata = PackageData() rawData = self.serverMethods.get_package_data(pid) + if not rawData: + raise PackageDoesNotExists(pid) + pdata.pid = rawData["id"] pdata.name = rawData["name"] pdata.folder = rawData["folder"] @@ -195,7 +198,8 @@ class Handler(Iface): if rawData: rawData = rawData.values()[0] else: - return None + raise FileDoesNotExists(fid) + fdata = self._convertPyFile(rawData) return fdata diff --git a/module/remote/thriftbackend/ThriftClient.py b/module/remote/thriftbackend/ThriftClient.py index 16bba7d1f..c6a48df2b 100644 --- a/module/remote/thriftbackend/ThriftClient.py +++ b/module/remote/thriftbackend/ThriftClient.py @@ -14,6 +14,11 @@ from Socket import Socket from Protocol import Protocol from thriftgen.pyload import Pyload +from thriftgen.pyload.Pyload import PackageDoesNotExists +from thriftgen.pyload.Pyload import FileDoesNotExists + + +ConnectionClosed = TTransport.TTransportException class WrongLogin(Exception): pass diff --git a/module/remote/thriftbackend/pyload.thrift b/module/remote/thriftbackend/pyload.thrift index 3cbd62d7a..a8c295339 100644 --- a/module/remote/thriftbackend/pyload.thrift +++ b/module/remote/thriftbackend/pyload.thrift @@ -151,6 +151,15 @@ struct AccountData { 4: optional map<string, string> options } +exception PackageDoesNotExists{ + 1: PackageID pid +} + +exception FileDoesNotExists{ + 1: FileID fid +} + + service Pyload { //general string getConfigValue(1: string category, 2: string option, 3: string section), @@ -173,8 +182,8 @@ service Pyload { //downloads list<DownloadInfo> statusDownloads(), PackageID addPackage(1: string name, 2: LinkList links, 3: Destination dest), - PackageData getPackageData(1: PackageID pid), - FileData getFileData(1: FileID fid), + PackageData getPackageData(1: PackageID pid) throws (1: PackageDoesNotExists e), + FileData getFileData(1: FileID fid) throws (1: FileDoesNotExists e), void deleteFiles(1: list<FileID> fids), void deletePackages(1: list<PackageID> pids), list<PackageInfo> getQueue(), diff --git a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py index 19e972559..7c2372745 100644 --- a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py +++ b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py @@ -843,6 +843,8 @@ class Client(Iface): self._iprot.readMessageEnd() if result.success != None: return result.success + if result.e != None: + raise result.e raise TApplicationException(TApplicationException.MISSING_RESULT, "getPackageData failed: unknown result"); def getFileData(self, fid): @@ -873,6 +875,8 @@ class Client(Iface): self._iprot.readMessageEnd() if result.success != None: return result.success + if result.e != None: + raise result.e raise TApplicationException(TApplicationException.MISSING_RESULT, "getFileData failed: unknown result"); def deleteFiles(self, fids): @@ -2111,7 +2115,10 @@ class Processor(Iface, TProcessor): args.read(iprot) iprot.readMessageEnd() result = getPackageData_result() - result.success = self._handler.getPackageData(args.pid) + try: + result.success = self._handler.getPackageData(args.pid) + except PackageDoesNotExists, e: + result.e = e oprot.writeMessageBegin("getPackageData", TMessageType.REPLY, seqid) result.write(oprot) oprot.writeMessageEnd() @@ -2122,7 +2129,10 @@ class Processor(Iface, TProcessor): args.read(iprot) iprot.readMessageEnd() result = getFileData_result() - result.success = self._handler.getFileData(args.fid) + try: + result.success = self._handler.getFileData(args.fid) + except FileDoesNotExists, e: + result.e = e oprot.writeMessageBegin("getFileData", TMessageType.REPLY, seqid) result.write(oprot) oprot.writeMessageEnd() @@ -4501,14 +4511,17 @@ class getPackageData_result: """ Attributes: - success + - e """ thrift_spec = ( (0, TType.STRUCT, 'success', (PackageData, PackageData.thrift_spec), None, ), # 0 + (1, TType.STRUCT, 'e', (PackageDoesNotExists, PackageDoesNotExists.thrift_spec), None, ), # 1 ) - def __init__(self, success=None,): + def __init__(self, success=None, e=None,): self.success = success + self.e = e 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: @@ -4525,6 +4538,12 @@ class getPackageData_result: self.success.read(iprot) else: iprot.skip(ftype) + elif fid == 1: + if ftype == TType.STRUCT: + self.e = PackageDoesNotExists() + self.e.read(iprot) + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -4539,6 +4558,10 @@ class getPackageData_result: oprot.writeFieldBegin('success', TType.STRUCT, 0) self.success.write(oprot) oprot.writeFieldEnd() + if self.e != None: + oprot.writeFieldBegin('e', TType.STRUCT, 1) + self.e.write(oprot) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() def validate(self): @@ -4619,14 +4642,17 @@ class getFileData_result: """ Attributes: - success + - e """ thrift_spec = ( (0, TType.STRUCT, 'success', (FileData, FileData.thrift_spec), None, ), # 0 + (1, TType.STRUCT, 'e', (FileDoesNotExists, FileDoesNotExists.thrift_spec), None, ), # 1 ) - def __init__(self, success=None,): + def __init__(self, success=None, e=None,): self.success = success + self.e = e 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: @@ -4643,6 +4669,12 @@ class getFileData_result: self.success.read(iprot) else: iprot.skip(ftype) + elif fid == 1: + if ftype == TType.STRUCT: + self.e = FileDoesNotExists() + self.e.read(iprot) + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -4657,6 +4689,10 @@ class getFileData_result: oprot.writeFieldBegin('success', TType.STRUCT, 0) self.success.write(oprot) oprot.writeFieldEnd() + if self.e != None: + oprot.writeFieldBegin('e', TType.STRUCT, 1) + self.e.write(oprot) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() def validate(self): diff --git a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py index 10964d127..370858d4e 100644 --- a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py +++ b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py @@ -1689,3 +1689,127 @@ class AccountData: def __ne__(self, other): return not (self == other) + +class PackageDoesNotExists(Exception): + """ + Attributes: + - pid + """ + + thrift_spec = ( + None, # 0 + (1, TType.I32, 'pid', None, None, ), # 1 + ) + + def __init__(self, pid=None,): + self.pid = pid + + 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 == 1: + if ftype == TType.I32: + self.pid = iprot.readI32(); + 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('PackageDoesNotExists') + if self.pid != None: + oprot.writeFieldBegin('pid', TType.I32, 1) + oprot.writeI32(self.pid) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + def validate(self): + return + + + def __str__(self): + return repr(self) + + 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 FileDoesNotExists(Exception): + """ + Attributes: + - fid + """ + + thrift_spec = ( + None, # 0 + (1, TType.I32, 'fid', None, None, ), # 1 + ) + + def __init__(self, fid=None,): + self.fid = fid + + 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 == 1: + if ftype == TType.I32: + self.fid = iprot.readI32(); + 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('FileDoesNotExists') + if self.fid != None: + oprot.writeFieldBegin('fid', TType.I32, 1) + oprot.writeI32(self.fid) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + def validate(self): + return + + + def __str__(self): + return repr(self) + + 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) |