diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-10-12 18:30:21 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-10-12 18:30:21 +0200 |
commit | b31eae963850c0de453016c4d1ac52b411e3ecd4 (patch) | |
tree | 141bb5546be26f874eab81de57cf8f461398b4e1 /module | |
parent | refactored ws handler, generate debug information for ttypes (diff) | |
download | pyload-b31eae963850c0de453016c4d1ac52b411e3ecd4.tar.xz |
create more compact type info for testing
Diffstat (limited to 'module')
-rw-r--r-- | module/remote/create_ttypes.py | 32 | ||||
-rw-r--r-- | module/remote/ttypes_debug.py | 202 |
2 files changed, 46 insertions, 188 deletions
diff --git a/module/remote/create_ttypes.py b/module/remote/create_ttypes.py index 023db60bb..ab74a3441 100644 --- a/module/remote/create_ttypes.py +++ b/module/remote/create_ttypes.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import re import inspect import sys from os.path import abspath, dirname, join @@ -30,30 +31,33 @@ type_map = { TType.UTF8: 'unicode', } -def write_spec(attr, spec, f): +def get_spec(spec, optional=False): """ analyze the generated spec file and writes information into file """ if spec[1] == TType.STRUCT: - f.write("\t'%s': %s,\n" % (attr, spec[3][0].__name__)) + return spec[3][0].__name__ elif spec[1] == TType.LIST: if spec[3][0] == TType.STRUCT: ttype = spec[3][1][0].__name__ else: ttype = type_map[spec[3][0]] - f.write("\t'%s': (list, %s),\n" % (attr, ttype)) + return "(list, %s)" % ttype elif spec[1] == TType.MAP: if spec[3][2] == TType.STRUCT: ttype = spec[3][3][0].__name__ else: ttype = type_map[spec[3][2]] - f.write("\t'%s': (dict, %s, %s),\n" % (attr, type_map[spec[3][0]], ttype)) + return "(dict, %s, %s)" % (type_map[spec[3][0]], ttype) else: - f.write("\t'%s': %s,\n" % (attr, type_map[spec[1]])) + return type_map[spec[1]] + +optional_re = "%d: +optional +[a-z0-9<>_-]+ +%s" def main(): enums = [] classes = [] + tf = open(join(path, "pyload.thrift"), "rb").read() print "generating lightweight ttypes.py" @@ -101,28 +105,36 @@ from ttypes import *\n f.write("\n") - dev.write("classes = {\n\n") + dev.write("classes = {\n") for klass in classes: name = klass.__name__ base = "Exception" if issubclass(klass, ttypes.TExceptionBase) else "BaseObject" f.write("class %s(%s):\n" % (name, base)) f.write("\t__slots__ = %s\n\n" % klass.__slots__) - dev.write("'%s' : {\n" % name) + dev.write("\t'%s' : [" % name) #create init args = ["self"] + ["%s=None" % x for x in klass.__slots__] + specs = [] f.write("\tdef __init__(%s):\n" % ", ".join(args)) for i, attr in enumerate(klass.__slots__): f.write("\t\tself.%s = %s\n" % (attr, attr)) spec = klass.thrift_spec[i+1] + # assert correct order, so the list of types is enough for check assert spec[2] == attr - write_spec(attr, spec, dev) + # dirty way to check optional attribute, since it is not in the generated code + # can produce false positives, but these are not critical + optional = re.search(optional_re % (i+1, attr), tf, re.I) + if optional: + specs.append("(None, %s)" % get_spec(spec)) + else: + specs.append(get_spec(spec)) f.write("\n") - dev.write("},\n") + dev.write(", ".join(specs) + "],\n") dev.write("}\n\n") @@ -141,7 +153,7 @@ from ttypes import *\n dev.write("\t'%s': None,\n" % name) else: spec = spec[0] - write_spec(name, spec, dev) + dev.write("\t'%s': %s,\n" % (name, get_spec(spec))) f.write("\n") dev.write("}\n") diff --git a/module/remote/ttypes_debug.py b/module/remote/ttypes_debug.py index dca54a56a..0e5312fdc 100644 --- a/module/remote/ttypes_debug.py +++ b/module/remote/ttypes_debug.py @@ -6,184 +6,30 @@ from ttypes import * classes = { - -'AccountInfo' : { - 'plugin': basestring, - 'loginname': basestring, - 'owner': int, - 'valid': bool, - 'validuntil': int, - 'trafficleft': int, - 'maxtraffic': int, - 'premium': bool, - 'activated': bool, - 'shared': bool, - 'options': (dict, basestring, basestring), -}, -'AddonInfo' : { - 'func_name': basestring, - 'description': basestring, - 'value': basestring, -}, -'AddonService' : { - 'func_name': basestring, - 'description': basestring, - 'arguments': (list, basestring), - 'media': int, -}, -'ConfigHolder' : { - 'name': basestring, - 'label': basestring, - 'description': basestring, - 'long_description': basestring, - 'items': (list, ConfigItem), - 'info': (list, AddonInfo), - 'handler': (list, InteractionTask), -}, -'ConfigInfo' : { - 'name': basestring, - 'label': basestring, - 'description': basestring, - 'saved': bool, - 'activated': bool, -}, -'ConfigItem' : { - 'name': basestring, - 'label': basestring, - 'description': basestring, - 'type': basestring, - 'default_value': basestring, - 'value': basestring, -}, -'DownloadInfo' : { - 'url': basestring, - 'plugin': basestring, - 'hash': basestring, - 'status': int, - 'statusmsg': basestring, - 'error': basestring, -}, -'DownloadProgress' : { - 'fid': int, - 'pid': int, - 'speed': int, - 'status': int, -}, -'EventInfo' : { - 'eventname': basestring, - 'event_args': (list, basestring), -}, -'FileDoesNotExists' : { - 'fid': int, -}, -'FileInfo' : { - 'fid': int, - 'name': basestring, - 'package': int, - 'owner': int, - 'size': int, - 'status': int, - 'media': int, - 'added': int, - 'fileorder': int, - 'download': DownloadInfo, -}, -'InteractionTask' : { - 'iid': int, - 'input': int, - 'data': (list, basestring), - 'output': int, - 'default_value': basestring, - 'title': basestring, - 'description': basestring, - 'plugin': basestring, -}, -'LinkStatus' : { - 'url': basestring, - 'name': basestring, - 'plugin': basestring, - 'size': int, - 'status': int, - 'packagename': basestring, -}, -'OnlineCheck' : { - 'rid': int, - 'data': (dict, basestring, LinkStatus), -}, -'PackageDoesNotExists' : { - 'pid': int, -}, -'PackageInfo' : { - 'pid': int, - 'name': basestring, - 'folder': basestring, - 'root': int, - 'owner': int, - 'site': basestring, - 'comment': basestring, - 'password': basestring, - 'added': int, - 'tags': (list, basestring), - 'status': int, - 'packageorder': int, - 'stats': PackageStats, - 'fids': (list, int), - 'pids': (list, int), -}, -'PackageStats' : { - 'linkstotal': int, - 'linksdone': int, - 'sizetotal': int, - 'sizedone': int, -}, -'ProgressInfo' : { - 'plugin': basestring, - 'name': basestring, - 'statusmsg': basestring, - 'eta': int, - 'format_eta': basestring, - 'done': int, - 'total': int, - 'download': DownloadProgress, -}, -'ServerStatus' : { - 'pause': bool, - 'active': int, - 'queue': int, - 'total': int, - 'speed': int, - 'download': bool, - 'reconnect': bool, -}, -'ServiceDoesNotExists' : { - 'plugin': basestring, - 'func': basestring, -}, -'ServiceException' : { - 'msg': basestring, -}, -'TreeCollection' : { - 'root': PackageInfo, - 'files': (dict, int, FileInfo), - 'packages': (dict, int, PackageInfo), -}, -'UserData' : { - 'uid': int, - 'name': basestring, - 'email': basestring, - 'role': int, - 'permission': int, - 'folder': basestring, - 'traffic': int, - 'dllimit': int, - 'dlquota': basestring, - 'hddquota': int, - 'user': int, - 'templateName': basestring, -}, -'UserDoesNotExists' : { - 'user': basestring, -}, + 'AccountInfo' : [basestring, basestring, int, bool, int, int, int, bool, bool, bool, (dict, basestring, basestring)], + 'AddonInfo' : [basestring, basestring, basestring], + 'AddonService' : [basestring, basestring, (list, basestring), (None, int)], + 'ConfigHolder' : [basestring, basestring, basestring, basestring, (list, ConfigItem), (None, (list, AddonInfo)), (None, (list, InteractionTask))], + 'ConfigInfo' : [basestring, basestring, basestring, bool, bool], + 'ConfigItem' : [basestring, basestring, basestring, basestring, (None, basestring), basestring], + 'DownloadInfo' : [basestring, basestring, basestring, int, basestring, basestring], + 'DownloadProgress' : [int, int, int, int], + 'EventInfo' : [basestring, (list, basestring)], + 'FileDoesNotExists' : [int], + 'FileInfo' : [int, basestring, int, int, int, int, int, int, int, (None, DownloadInfo)], + 'InteractionTask' : [int, int, (list, basestring), int, (None, basestring), basestring, basestring, basestring], + 'LinkStatus' : [basestring, basestring, basestring, int, int, basestring], + 'OnlineCheck' : [int, (dict, basestring, LinkStatus)], + 'PackageDoesNotExists' : [int], + 'PackageInfo' : [int, basestring, basestring, int, int, basestring, basestring, basestring, int, (list, basestring), int, int, PackageStats, (list, int), (list, int)], + 'PackageStats' : [int, int, int, int], + 'ProgressInfo' : [basestring, basestring, basestring, int, basestring, int, int, (None, DownloadProgress)], + 'ServerStatus' : [bool, int, int, int, int, bool, bool], + 'ServiceDoesNotExists' : [basestring, basestring], + 'ServiceException' : [basestring], + 'TreeCollection' : [PackageInfo, (dict, int, FileInfo), (dict, int, PackageInfo)], + 'UserData' : [int, basestring, basestring, int, int, basestring, int, int, basestring, int, int, basestring], + 'UserDoesNotExists' : [basestring], } methods = { |