This commit is contained in:
BeholdersEye 2022-02-24 10:38:52 -05:00
commit 362a975fbf
5 changed files with 146 additions and 110 deletions

View File

@ -134,13 +134,13 @@ function build_dll(){
cd src/bitmsghash || exit 1
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
echo "Create dll"
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native \
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=x86-64 \
"-I$HOME/.wine64/drive_c/OpenSSL-Win64/include" \
-I/usr/x86_64-w64-mingw32/include \
"-L$HOME/.wine64/drive_c/OpenSSL-Win64/lib" \
-c bitmsghash.cpp
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \
-D_WIN32 -O3 -march=native \
-D_WIN32 -O3 -march=x86-64 \
"-I$HOME/.wine64/drive_c/OpenSSL-Win64/include" \
"-L$HOME/.wine64/drive_c/OpenSSL-Win64" \
-L/usr/lib/x86_64-linux-gnu/wine \
@ -148,13 +148,13 @@ function build_dll(){
-o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
else
echo "Create dll"
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native \
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=i686 \
"-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \
-I/usr/i686-w64-mingw32/include \
"-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib" \
-c bitmsghash.cpp
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \
-D_WIN32 -O3 -march=native \
-D_WIN32 -O3 -march=i686 \
"-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \
"-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW" \
-fPIC -shared -lcrypt32 -leay32 -lwsock32 \

View File

@ -0,0 +1,31 @@
# pylint: disable=no-else-return, too-many-return-statements
"""To check the platform"""
from sys import platform as _sys_platform
from os import environ
def _get_platform():
kivy_build = environ.get("KIVY_BUILD", "")
if kivy_build in {"android", "ios"}:
return kivy_build
elif "P4A_BOOTSTRAP" in environ:
return "android"
elif "ANDROID_ARGUMENT" in environ:
return "android"
elif _sys_platform in ("win32", "cygwin"):
return "win"
elif _sys_platform == "darwin":
return "macosx"
elif _sys_platform.startswith("linux"):
return "linux"
elif _sys_platform.startswith("freebsd"):
return "linux"
return "unknown"
platform = _get_platform()
if platform not in ("android", "unknown"):
environ["KIVY_CAMERA"] = "opencv"

View File

@ -16,7 +16,7 @@ import paths
import queues
import state
import widgets
from bmconfigparser import config
from bmconfigparser import config as config_obj
from helper_sql import sqlExecute, sqlStoredProcedure
from helper_startup import start_proxyconfig
from network import knownnodes, AnnounceThread
@ -24,11 +24,11 @@ from network.asyncore_pollchoose import set_rates
from tr import _translate
def getSOCKSProxyType(config_):
def getSOCKSProxyType(config):
"""Get user socksproxytype setting from *config*"""
try:
result = ConfigParser.SafeConfigParser.get(
config_, 'bitmessagesettings', 'socksproxytype')
config, 'bitmessagesettings', 'socksproxytype')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
return None
else:
@ -45,7 +45,7 @@ class SettingsDialog(QtGui.QDialog):
self.parent = parent
self.firstrun = firstrun
self.config = config
self.config = config_obj
self.net_restart_needed = False
self.timer = QtCore.QTimer()
@ -80,7 +80,7 @@ class SettingsDialog(QtGui.QDialog):
)
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
def adjust_from_config(self, config_):
def adjust_from_config(self, config):
"""Adjust all widgets state according to config settings"""
# pylint: disable=too-many-branches,too-many-statements
if not self.parent.tray.isSystemTrayAvailable():
@ -89,31 +89,31 @@ class SettingsDialog(QtGui.QDialog):
"MainWindow", "Tray (not available in your system)"))
for setting in (
'minimizetotray', 'trayonclose', 'startintray'):
config_.set('bitmessagesettings', setting, 'false')
config.set('bitmessagesettings', setting, 'false')
else:
self.checkBoxMinimizeToTray.setChecked(
config_.getboolean('bitmessagesettings', 'minimizetotray'))
config.getboolean('bitmessagesettings', 'minimizetotray'))
self.checkBoxTrayOnClose.setChecked(
config_.safeGetBoolean('bitmessagesettings', 'trayonclose'))
config.safeGetBoolean('bitmessagesettings', 'trayonclose'))
self.checkBoxStartInTray.setChecked(
config_.getboolean('bitmessagesettings', 'startintray'))
config.getboolean('bitmessagesettings', 'startintray'))
self.checkBoxHideTrayConnectionNotifications.setChecked(
config_.getboolean(
config.getboolean(
'bitmessagesettings', 'hidetrayconnectionnotifications'))
self.checkBoxShowTrayNotifications.setChecked(
config_.getboolean('bitmessagesettings', 'showtraynotifications'))
config.getboolean('bitmessagesettings', 'showtraynotifications'))
self.checkBoxStartOnLogon.setChecked(
config_.getboolean('bitmessagesettings', 'startonlogon'))
config.getboolean('bitmessagesettings', 'startonlogon'))
self.checkBoxWillinglySendToMobile.setChecked(
config_.safeGetBoolean(
config.safeGetBoolean(
'bitmessagesettings', 'willinglysendtomobile'))
self.checkBoxUseIdenticons.setChecked(
config_.safeGetBoolean('bitmessagesettings', 'useidenticons'))
config.safeGetBoolean('bitmessagesettings', 'useidenticons'))
self.checkBoxReplyBelow.setChecked(
config_.safeGetBoolean('bitmessagesettings', 'replybelow'))
config.safeGetBoolean('bitmessagesettings', 'replybelow'))
if state.appdata == paths.lookupExeFolder():
self.checkBoxPortableMode.setChecked(True)
@ -142,57 +142,57 @@ class SettingsDialog(QtGui.QDialog):
# On the Network settings tab:
self.lineEditTCPPort.setText(str(
config_.get('bitmessagesettings', 'port')))
config.get('bitmessagesettings', 'port')))
self.checkBoxUPnP.setChecked(
config_.safeGetBoolean('bitmessagesettings', 'upnp'))
config.safeGetBoolean('bitmessagesettings', 'upnp'))
self.checkBoxUDP.setChecked(
config_.safeGetBoolean('bitmessagesettings', 'udp'))
config.safeGetBoolean('bitmessagesettings', 'udp'))
self.checkBoxAuthentication.setChecked(
config_.getboolean('bitmessagesettings', 'socksauthentication'))
config.getboolean('bitmessagesettings', 'socksauthentication'))
self.checkBoxSocksListen.setChecked(
config_.getboolean('bitmessagesettings', 'sockslisten'))
config.getboolean('bitmessagesettings', 'sockslisten'))
self.checkBoxOnionOnly.setChecked(
config_.safeGetBoolean('bitmessagesettings', 'onionservicesonly'))
config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'))
self._proxy_type = getSOCKSProxyType(config_)
self._proxy_type = getSOCKSProxyType(config)
self.comboBoxProxyType.setCurrentIndex(
0 if not self._proxy_type
else self.comboBoxProxyType.findText(self._proxy_type))
self.comboBoxProxyTypeChanged(self.comboBoxProxyType.currentIndex())
self.lineEditSocksHostname.setText(
config_.get('bitmessagesettings', 'sockshostname'))
config.get('bitmessagesettings', 'sockshostname'))
self.lineEditSocksPort.setText(str(
config_.get('bitmessagesettings', 'socksport')))
config.get('bitmessagesettings', 'socksport')))
self.lineEditSocksUsername.setText(
config_.get('bitmessagesettings', 'socksusername'))
config.get('bitmessagesettings', 'socksusername'))
self.lineEditSocksPassword.setText(
config_.get('bitmessagesettings', 'sockspassword'))
config.get('bitmessagesettings', 'sockspassword'))
self.lineEditMaxDownloadRate.setText(str(
config_.get('bitmessagesettings', 'maxdownloadrate')))
config.get('bitmessagesettings', 'maxdownloadrate')))
self.lineEditMaxUploadRate.setText(str(
config_.get('bitmessagesettings', 'maxuploadrate')))
config.get('bitmessagesettings', 'maxuploadrate')))
self.lineEditMaxOutboundConnections.setText(str(
config_.get('bitmessagesettings', 'maxoutboundconnections')))
config.get('bitmessagesettings', 'maxoutboundconnections')))
# Demanded difficulty tab
self.lineEditTotalDifficulty.setText(str((float(
config_.getint(
config.getint(
'bitmessagesettings', 'defaultnoncetrialsperbyte')
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.lineEditSmallMessageDifficulty.setText(str((float(
config_.getint(
config.getint(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
) / defaults.networkDefaultPayloadLengthExtraBytes)))
# Max acceptable difficulty tab
self.lineEditMaxAcceptableTotalDifficulty.setText(str((float(
config_.getint(
config.getint(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.lineEditMaxAcceptableSmallMessageDifficulty.setText(str((float(
config_.getint(
config.getint(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes')
) / defaults.networkDefaultPayloadLengthExtraBytes)))
@ -203,21 +203,21 @@ class SettingsDialog(QtGui.QDialog):
self.comboBoxOpenCL.addItems(openclpow.vendors)
self.comboBoxOpenCL.setCurrentIndex(0)
for i in range(self.comboBoxOpenCL.count()):
if self.comboBoxOpenCL.itemText(i) == config_.safeGet(
if self.comboBoxOpenCL.itemText(i) == config.safeGet(
'bitmessagesettings', 'opencl'):
self.comboBoxOpenCL.setCurrentIndex(i)
break
# Namecoin integration tab
nmctype = config_.get('bitmessagesettings', 'namecoinrpctype')
nmctype = config.get('bitmessagesettings', 'namecoinrpctype')
self.lineEditNamecoinHost.setText(
config_.get('bitmessagesettings', 'namecoinrpchost'))
config.get('bitmessagesettings', 'namecoinrpchost'))
self.lineEditNamecoinPort.setText(str(
config_.get('bitmessagesettings', 'namecoinrpcport')))
config.get('bitmessagesettings', 'namecoinrpcport')))
self.lineEditNamecoinUser.setText(
config_.get('bitmessagesettings', 'namecoinrpcuser'))
config.get('bitmessagesettings', 'namecoinrpcuser'))
self.lineEditNamecoinPassword.setText(
config_.get('bitmessagesettings', 'namecoinrpcpassword'))
config.get('bitmessagesettings', 'namecoinrpcpassword'))
if nmctype == "namecoind":
self.radioButtonNamecoinNamecoind.setChecked(True)
@ -232,9 +232,9 @@ class SettingsDialog(QtGui.QDialog):
# Message Resend tab
self.lineEditDays.setText(str(
config_.get('bitmessagesettings', 'stopresendingafterxdays')))
config.get('bitmessagesettings', 'stopresendingafterxdays')))
self.lineEditMonths.setText(str(
config_.get('bitmessagesettings', 'stopresendingafterxmonths')))
config.get('bitmessagesettings', 'stopresendingafterxmonths')))
def comboBoxProxyTypeChanged(self, comboBoxIndex):
"""A callback for currentIndexChanged event of comboBoxProxyType"""

View File

@ -4,7 +4,6 @@ BMConfigParser class definition and default configuration settings
import os
import shutil
import sys # FIXME: bad style! write more generally
from threading import Event
from datetime import datetime
@ -36,6 +35,15 @@ class BMConfigParser(SafeConfigParser):
raise ValueError("Invalid value %s" % value)
return SafeConfigParser.set(self, section, option, value)
def get(self, section, option, **kwargs):
"""Try returning temporary value before using parent get()"""
try:
return self._temp[section][option]
except KeyError:
pass
return SafeConfigParser.get(
self, section, option, **kwargs)
def setTemp(self, section, option, value=None):
"""Temporary set option to value, not saving."""
try:
@ -43,41 +51,36 @@ class BMConfigParser(SafeConfigParser):
except KeyError:
self._temp[section] = {option: value}
def safeGetBoolean(self, section, field):
def safeGetBoolean(self, section, option):
"""Return value as boolean, False on exceptions"""
try:
# Used in the python2.7
# return self.getboolean(section, field)
# Used in the python3.5.2
# print(config, section, field)
return self.getboolean(section, field)
return self.getboolean(section, option)
except (configparser.NoSectionError, configparser.NoOptionError,
ValueError, AttributeError):
return False
def safeGetInt(self, section, field, default=0):
def safeGetInt(self, section, option, default=0):
"""Return value as integer, default on exceptions,
0 if default missing"""
try:
# Used in the python2.7
# return self.getint(section, field)
# Used in the python3.7.0
return int(self.get(section, field))
return int(self.get(section, option))
except (configparser.NoSectionError, configparser.NoOptionError,
ValueError, AttributeError):
return default
def safeGetFloat(self, section, field, default=0.0):
def safeGetFloat(self, section, option, default=0.0):
"""Return value as float, default on exceptions,
0.0 if default missing"""
try:
return self.getfloat(section, field)
return self.getfloat(section, option)
except (configparser.NoSectionError, configparser.NoOptionError,
ValueError, AttributeError):
return default
def safeGet(self, section, option, default=None):
"""Return value as is, default on exceptions, None if default missing"""
"""
Return value as is, default on exceptions, None if default missing
"""
try:
return self.get(section, option)
except (configparser.NoSectionError, configparser.NoOptionError,
@ -91,34 +94,25 @@ class BMConfigParser(SafeConfigParser):
return SafeConfigParser.items(self, section, True, variables)
def _reset(self):
"""Reset current config. There doesn't appear to be a built in
method for this"""
"""
Reset current config.
There doesn't appear to be a built in method for this.
"""
self._temp = {}
sections = self.sections()
for x in sections:
self.remove_section(x)
def read(self, filenames=None):
self._reset()
SafeConfigParser.read(self, os.path.join(os.path.dirname(__file__), 'default.ini'))
SafeConfigParser.read(
self, os.path.join(os.path.dirname(__file__), 'default.ini'))
if filenames:
SafeConfigParser.read(self, filenames)
if sys.version_info[0] == 3:
@staticmethod
def addresses(hidden=False):
"""Return a list of local bitmessage addresses (from section labels)"""
return [x for x in config.sections() if x.startswith('BM-') and (
hidden or not config.safeGetBoolean(x, 'hidden'))]
def readfp(self, fp, filename=None):
# pylint: disable=no-member
SafeConfigParser.read_file(self, fp)
else:
@staticmethod
def addresses():
"""Return a list of local bitmessage addresses (from section labels)"""
return [
x for x in config.sections() if x.startswith('BM-')]
def addresses(self):
"""Return a list of local bitmessage addresses (from section labels)"""
return [x for x in self.sections() if x.startswith('BM-')]
def save(self):
"""Save the runtime config onto the filesystem"""
@ -161,4 +155,7 @@ class BMConfigParser(SafeConfigParser):
return True
config = BMConfigParser()
if not getattr(BMConfigParser, 'read_file', False):
BMConfigParser.read_file = BMConfigParser.readfp
config = BMConfigParser() # TODO: remove this crutch

View File

@ -1,4 +1,3 @@
# pylint: disable=no-member, no-self-use
"""
Various tests for config
"""
@ -36,63 +35,72 @@ maxnodes = 15000
maxsize = 1048576"""
# pylint: disable=protected-access
class TestConfig(unittest.TestCase):
"""A test case for bmconfigparser"""
configfile = StringIO('')
def setUp(self):
self.config = BMConfigParser()
self.config.add_section('bitmessagesettings')
def test_safeGet(self):
"""safeGet retuns provided default for nonexistent option or None"""
config = BMConfigParser()
self.assertIs(
config.safeGet('nonexistent', 'nonexistent'), None)
self.config.safeGet('nonexistent', 'nonexistent'), None)
self.assertEqual(
config.safeGet('nonexistent', 'nonexistent', 42), 42)
self.config.safeGet('nonexistent', 'nonexistent', 42), 42)
def test_safeGetBoolean(self):
"""safeGetBoolean returns False for nonexistent option, no default"""
config = BMConfigParser()
self.assertIs(
config.safeGetBoolean('nonexistent', 'nonexistent'),
False
)
self.config.safeGetBoolean('nonexistent', 'nonexistent'), False)
# no arg for default
# pylint: disable=too-many-function-args
with self.assertRaises(TypeError):
config.safeGetBoolean(
'nonexistent', 'nonexistent', True)
self.config.safeGetBoolean('nonexistent', 'nonexistent', True)
def test_safeGetInt(self):
"""safeGetInt retuns provided default for nonexistent option or 0"""
config = BMConfigParser()
self.assertEqual(
config.safeGetInt('nonexistent', 'nonexistent'), 0)
self.config.safeGetInt('nonexistent', 'nonexistent'), 0)
self.assertEqual(
config.safeGetInt('nonexistent', 'nonexistent', 42), 42)
self.config.safeGetInt('nonexistent', 'nonexistent', 42), 42)
def test_safeGetFloat(self):
"""safeGetFloat retuns provided default for nonexistent option or 0.0"""
config = BMConfigParser()
"""
safeGetFloat retuns provided default for nonexistent option or 0.0
"""
self.assertEqual(
config.safeGetFloat('nonexistent', 'nonexistent'), 0.0)
self.config.safeGetFloat('nonexistent', 'nonexistent'), 0.0)
self.assertEqual(
config.safeGetFloat('nonexistent', 'nonexistent', 42.0), 42.0)
self.config.safeGetFloat('nonexistent', 'nonexistent', 42.0), 42.0)
def test_setTemp(self):
"""Set a temporary value and ensure it's returned by get()"""
self.config.setTemp('bitmessagesettings', 'connect', 'true')
self.assertIs(
self.config.safeGetBoolean('bitmessagesettings', 'connect'), True)
written_fp = StringIO('')
self.config.write(written_fp)
self.config._reset()
self.config.read_file(written_fp)
self.assertIs(
self.config.safeGetBoolean('bitmessagesettings', 'connect'), False)
def test_reset(self):
"""safeGetInt retuns provided default for bitmessagesettings option or 0"""
config = BMConfigParser()
"""Some logic for testing _reset()"""
test_config_object = StringIO(test_config)
config.readfp(test_config_object)
self.config.read_file(test_config_object)
self.assertEqual(
config.safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 100)
# pylint: disable=protected-access
config._reset()
self.assertEqual(config.sections(), [])
self.config.safeGetInt(
'bitmessagesettings', 'maxaddrperstreamsend'), 100)
self.config._reset()
self.assertEqual(self.config.sections(), [])
def test_defaults(self):
"""Loading defaults"""
config = BMConfigParser()
config.add_section('bitmessagesettings')
config.set("bitmessagesettings", "maxaddrperstreamsend", "100")
config.read()
self.config.set('bitmessagesettings', 'maxaddrperstreamsend', '100')
self.config.read()
self.assertEqual(
config.safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 500)
self.config.safeGetInt(
'bitmessagesettings', 'maxaddrperstreamsend'), 500)