From a8d50bb699dee60142de04ca271fb29b780c4488 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 16 Feb 2016 21:11:56 +0300 Subject: [PATCH] Start --- .gitignore | 2 ++ src/profile.py | 0 src/settings.py | 22 ++++++++++++++++++++++ src/tox.py | 39 +++++++++++++++++++++++++++++++++++++++ tests/tests.py | 0 5 files changed, 63 insertions(+) create mode 100644 src/profile.py create mode 100644 src/settings.py create mode 100644 src/tox.py create mode 100644 tests/tests.py diff --git a/.gitignore b/.gitignore index 8509765..9b7a72c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.ui src/toxcore src/libs +.idea +*~ diff --git a/src/profile.py b/src/profile.py new file mode 100644 index 0000000..e69de29 diff --git a/src/settings.py b/src/settings.py new file mode 100644 index 0000000..5cfd85d --- /dev/null +++ b/src/settings.py @@ -0,0 +1,22 @@ +import getpass +import platform +import json + + +class Settings(object): + + def __init__(self): + path = Settings.get_default_path() + 'toxygen.json' + with open(path) as fl: + data = fl.read() + self.data = json.loads(data) + + def __get__(self, attr): + return self.data[attr] + + @staticmethod + def get_default_path(): + name = platform.system() + if name == 'Linux': + user = getpass.getuser() + return '/home/{}/.config/tox/'.format(user) diff --git a/src/tox.py b/src/tox.py new file mode 100644 index 0000000..792ac45 --- /dev/null +++ b/src/tox.py @@ -0,0 +1,39 @@ +from ctypes import * +from settings import Settings + + +class ToxOptions(Structure): + _fields_ = [ + ("ipv6_enabled", c_bool), + ("udp_enabled", c_bool), + ("proxy_type", c_int), + ("proxy_host", c_char_p), + ("proxy_port", c_uint16), + ("start_port", c_uint16), + ("end_port", c_uint16), + ("tcp_port", c_uint16), + ("savedata_type", c_int), + ("savedata_data", POINTER(c_uint8)), + ("savedata_length", c_size_t) + ] + + +class Tox(object): + + def __init__(self, name): + path = Settings.get_default_path() + name + '.tox' + with open(path, 'rb') as fl: + data = fl.read() + size = len(data) + print size + libtoxcore = CDLL('libtoxcore.so') + libtoxcore.tox_options_new.restype = POINTER(ToxOptions) + self.tox_options = libtoxcore.tox_options_new(0) + libtoxcore.tox_new.restype = POINTER(c_void_p) + tox = libtoxcore.tox_new(None, None) + self.libtoxcore = libtoxcore + +if __name__ == "__main__": + t = Tox('tox_save') + + diff --git a/tests/tests.py b/tests/tests.py new file mode 100644 index 0000000..e69de29