Merge branch '1208' into v0.6

This commit is contained in:
Peter Šurda 2018-04-10 08:12:25 +02:00
commit 32ab6aaae5
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 38 additions and 38 deletions

View File

@ -3,9 +3,9 @@
from helper_sql import * from helper_sql import *
try: try:
from PyQt4 import QtCore, QtGui from PyQt4 import QtGui
haveQt = True haveQt = True
except: except Exception:
haveQt = False haveQt = False
def search_translate (context, text): def search_translate (context, text):

View File

@ -1,22 +1,27 @@
"""Helper Sql performs sql operations."""
import threading import threading
import Queue import Queue
sqlSubmitQueue = Queue.Queue() #SQLITE3 is so thread-unsafe that they won't even let you call it from different threads using your own locks. SQL objects can only be called from one thread. sqlSubmitQueue = Queue.Queue()
# SQLITE3 is so thread-unsafe that they won't even let you call it from different threads using your own locks.
# SQL objects #can only be called from one thread.
sqlReturnQueue = Queue.Queue() sqlReturnQueue = Queue.Queue()
sqlLock = threading.Lock() sqlLock = threading.Lock()
def sqlQuery(sqlStatement, *args): def sqlQuery(sqlStatement, *args):
"""SQLLITE execute statement and return query."""
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)
if args == (): if args == ():
sqlSubmitQueue.put('') sqlSubmitQueue.put('')
elif type(args[0]) in [list, tuple]: elif isinstance(args[0], (list, tuple)):
sqlSubmitQueue.put(args[0]) sqlSubmitQueue.put(args[0])
else: else:
sqlSubmitQueue.put(args) sqlSubmitQueue.put(args)
queryreturn, _ = sqlReturnQueue.get()
queryreturn, rowcount = sqlReturnQueue.get()
sqlLock.release() sqlLock.release()
return queryreturn return queryreturn
@ -60,8 +65,7 @@ def sqlExecute(sqlStatement, *args):
sqlSubmitQueue.put('') sqlSubmitQueue.put('')
else: else:
sqlSubmitQueue.put(args) sqlSubmitQueue.put(args)
_, rowcount = sqlReturnQueue.get()
queryreturn, rowcount = sqlReturnQueue.get()
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
sqlLock.release() sqlLock.release()
return rowcount return rowcount
@ -71,30 +75,24 @@ def sqlStoredProcedure(procName):
sqlSubmitQueue.put(procName) sqlSubmitQueue.put(procName)
sqlLock.release() sqlLock.release()
class SqlBulkExecute: class SqlBulkExecute:
"""This is used when you have to execute the same statement in a cycle."""
def __enter__(self): def __enter__(self):
sqlLock.acquire() sqlLock.acquire()
return self return self
def __exit__(self, type, value, traceback): def __exit__(self, exc_type, value, traceback):
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
sqlLock.release() sqlLock.release()
def execute(self, sqlStatement, *args): @staticmethod
def execute(sqlStatement, *args):
"""Used for statements that do not return results."""
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)
if args == (): if args == ():
sqlSubmitQueue.put('') sqlSubmitQueue.put('')
else: else:
sqlSubmitQueue.put(args) sqlSubmitQueue.put(args)
sqlReturnQueue.get() sqlReturnQueue.get()
def query(self, sqlStatement, *args):
sqlSubmitQueue.put(sqlStatement)
if args == ():
sqlSubmitQueue.put('')
else:
sqlSubmitQueue.put(args)
return sqlReturnQueue.get()

View File

@ -1,11 +1,10 @@
"""Helper Start performs all the startup operations."""
import ConfigParser import ConfigParser
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import defaults import defaults
import sys import sys
import os import os
import locale
import random
import string
import platform import platform
from distutils.version import StrictVersion from distutils.version import StrictVersion
@ -14,7 +13,10 @@ import paths
import state import state
import helper_random import helper_random
storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may de-select Portable Mode in the settings if they want the config files to stay in the application data folder. StoreConfigFilesInSameDirectoryAsProgramByDefault = False
# The user may de-select Portable Mode in the settings if they want the config
# files to stay in the application data folder.
def _loadTrustedPeer(): def _loadTrustedPeer():
try: try:
@ -27,6 +29,7 @@ def _loadTrustedPeer():
host, port = trustedPeer.split(':') host, port = trustedPeer.split(':')
state.trustedPeer = state.Peer(host, int(port)) state.trustedPeer = state.Peer(host, int(port))
def loadConfig(): def loadConfig():
if state.appdata: if state.appdata:
BMConfigParser().read(state.appdata + 'keys.dat') BMConfigParser().read(state.appdata + 'keys.dat')
@ -35,7 +38,7 @@ def loadConfig():
BMConfigParser().get('bitmessagesettings', 'settingsversion') BMConfigParser().get('bitmessagesettings', 'settingsversion')
print 'Loading config files from directory specified on startup: ' + state.appdata print 'Loading config files from directory specified on startup: ' + state.appdata
needToCreateKeysFile = False needToCreateKeysFile = False
except: except Exception:
needToCreateKeysFile = True needToCreateKeysFile = True
else: else:
@ -45,16 +48,16 @@ def loadConfig():
print 'Loading config files from same directory as program.' print 'Loading config files from same directory as program.'
needToCreateKeysFile = False needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder() state.appdata = paths.lookupExeFolder()
except: except Exception:
# Could not load the keys.dat file in the program directory. Perhaps it # Could not load the keys.dat file in the program directory.
# is in the appdata directory. # Perhaps it is in the appdata directory.
state.appdata = paths.lookupAppdataFolder() state.appdata = paths.lookupAppdataFolder()
BMConfigParser().read(state.appdata + 'keys.dat') BMConfigParser().read(state.appdata + 'keys.dat')
try: try:
BMConfigParser().get('bitmessagesettings', 'settingsversion') BMConfigParser().get('bitmessagesettings', 'settingsversion')
print 'Loading existing config files from', state.appdata print 'Loading existing config files from', state.appdata
needToCreateKeysFile = False needToCreateKeysFile = False
except: except Exception:
needToCreateKeysFile = True needToCreateKeysFile = True
if needToCreateKeysFile: if needToCreateKeysFile:
@ -110,7 +113,6 @@ def loadConfig():
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0') BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0')
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8') BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8')
BMConfigParser().set('bitmessagesettings', 'ttl', '367200') BMConfigParser().set('bitmessagesettings', 'ttl', '367200')
#start:UI setting to stop trying to send messages after X days/months #start:UI setting to stop trying to send messages after X days/months
BMConfigParser().set( BMConfigParser().set(
'bitmessagesettings', 'stopresendingafterxdays', '') 'bitmessagesettings', 'stopresendingafterxdays', '')
@ -128,7 +130,7 @@ def loadConfig():
ensureNamecoinOptions() ensureNamecoinOptions()
if storeConfigFilesInSameDirectoryAsProgramByDefault: if StoreConfigFilesInSameDirectoryAsProgramByDefault:
# Just use the same directory as the program and forget about # Just use the same directory as the program and forget about
# the appdata folder # the appdata folder
state.appdata = '' state.appdata = ''
@ -149,5 +151,5 @@ def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
VER_THIS = StrictVersion(platform.version()) VER_THIS = StrictVersion(platform.version())
return StrictVersion("5.1.2600")<=VER_THIS and StrictVersion("6.0.6000")>=VER_THIS return StrictVersion("5.1.2600")<=VER_THIS and StrictVersion("6.0.6000")>=VER_THIS
return False return False
except Exception as err: except Exception:
return False return False