diff --git a/README.md b/README.md index 4054441..92af911 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -### File bot +###File bot A bot which allows you to easily share files with friends and family using [Tox](https://tox.chat/) Based on [toxygen](https://github.com/xveduk/toxygen/) toxcore wrapper @@ -8,25 +8,17 @@ Based on [toxygen](https://github.com/xveduk/toxygen/) toxcore wrapper - Windows - Linux -# Install: +#Install: ### Windows 1. [Download and install latest Python 2.7](https://www.python.org/downloads/windows/) 2. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip) -3. Unpack archive -4. Download latest libtox.dll build, download latest libsodium.a build, put it into \libs\ +3. Unpack archive +4. Download latest [libtox.dll](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86_shared_release.zip) build, download latest [libsodium.a](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86_static_release.zip) build, put it into libs\ 5. Run app: ``python main.py path_to_profile`` -[libtox.dll for 32-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86_shared_release.zip) - -[libtox.dll for 64-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86-64_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86-64_shared_release.zip) - -[libsodium.a for 32-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86_static_release.zip) - -[libsodium.a for 64-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86-64_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86-64_static_release.zip) - ### Linux @@ -37,8 +29,7 @@ Based on [toxygen](https://github.com/xveduk/toxygen/) toxcore wrapper 5. Run app: ``python main.py path_to_profile`` -# Commands: -``` +#Commands: help - list of commands rights - get access rights @@ -75,18 +66,5 @@ message --all - send message to all friends (masters only) stop - stop bot (masters only) -fsize - sets size of shared folder (masters only) -``` - Users with write access can send files to bot. - -Users with delete access can delete and rename files. - -Example of settings is [here](/settings.json) - -## Hard Fork - -https://git.plastiras.org/emdee/filebot - -Work on this project is suspended until the MultiDevice problem is solved. diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/bootstrap.py b/bootstrap.py index fd6446d..340af37 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -1,19 +1,9 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- import random -global LOG -import logging -LOG = logging.getLogger(__name__) - -iNUM_NODES = 6 class Node(object): - - def __init__(self, ip, port, tox_key, rand=0): - self._ip = ip - self._port = port - self._tox_key = tox_key - self.rand = rand + def __init__(self, ip, port, tox_key, rand): + self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand def get_data(self): return self._ip, self._port, self._tox_key @@ -21,16 +11,6 @@ class Node(object): def node_generator(): nodes = [] - try: - from wrapper_tests.support_testing import generate_nodes - all = generate_nodes() - random.shuffle(all) - for elt in all[:iNUM_NODES]: - nodes.append(Node(*elt)) - return nodes - except Exception as e: - LOG.warn(e) - # drop through ips = [ "144.76.60.215", "23.226.230.47", "195.154.119.113", "biribiri.org", "46.38.239.179", "178.62.250.138", "130.133.110.14", "104.167.101.29", @@ -95,9 +75,13 @@ def node_generator(): "5625A62618CB4FCA70E147A71B29695F38CC65FF0CBD68AD46254585BE564802", "31910C0497D347FF160D6F3A6C0E317BAFA71E8E03BC4CBB2A185C9D4FB8B31E" ] - for i in range(len(ips)): - nodes.append(Node(ips[i], ports[i], ids[i]) ) - arr = sorted(nodes) - random.shuffle(arr) - for elem in arr[:iNUM_NODES]: + for i in xrange(len(ips)): + nodes.append(Node(ips[i], ports[i], ids[i], random.randint(0, 1000000))) + arr = sorted(nodes, key=lambda x: x.rand)[:4] + for elem in arr: yield elem.get_data() + + +if __name__ == "__main__": + for elem in node_generator(): + print str(elem) diff --git a/bot.py b/bot.py index d03e84a..b11740a 100644 --- a/bot.py +++ b/bot.py @@ -1,16 +1,12 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- -from wrapper.tox import Tox +from tox import Tox import os from settings import * -from wrapper.toxcore_enums_and_consts import * +from toxcore_enums_and_consts import * from ctypes import * -from util import Singleton, folder_size +from util import log, Singleton from file_transfers import * from collections import defaultdict -global LOG -import logging -LOG = logging.getLogger(__name__) class Bot(Singleton): @@ -54,7 +50,7 @@ class Bot(Singleton): elif '.' in last_part: index = last_part.index('.') else: - index = TOX_MAX_MESSAGE_LENGTH - size - 1 + index = TOX_MAX_MESSAGE_LENGTH - size index += size + 1 self._tox.friend_send_message(number, message_type, message[:index]) message = message[index:] @@ -66,7 +62,7 @@ class Bot(Singleton): :param friend_num: number of friend who sent message :param message: text of message """ - id = self._tox.friend_get_public_key(friend_num) # public key of user + id = self._tox.friend_get_public_key(friend_num) settings = Settings.get_instance() message = message.strip() # message parsing @@ -116,7 +112,6 @@ class Bot(Singleton): message - send message to friend (masters only)\n message --all - send message to all friends (masters only)\n stop - stop bot (masters only)\n - fsize - set folder size in MB (masters only)\n Users with write access can send files to bot. """.encode('utf-8')) elif message == 'rights': # get rights @@ -178,10 +173,10 @@ class Bot(Singleton): fl = ' '.join(message.split(' ')[2:]) try: num = self._tox.friend_by_public_key(message.split(' ')[1][:TOX_PUBLIC_KEY_SIZE * 2]) - LOG.debug(num) + print num self.send_file(settings['folder'] + '/' + fl, num) except Exception as ex: - LOG.warn(ex) + print ex self.send_message(friend_num, 'Friend not found'.encode('utf-8')) else: fl = ' '.join(message.split(' ')[2:]) @@ -221,7 +216,7 @@ class Bot(Singleton): elif bytes_size < 1024 * 1024: size = u'{} KB'.format(bytes_size / 1024) else: - size = u'{} MB'.format(bytes_size / (1024 * 1024)) + size = u'{} MB'.format(bytes_size / 1024 * 1024) s = u'Size: {} ({} bytes)'.format(size, bytes_size) self.send_message(friend_num, s.encode('utf-8')) elif message.startswith('message '): # send message to friend (all friends) @@ -269,17 +264,6 @@ class Bot(Singleton): raise SystemExit() else: self.send_message(friend_num, 'Not enough rights'.encode('utf-8')) - elif message.startswith('fsize '): - if id not in settings['master']: - self.send_message(friend_num, 'Not enough rights'.encode('utf-8')) - else: - try: - size = int(message[6:]) - settings['size'] = max(size, 10) - settings.save() - self.send_message(friend_num, 'Size was set'.encode('utf-8')) - except: - self.send_message(friend_num, 'Wrong command'.encode('utf-8')) else: self.send_message(friend_num, 'Wrong command'.encode('utf-8')) @@ -293,7 +277,6 @@ class Bot(Singleton): :param tox_id: tox id of contact :param message: message """ - LOG.info('Friend request:' +message) self._tox.friend_add_norequest(tox_id) settings = Settings.get_instance() # give friend default rights @@ -306,8 +289,6 @@ class Bot(Singleton): if 'm' in settings['auto_rights'] and tox_id not in settings['master']: settings['master'].append(tox_id) settings.save() - data = self._tox.get_savedata() - ProfileHelper.save_profile(data) # ----------------------------------------------------------------------------------------------------------------- # File transfers support @@ -323,9 +304,7 @@ class Bot(Singleton): """ id = self._tox.friend_get_public_key(friend_number) settings = Settings.get_instance() - fsize = folder_size(settings['folder']) + size - max_folder_size = settings['size'] * 1024 * 1024 - if id in settings['write'] and fsize <= max_folder_size: + if id in settings['write']: path = settings['folder'] new_file_name, i = file_name, 1 while os.path.isfile(path + '/' + new_file_name): # file with same name already exists @@ -399,28 +378,16 @@ def tox_factory(data=None, settings=None): :return: new tox instance """ if settings is None: - if os.getenv('socks_proxy') != '': - settings = { - 'ipv6_enabled': False, - 'udp_enabled': False, - 'proxy_type': 2, - 'proxy_host': b'127.0.0.1', - 'proxy_port': 9050, - 'start_port': 0, - 'end_port': 0, - 'tcp_port': 0 - } - else: - settings = { - 'ipv6_enabled': True, - 'udp_enabled': True, - 'proxy_type': 0, - 'proxy_host': '0', - 'proxy_port': 0, - 'start_port': 0, - 'end_port': 0, - 'tcp_port': 0 - } + settings = { + 'ipv6_enabled': True, + 'udp_enabled': True, + 'proxy_type': 0, + 'proxy_host': '0', + 'proxy_port': 0, + 'start_port': 0, + 'end_port': 0, + 'tcp_port': 0 + } tox_options = Tox.options_new() tox_options.contents.udp_enabled = settings['udp_enabled'] tox_options.contents.proxy_type = settings['proxy_type'] @@ -437,11 +404,4 @@ def tox_factory(data=None, settings=None): tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['NONE'] tox_options.contents.savedata_data = None tox_options.contents.savedata_length = 0 - # overrides - tox_options.contents.local_discovery_enabled = False - tox_options.contents.ipv6_enabled = False - tox_options.contents.hole_punching_enabled = False - - LOG.debug("wrapper.tox.Tox settings: " +repr(settings)) - return Tox(tox_options) diff --git a/callbacks.py b/callbacks.py index 9dcf2c1..31602fa 100644 --- a/callbacks.py +++ b/callbacks.py @@ -1,12 +1,8 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- from settings import Settings from bot import Bot -from wrapper.toxcore_enums_and_consts import * -from wrapper.tox import bin_to_string +from toxcore_enums_and_consts import * +from tox import bin_to_string -global LOG -import logging -LOG = logging.getLogger(__name__) # ----------------------------------------------------------------------------------------------------------------- # Callbacks - current user @@ -18,7 +14,7 @@ def self_connection_status(): Current user changed connection status (offline, UDP, TCP) """ def wrapped(tox, connection, user_data): - LOG.debug('Connection status: ' + str(connection)) + print 'Connection status: ', str(connection) return wrapped @@ -31,7 +27,7 @@ def friend_connection_status(tox, friend_num, new_status, user_data): """ Check friend's connection status (offline, udp, tcp) """ - LOG.info("Friend #{} connected! Friend's status: {}".format(friend_num, new_status)) + print "Friend #{} connected! Friend's status: {}".format(friend_num, new_status) def friend_message(): @@ -39,7 +35,7 @@ def friend_message(): New message from friend """ def wrapped(tox, friend_number, message_type, message, size, user_data): - LOG.info(message.decode('utf-8')) + print message.decode('utf-8') Bot.get_instance().new_message(friend_number, message.decode('utf-8')) # parse message return wrapped @@ -66,7 +62,7 @@ def tox_file_recv(tox_link): def wrapped(tox, friend_number, file_number, file_type, size, file_name, file_name_size, user_data): profile = Bot.get_instance() if file_type == TOX_FILE_KIND['DATA']: - LOG.info('file') + print 'file' file_name = unicode(file_name[:file_name_size].decode('utf-8')) profile.incoming_file_transfer(friend_number, file_number, size, file_name) else: # AVATAR @@ -113,13 +109,13 @@ def init_callbacks(tox): Initialization of all callbacks. :param tox: tox instance """ - tox.callback_self_connection_status(self_connection_status()) + tox.callback_self_connection_status(self_connection_status(), 0) - tox.callback_friend_message(friend_message()) - tox.callback_friend_connection_status(friend_connection_status) - tox.callback_friend_request(friend_request) + tox.callback_friend_message(friend_message(), 0) + tox.callback_friend_connection_status(friend_connection_status, 0) + tox.callback_friend_request(friend_request, 0) - tox.callback_file_recv(tox_file_recv(tox)) - tox.callback_file_recv_chunk(file_recv_chunk) - tox.callback_file_chunk_request(file_chunk_request) - tox.callback_file_recv_control(file_recv_control) + tox.callback_file_recv(tox_file_recv(tox), 0) + tox.callback_file_recv_chunk(file_recv_chunk, 0) + tox.callback_file_chunk_request(file_chunk_request, 0) + tox.callback_file_recv_control(file_recv_control, 0) diff --git a/file_transfers.py b/file_transfers.py index 2a67750..32aebcc 100644 --- a/file_transfers.py +++ b/file_transfers.py @@ -1,9 +1,8 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- -from wrapper.toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL +from toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL from os.path import basename, getsize from os import remove from time import time -from wrapper.tox import Tox +from tox import Tox TOX_FILE_TRANSFER_STATE = { @@ -26,7 +25,7 @@ class FileTransfer(object): self.state = TOX_FILE_TRANSFER_STATE['RUNNING'] self._file_number = file_number self._creation_time = time() - self._size = size + self._size = float(size) self._done = 0 def set_tox(self, tox): @@ -124,6 +123,3 @@ class ReceiveTransfer(FileTransfer): if position + l > self._file_size: self._file_size = position + l self._done += l - if self._done > self._size: - self.cancel() - remove(self._path) diff --git a/main.py b/main.py index 988cb12..2006605 100644 --- a/main.py +++ b/main.py @@ -1,40 +1,9 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- - -""" - help - list of commands\n - rights - get access rights\n - files - show list of files (get access)\n - id - get bot's id (get access)\n - share - send file to friend (get access)\n - share --all - send file to all friends (get access)\n - size - get size of file (get access)\n - get - get file with specified filename (get access)\n - get --all - get all files (get access)\n - stats - show statistics (write access)\n - del - remove file with specified filename (delete access)\n - rename --new - rename file (delete access)\n - user - new rights (example: rwdm) for user (masters only)\n - status - new status message (masters only)\n - name - new name (masters only)\n - message - send message to friend (masters only)\n - message --all - send message to all friends (masters only)\n - stop - stop bot (masters only)\n - fsize - set folder size in MB (masters only)\n - Users with write access can send files to bot. -""" - +from bootstrap import node_generator +from bot import * +from callbacks import init_callbacks import time import sys -from bootstrap import node_generator -from bot import Bot, tox_factory, ProfileHelper -from callbacks import init_callbacks -from settings import Settings - -global LOG -import logging -logging.basicConfig(level=10) -LOG = logging.getLogger(__name__) class FileBot(object): @@ -44,7 +13,7 @@ class FileBot(object): self.stop = False self.profile = None self.path = path - LOG.info('FileBot v0.1.2+') + print 'FileBot v0.1' def main(self): self.tox = tox_factory(ProfileHelper.open_profile(self.path)) @@ -54,7 +23,7 @@ class FileBot(object): self.tox.bootstrap(*data) settings = Settings() self.profile = Bot(self.tox) - LOG.debug('Iterate') + print 'Iterate' try: while not self.stop: self.tox.iterate() @@ -67,9 +36,10 @@ class FileBot(object): if __name__ == '__main__': - if len(sys.argv) <= 1: + if len(sys.argv) > 1: + path = sys.argv[1] + bot = FileBot(path) + bot.main() + else: raise IOError('Path to save file not found') - path = sys.argv[1] - bot = FileBot(path) - bot.main() diff --git a/settings.json b/settings.json index 626efa6..110e102 100644 --- a/settings.json +++ b/settings.json @@ -1 +1 @@ -{"write": ["56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855"], "auto_rights": "r", "master": [], "read": ["56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855"], "folder": "/home/tox_user/tox/shared", "size": 500, "delete": ["56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855"]} +{"write": ["56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855"], "auto_rights": "r", "master": [], "read": ["56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855"], "folder": "/home/tox_user/tox/shared", "delete": ["56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855"]} \ No newline at end of file diff --git a/settings.py b/settings.py index b0c9962..4b1db2d 100644 --- a/settings.py +++ b/settings.py @@ -1,28 +1,25 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- +from platform import system import json import os import locale from util import Singleton, curr_directory -from wrapper.toxcore_enums_and_consts import * +from toxcore_enums_and_consts import * -global LOG -import logging -LOG = logging.getLogger(__name__) class Settings(Singleton, dict): def __init__(self): - self.path = os.path.join(curr_directory(), 'settings.json') + self.path = curr_directory() + '/settings.json' if os.path.isfile(self.path): with open(self.path) as fl: data = fl.read() super(self.__class__, self).__init__(json.loads(data)) else: super(self.__class__, self).__init__(Settings.get_default_settings()) - self['read'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['read']))) - self['write'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['write']))) - self['delete'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['delete']))) - self['master'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['master']))) + self['read'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['read'])) + self['write'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['write'])) + self['delete'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['delete'])) + self['master'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['master'])) if self['folder'][-1] == '/' or self['folder'][-1] == '\\': self['folder'] = self['folder'][:-1] self.save() @@ -35,13 +32,11 @@ class Settings(Singleton, dict): 'delete': [], 'master': [], 'folder': curr_directory(), - 'folder_save': curr_directory(), - 'auto_rights': 'r', - 'size': 500 + 'auto_rights': 'r' } def save(self): - LOG.debug('Saving') + print 'Saving' text = json.dumps(self) with open(self.path, 'w') as fl: fl.write(text) @@ -54,6 +49,7 @@ class ProfileHelper(object): @staticmethod def open_profile(path): + path = path.decode(locale.getpreferredencoding()) ProfileHelper._path = path with open(ProfileHelper._path, 'rb') as fl: data = fl.read() diff --git a/tox.py.dst b/tox.py similarity index 97% rename from tox.py.dst rename to tox.py index 68fbc42..c28fa14 100644 --- a/tox.py.dst +++ b/tox.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from ctypes import c_char_p, Structure, CDLL, c_bool, byref, c_int, c_size_t, POINTER, c_uint16, c_void_p, c_uint64 +from ctypes import c_char_p, Structure, CDLL, c_bool, addressof, c_int, c_size_t, POINTER, c_uint16, c_void_p, c_uint64 from ctypes import create_string_buffer, ArgumentError, CFUNCTYPE, c_uint32, sizeof, c_uint8 from platform import system from toxcore_enums_and_consts import * @@ -62,7 +62,7 @@ class Tox(object): else: tox_err_new = c_int() Tox.libtoxcore.tox_new.restype = POINTER(c_void_p) - self._tox_pointer = Tox.libtoxcore.tox_new(tox_options, byref(tox_err_new)) + self._tox_pointer = Tox.libtoxcore.tox_new(tox_options, addressof(tox_err_new)) tox_err_new = tox_err_new.value if tox_err_new == TOX_ERR_NEW['NULL']: raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') @@ -138,7 +138,7 @@ class Tox(object): tox_err_options_new = c_int() f = Tox.libtoxcore.tox_options_new f.restype = POINTER(ToxOptions) - result = f(byref(tox_err_options_new)) + result = f(addressof(tox_err_options_new)) tox_err_options_new = tox_err_options_new.value if tox_err_options_new == TOX_ERR_OPTIONS_NEW['OK']: return result @@ -202,7 +202,7 @@ class Tox(object): """ tox_err_bootstrap = c_int() result = Tox.libtoxcore.tox_bootstrap(self._tox_pointer, c_char_p(address), c_uint16(port), - string_to_bin(public_key), byref(tox_err_bootstrap)) + string_to_bin(public_key), addressof(tox_err_bootstrap)) tox_err_bootstrap = tox_err_bootstrap.value if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']: return bool(result) @@ -228,7 +228,7 @@ class Tox(object): """ tox_err_bootstrap = c_int() result = Tox.libtoxcore.tox_add_tcp_relay(self._tox_pointer, c_char_p(address), c_uint16(port), - c_char_p(public_key), byref(tox_err_bootstrap)) + c_char_p(public_key), addressof(tox_err_bootstrap)) tox_err_bootstrap = tox_err_bootstrap.value if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']: return bool(result) @@ -355,7 +355,7 @@ class Tox(object): """ tox_err_set_info = c_int() result = Tox.libtoxcore.tox_self_set_name(self._tox_pointer, c_char_p(name), - c_size_t(len(name)), byref(tox_err_set_info)) + c_size_t(len(name)), addressof(tox_err_set_info)) tox_err_set_info = tox_err_set_info.value if tox_err_set_info == TOX_ERR_SET_INFO['OK']: return bool(result) @@ -403,7 +403,7 @@ class Tox(object): """ tox_err_set_info = c_int() result = Tox.libtoxcore.tox_self_set_status_message(self._tox_pointer, c_char_p(status_message), - c_size_t(len(status_message)), byref(tox_err_set_info)) + c_size_t(len(status_message)), addressof(tox_err_set_info)) tox_err_set_info = tox_err_set_info.value if tox_err_set_info == TOX_ERR_SET_INFO['OK']: return bool(result) @@ -479,7 +479,7 @@ class Tox(object): """ tox_err_friend_add = c_int() result = Tox.libtoxcore.tox_friend_add(self._tox_pointer, string_to_bin(address), c_char_p(message), - c_size_t(len(message)), byref(tox_err_friend_add)) + c_size_t(len(message)), addressof(tox_err_friend_add)) tox_err_friend_add = tox_err_friend_add.value if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']: return result @@ -519,7 +519,7 @@ class Tox(object): """ tox_err_friend_add = c_int() result = Tox.libtoxcore.tox_friend_add_norequest(self._tox_pointer, string_to_bin(public_key), - byref(tox_err_friend_add)) + addressof(tox_err_friend_add)) tox_err_friend_add = tox_err_friend_add.value if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']: return result @@ -554,7 +554,7 @@ class Tox(object): """ tox_err_friend_delete = c_int() result = Tox.libtoxcore.tox_friend_delete(self._tox_pointer, c_uint32(friend_number), - byref(tox_err_friend_delete)) + addressof(tox_err_friend_delete)) tox_err_friend_delete = tox_err_friend_delete.value if tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['OK']: return bool(result) @@ -574,7 +574,7 @@ class Tox(object): """ tox_err_friend_by_public_key = c_int() result = Tox.libtoxcore.tox_friend_by_public_key(self._tox_pointer, string_to_bin(public_key), - byref(tox_err_friend_by_public_key)) + addressof(tox_err_friend_by_public_key)) tox_err_friend_by_public_key = tox_err_friend_by_public_key.value if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['OK']: return result @@ -629,7 +629,7 @@ class Tox(object): public_key = create_string_buffer(TOX_PUBLIC_KEY_SIZE) tox_err_friend_get_public_key = c_int() Tox.libtoxcore.tox_friend_get_public_key(self._tox_pointer, c_uint32(friend_number), public_key, - byref(tox_err_friend_get_public_key)) + addressof(tox_err_friend_get_public_key)) tox_err_friend_get_public_key = tox_err_friend_get_public_key.value if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['OK']: return bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE) @@ -646,7 +646,7 @@ class Tox(object): """ tox_err_last_online = c_int() result = Tox.libtoxcore.tox_friend_get_last_online(self._tox_pointer, c_uint32(friend_number), - byref(tox_err_last_online)) + addressof(tox_err_last_online)) tox_err_last_online = tox_err_last_online.value if tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['OK']: return result @@ -665,7 +665,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_name_size(self._tox_pointer, c_uint32(friend_number), - byref(tox_err_friend_query)) + addressof(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -691,7 +691,7 @@ class Tox(object): name = create_string_buffer(self.friend_get_name_size(friend_number)) tox_err_friend_query = c_int() Tox.libtoxcore.tox_friend_get_name(self._tox_pointer, c_uint32(friend_number), name, - byref(tox_err_friend_query)) + addressof(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return name.value.decode('utf8') @@ -727,7 +727,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_status_message_size(self._tox_pointer, c_uint32(friend_number), - byref(tox_err_friend_query)) + addressof(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -755,7 +755,7 @@ class Tox(object): status_message = create_string_buffer(self.friend_get_status_message_size(friend_number)) tox_err_friend_query = c_int() Tox.libtoxcore.tox_friend_get_status_message(self._tox_pointer, c_uint32(friend_number), status_message, - byref(tox_err_friend_query)) + addressof(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return status_message.value.decode('utf8') @@ -796,7 +796,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_status(self._tox_pointer, c_uint32(friend_number), - byref(tox_err_friend_query)) + addressof(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -835,7 +835,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_connection_status(self._tox_pointer, c_uint32(friend_number), - byref(tox_err_friend_query)) + addressof(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -875,7 +875,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_typing(self._tox_pointer, c_uint32(friend_number), - byref(tox_err_friend_query)) + addressof(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return bool(result) @@ -918,7 +918,7 @@ class Tox(object): """ tox_err_set_typing = c_int() result = Tox.libtoxcore.tox_self_set_typing(self._tox_pointer, c_uint32(friend_number), - c_bool(typing), byref(tox_err_set_typing)) + c_bool(typing), addressof(tox_err_set_typing)) tox_err_set_typing = tox_err_set_typing.value if tox_err_set_typing == TOX_ERR_SET_TYPING['OK']: return bool(result) @@ -948,7 +948,7 @@ class Tox(object): tox_err_friend_send_message = c_int() result = Tox.libtoxcore.tox_friend_send_message(self._tox_pointer, c_uint32(friend_number), c_int(message_type), c_char_p(message), c_size_t(len(message)), - byref(tox_err_friend_send_message)) + addressof(tox_err_friend_send_message)) tox_err_friend_send_message = tox_err_friend_send_message.value if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['OK']: return result @@ -1058,7 +1058,7 @@ class Tox(object): """ tox_err_file_control = c_int() result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), - c_int(control), byref(tox_err_file_control)) + c_int(control), addressof(tox_err_file_control)) tox_err_file_control = tox_err_file_control.value if tox_err_file_control == TOX_ERR_FILE_CONTROL['OK']: return bool(result) @@ -1113,7 +1113,7 @@ class Tox(object): """ tox_err_file_seek = c_int() result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), - c_uint64(position), byref(tox_err_file_seek)) + c_uint64(position), addressof(tox_err_file_seek)) tox_err_file_seek = tox_err_file_seek.value if tox_err_file_seek == TOX_ERR_FILE_SEEK['OK']: return bool(result) @@ -1143,8 +1143,8 @@ class Tox(object): if file_id is None: file_id = create_string_buffer(TOX_FILE_ID_LENGTH) tox_err_file_get = c_int() - Tox.libtoxcore.tox_get_file_id(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), file_id, - byref(tox_err_file_get)) + Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), file_id, + addressof(tox_err_file_get)) tox_err_file_get = tox_err_file_get.value if tox_err_file_get == TOX_ERR_FILE_GET['OK']: return bin_to_string(file_id, TOX_FILE_ID_LENGTH) @@ -1207,7 +1207,7 @@ class Tox(object): tox_err_file_send = c_int() result = self.libtoxcore.tox_file_send(self._tox_pointer, c_uint32(friend_number), c_uint32(kind), c_uint64(file_size), string_to_bin(file_id), c_char_p(filename), - c_size_t(len(filename)), byref(tox_err_file_send)) + c_size_t(len(filename)), addressof(tox_err_file_send)) tox_err_file_send = tox_err_file_send.value if tox_err_file_send == TOX_ERR_FILE_SEND['OK']: return result @@ -1242,7 +1242,7 @@ class Tox(object): tox_err_file_send_chunk = c_int() result = self.libtoxcore.tox_file_send_chunk(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), c_uint64(position), c_char_p(data), c_size_t(len(data)), - byref(tox_err_file_send_chunk)) + addressof(tox_err_file_send_chunk)) tox_err_file_send_chunk = tox_err_file_send_chunk.value if tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['OK']: return bool(result) @@ -1383,7 +1383,7 @@ class Tox(object): Return the UDP port this Tox instance is bound to. """ tox_err_get_port = c_int() - result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, byref(tox_err_get_port)) + result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, addressof(tox_err_get_port)) tox_err_get_port = tox_err_get_port.value if tox_err_get_port == TOX_ERR_GET_PORT['OK']: return result @@ -1396,9 +1396,17 @@ class Tox(object): relay. """ tox_err_get_port = c_int() - result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, byref(tox_err_get_port)) + result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, addressof(tox_err_get_port)) tox_err_get_port = tox_err_get_port.value if tox_err_get_port == TOX_ERR_GET_PORT['OK']: return result elif tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']: raise RuntimeError('The instance was not bound to any port.') + + +if __name__ == '__main__': + tox = Tox(Tox.options_new()) + p = tox.get_savedata() + print type(p) + print p + del tox diff --git a/toxcore_enums_and_consts.py.dst b/toxcore_enums_and_consts.py similarity index 100% rename from toxcore_enums_and_consts.py.dst rename to toxcore_enums_and_consts.py diff --git a/util.py b/util.py index 6ada7aa..7e9aae4 100644 --- a/util.py +++ b/util.py @@ -1,5 +1,3 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- - import os @@ -12,20 +10,11 @@ def curr_directory(): return os.path.dirname(os.path.realpath(__file__)) -def folder_size(path): - size = 0 - for f in os.listdir(path): - f = unicode(f) - if os.path.isfile(os.path.join(path, f)): - size += os.path.getsize(os.path.join(path, f)) - return size - - class Singleton(object): def __new__(cls, *args, **kwargs): if not hasattr(cls, '_instance'): - cls._instance = super(Singleton, cls).__new__(cls) + cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs) return cls._instance @classmethod