From 695d8e2cf996dd277a4885c55b544756814cfa0d Mon Sep 17 00:00:00 2001 From: emdee Date: Sat, 1 Oct 2022 18:44:31 +0000 Subject: [PATCH] Broke out wrapper_tests to toxygen_wrapper --- toxygen/app.py | 8 ++++---- toxygen/av/calls.py | 2 +- toxygen/bootstrap/bootstrap.py | 12 ++++-------- toxygen/contacts/contacts_manager.py | 8 ++++++-- .../file_transfers/file_transfers_handler.py | 2 +- toxygen/main.py | 2 +- toxygen/messenger/messenger.py | 4 +++- toxygen/middleware/threads.py | 2 +- toxygen/ui/av_widgets.py | 2 +- toxygen/ui/menu.py | 7 ++++--- toxygen/user_data/settings.py | 18 ++++++++++++------ 11 files changed, 38 insertions(+), 29 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index 2017cd1..e2d47c4 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -9,8 +9,8 @@ from time import sleep from gevent import monkey; monkey.patch_all(); del monkey # noqa import gevent -import tests.support_testing as ts -from tests.tests_wrapper import bootstrap_iNodeInfo +import wrapper_tests.support_testing as ts +from wrapper_tests.tests_wrapper import bootstrap_iNodeInfo from user_data import settings IDLE_PERIOD = 0.10 @@ -117,8 +117,8 @@ from contacts.group_peer_factory import GroupPeerFactory from user_data.backup_service import BackupService import styles.style # TODO: dynamic loading -from tests.support_testing import lLOCAL, lGOOD, lNEW, lRELAYS -from tests.tests_wrapper import main as oTOX_OPTIONS, iMain, ToxOptions, iNodeInfo +from wrapper_tests.support_testing import lLOCAL, lGOOD, lNEW, lRELAYS +from wrapper_tests.tests_wrapper import main as oTOX_OPTIONS, iMain, ToxOptions, iNodeInfo global iI iI = 0 diff --git a/toxygen/av/calls.py b/toxygen/av/calls.py index 92f7611..d0378a9 100644 --- a/toxygen/av/calls.py +++ b/toxygen/av/calls.py @@ -10,7 +10,7 @@ from av.call import Call import common.tox_save from utils import ui as util_ui -import tests.support_testing as ts +import wrapper_tests.support_testing as ts from middleware.threads import invoke_in_main_thread from main import sleep from middleware.threads import BaseThread diff --git a/toxygen/bootstrap/bootstrap.py b/toxygen/bootstrap/bootstrap.py index a8df3d4..a66f8c9 100644 --- a/toxygen/bootstrap/bootstrap.py +++ b/toxygen/bootstrap/bootstrap.py @@ -5,18 +5,14 @@ from utils.util import * from PyQt5 import QtNetwork from PyQt5 import QtCore try: - import requests -except ImportError: - requests = None -try: - import pycurl import certifi from io import BytesIO except ImportError: - pycurl = None + certifi = None from user_data.settings import get_user_config_path -from tests.support_testing import download_url, _get_nodes_path +from wrapper_tests.support_testing import _get_nodes_path +from wrapper_tests.support_http import download_url global LOG import logging @@ -33,7 +29,7 @@ def download_nodes_list(settings, oArgs): result = fl.read() return result LOG.debug("downloading list of nodes") - result = download_url(url, settings._app) + result = download_url(url, settings._app._settings) if not result: LOG.warn("failed downloading list of nodes") return '' diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 1c6c0f7..0234bad 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -40,8 +40,11 @@ class ContactsManager(ToxSave): self._history = history self._load_contacts() - def _log(self, s): self._ms(s) - + def _log(self, s): + try: + self._ms._log(s) + except: pass + def get_contact(self, num): if num < 0 or num >= len(self._contacts): return None @@ -431,6 +434,7 @@ class ContactsManager(ToxSave): :param message: additional message :return: True on success else error string """ + retval = '' try: message = message or 'Hello! Add me to your contact list please' if len(tox_id) == TOX_PUBLIC_KEY_SIZE * 2: # public key diff --git a/toxygen/file_transfers/file_transfers_handler.py b/toxygen/file_transfers/file_transfers_handler.py index 0c137d9..673b1fe 100644 --- a/toxygen/file_transfers/file_transfers_handler.py +++ b/toxygen/file_transfers/file_transfers_handler.py @@ -3,7 +3,7 @@ from messenger.messages import * from ui.contact_items import * import utils.util as util from common.tox_save import ToxSave -from tests.support_testing import assert_main_thread +from wrapper_tests.support_testing import assert_main_thread from copy import deepcopy # LOG=util.log diff --git a/toxygen/main.py b/toxygen/main.py index 027e3d6..fc73f97 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -12,7 +12,7 @@ faulthandler.enable() import warnings warnings.filterwarnings('ignore') -import tests.support_testing as ts +import wrapper_tests.support_testing as ts try: from trepan.interfaces import server as Mserver from trepan.api import debug diff --git a/toxygen/messenger/messenger.py b/toxygen/messenger/messenger.py index 25b3c87..08a0b67 100644 --- a/toxygen/messenger/messenger.py +++ b/toxygen/messenger/messenger.py @@ -1,7 +1,7 @@ # -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- import common.tox_save as tox_save from messenger.messages import * -from tests.support_testing import assert_main_thread +from wrapper_tests.support_testing import assert_main_thread global LOG import logging @@ -170,7 +170,9 @@ class Messenger(tox_save.ToxSave): return assert_main_thread() + # FixMe: peer_id is None? group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id) + # group_peer_contact now may be None group = self._get_group_by_number(group_number) messages = self._split_message(text.encode('utf-8')) t = util.get_unix_time() diff --git a/toxygen/middleware/threads.py b/toxygen/middleware/threads.py index ca3dbbb..c249a1c 100644 --- a/toxygen/middleware/threads.py +++ b/toxygen/middleware/threads.py @@ -6,7 +6,7 @@ from PyQt5 import QtCore from bootstrap.bootstrap import * from bootstrap.bootstrap import download_nodes_list -import tests.support_testing as ts +import wrapper_tests.support_testing as ts from utils import util if 'QtCore' in sys.modules: diff --git a/toxygen/ui/av_widgets.py b/toxygen/ui/av_widgets.py index 24e4a38..a441fb7 100644 --- a/toxygen/ui/av_widgets.py +++ b/toxygen/ui/av_widgets.py @@ -6,7 +6,7 @@ import wave from ui import widgets import utils.util as util -import tests.support_testing as ts +import wrapper_tests.support_testing as ts global LOG import logging diff --git a/toxygen/ui/menu.py b/toxygen/ui/menu.py index 8cc2d28..d08d494 100644 --- a/toxygen/ui/menu.py +++ b/toxygen/ui/menu.py @@ -7,7 +7,7 @@ from utils.util import * from ui.widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow import updater.updater as updater import utils.ui as util_ui -import tests.support_testing as ts +import wrapper_tests.support_testing as ts from user_data import settings global LOG @@ -56,9 +56,10 @@ class AddContact(CenteredWidget): self._adding = False if send is True: # request was successful - self.close() - else: # print error data + pass + elif send and type(send) == str: # print error data self.errorLabel.setText(send) + self.close() def _retranslate_ui(self): self.setWindowTitle(util_ui.tr('Add contact')) diff --git a/toxygen/user_data/settings.py b/toxygen/user_data/settings.py index b5faf21..5797a4b 100644 --- a/toxygen/user_data/settings.py +++ b/toxygen/user_data/settings.py @@ -1,7 +1,8 @@ # -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- + +import os from platform import system import json -import os from pprint import pprint from utils.util import * @@ -10,7 +11,7 @@ from common.event import Event import utils.ui as util_ui import utils.util as util_utils import user_data -import tests.support_testing as ts +import wrapper_tests.support_testing as ts global LOG import logging @@ -210,10 +211,15 @@ class Settings(dict): text = bytes(self._toxes.pass_encrypt(bytes(text, 'utf-8'))) else: text = bytes(text, 'utf-8') - with open(self._path, 'wb') as fl: - fl.write(text) - - self._settings_saved_event(text) + tmp = self._path + str(os.getpid()) + try: + with open(tmp, 'wb') as fl: + fl.write(text) + os.rename(tmp, self._path) + except Exception as e: + LOG.warn(f'Error saving to {self._path} ' +str(e)) + else: + self._settings_saved_event(text) def close(self): path = self._profile_path + '.lock'