summaryrefslogtreecommitdiffstats
path: root/module/remote/socketbackend
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-02-16 10:46:28 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-02-16 10:46:28 +0100
commitce1c2b6b05c08b669357947e61ae40efce7fc50f (patch)
tree0b5f7996960cf35c4eface53a89eba18a37519b7 /module/remote/socketbackend
parentFix filename case (diff)
downloadpyload-ce1c2b6b05c08b669357947e61ae40efce7fc50f.tar.xz
module temp
Diffstat (limited to 'module/remote/socketbackend')
-rw-r--r--module/remote/socketbackend/__init__.py1
-rw-r--r--module/remote/socketbackend/create_ttypes.py88
2 files changed, 89 insertions, 0 deletions
diff --git a/module/remote/socketbackend/__init__.py b/module/remote/socketbackend/__init__.py
new file mode 100644
index 000000000..40a96afc6
--- /dev/null
+++ b/module/remote/socketbackend/__init__.py
@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-
diff --git a/module/remote/socketbackend/create_ttypes.py b/module/remote/socketbackend/create_ttypes.py
new file mode 100644
index 000000000..5bfbcafa0
--- /dev/null
+++ b/module/remote/socketbackend/create_ttypes.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+
+import inspect
+import os
+import platform
+import sys
+
+
+if "64" in platform.machine():
+ sys.path.append(os.path.join(pypath, "lib64"))
+sys.path.append(os.path.join(pypath, "lib"))
+
+sys.path.append(os.path.join(pypath, "pyload", "remote"))
+
+from pyload.remote.thriftbackend.thriftgen.pyload import ttypes
+from pyload.remote.thriftbackend.thriftgen.pyload.Pyload import Iface
+
+
+def main():
+
+ enums = []
+ classes = []
+
+ print "generating lightweight ttypes.py"
+
+ for name in dir(ttypes):
+ klass = getattr(ttypes, name)
+
+ if name in ("TBase", "TExceptionBase") or name.startswith("_") or not (issubclass(klass, ttypes.TBase) or issubclass(klass, ttypes.TExceptionBase)):
+ continue
+
+ if hasattr(klass, "thrift_spec"):
+ classes.append(klass)
+ else:
+ enums.append(klass)
+
+
+ f = open(os.path.join(pypath, "pyload", "api", "types.py"), "wb")
+
+ f.write(
+ """# -*- coding: utf-8 -*-
+# Autogenerated by pyload
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+
+class BaseObject(object):
+\t__slots__ = []
+
+""")
+
+ ## generate enums
+ for enum in enums:
+ name = enum.__name__
+ f.write("class %s:\n" % name)
+
+ for attr in dir(enum):
+ if attr.startswith("_") or attr in ("read", "write"): continue
+
+ f.write("\t%s = %s\n" % (attr, getattr(enum, attr)))
+
+ f.write("\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__)
+
+ #create init
+ args = ["self"] + ["%s=None" % x for x in klass.__slots__]
+
+ f.write("\tdef __init__(%s):\n" % ", ".join(args))
+ for attr in klass.__slots__:
+ f.write("\t\tself.%s = %s\n" % (attr, attr))
+
+ f.write("\n")
+
+ f.write("class Iface(object):\n")
+
+ for name in dir(Iface):
+ if name.startswith("_"): continue
+
+ func = inspect.getargspec(getattr(Iface, name))
+
+ f.write("\tdef %s(%s):\n\t\tpass\n" % (name, ", ".join(func.args)))
+
+ f.write("\n")
+
+ f.close()