Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SPMT to Python 3.10 - PEP498 Literal String Interpolation #60

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions SecurePivxMasternodeTool.spec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def libModule(module, source, dest):
m = __import__(module)
module_path = os_path.dirname(m.__file__)
del m
print("libModule %s" % str(( os_path.join(module_path, source), dest )))
print(f"libModule {(os.path.join(module_path, source), dest)}")
return ( os_path.join(module_path, source), dest )


Expand Down Expand Up @@ -89,7 +89,7 @@ exe = EXE(pyz,
strip=False,
upx=False,
console=False,
icon=os_path.join(base_dir, 'img', 'spmt.%s' % ('icns' if os_type=='darwin' else 'ico')) )
icon = os.path.join(base_dir, 'img', f'spmt.{"icns" if os_type == "darwin" else "ico"}'))

#coll = COLLECT(exe,
# a.binaries,
Expand Down Expand Up @@ -125,7 +125,7 @@ if os_type == 'win32':
os.rename(dist_path, dist_path_win)
# Create NSIS compressed installer
print('Creating Windows installer (requires NSIS)')
os.system('\"c:\\program files (x86)\\NSIS\\makensis.exe\" %s' % os.path.join(base_dir, 'setup.nsi'))
os.system(f'"{os.path.join("c:", "program files (x86)", "NSIS", "makensis.exe")}" {os.path.join(base_dir, "setup.nsi")}')


if os_type == 'linux':
Expand All @@ -135,8 +135,7 @@ if os_type == 'linux':
os.rename(dist_path, dist_path_linux)
# Compress dist Dir
print('Compressing Linux App Folder')
os.system('tar -zcvf %s -C %s %s' % ('SPMT-v' + version_str + '-x86_64-gnu_linux.tar.gz',
base_dir, 'SPMT-v' + version_str + '-gnu_linux'))
os.system(f'tar -zcvf SPMT-v{version_str}-x86_64-gnu_linux.tar.gz -C {base_dir} SPMT-v{version_str}-gnu_linux')


if os_type == 'darwin':
Expand All @@ -151,5 +150,4 @@ if os_type == 'darwin':
os.chdir(base_dir)
# Compress dist Dir
print('Compressing Mac App Folder')
os.system('tar -zcvf %s -C %s %s' % ('SPMT-v' + version_str + '-MacOSX.tar.gz',
base_dir, 'SPMT-v' + version_str + '-MacOSX'))
os.system(f'tar -zcvf SPMT-v{version_str}-MacOSX.tar.gz -C {base_dir} SPMT-v{version_str}-MacOSX')
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ python-bitcoinrpc==1.0
bitcoin==1.1.42
btchip-python==0.1.27
trezor==0.11.1
PyQt5>=5.9,<5.14.1
PyQt5>=5.15.10
requests>=2.18.4,<=2.23
simplejson<=3.13.2
ecdsa==0.13.3
wheel==0.35.0
setuptools==53.0.0
2 changes: 1 addition & 1 deletion spmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

label = QLabel(splash)
label.setStyleSheet(labelstyle)
label.setGeometry((splash_pix.width()-500)/2, splash_pix.height()-40, 500, 20)
label.setGeometry(int((splash_pix.width() - 500) / 2), int(splash_pix.height() - 40), 500, 20)
label.setAlignment(Qt.AlignCenter)

progressText = "loading..."
Expand Down
6 changes: 3 additions & 3 deletions src/blockbookClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def process_blockbook_exceptions_int(*args, **kwargs):
new_url = "https://testnet.fuzzbawls.pw"
else:
new_url = "https://zkbitcoin.com/"
message = "BlockBook Client exception on %s\nTrying backup server %s" % (client.url, new_url)
message = f"BlockBook Client exception on {client.url}\nTrying backup server {new_url}"
printException(getCallerName(True), getFunctionName(True), message, str(e))

try:
Expand All @@ -42,9 +42,9 @@ def __init__(self, isTestnet=False):
self.url = "https://explorer.rockdev.org/"

def checkResponse(self, method, param=""):
url = self.url + "/api/%s" % method
url = f"{self.url}/api/{method}"
if param != "":
url += "/%s" % param
url += "/{param}"
resp = requests.get(url, data={}, verify=True)
if resp.status_code == 200:
data = resp.json()
Expand Down
77 changes: 39 additions & 38 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def releaseCursor(self, rollingBack=False, vacuum=False):
raise Exception("Database closed")

def initTables(self):
printDbg("DB: Initializing tables...")
printDbg(f"DB: Initializing tables...")
try:
cursor = self.conn.cursor()

Expand Down Expand Up @@ -187,19 +187,19 @@ def initTable_RPC(self, cursor):
'''

def clearTable(self, table_name):
printDbg("DB: Clearing table %s..." % table_name)
printDbg(f"DB: Clearing table {table_name}...")
cleared_RPC = False
try:
cursor = self.getCursor()
cursor.execute("DELETE FROM %s" % table_name)
cursor.execute(f"DELETE FROM {table_name}")
# in case, reload default RPC and emit changed signal
if table_name == 'CUSTOM_RPC_SERVERS':
self.initTable_RPC(cursor)
cleared_RPC = True
printDbg("DB: Table %s cleared" % table_name)
printDbg(f"DB: Table {table_name} cleared")

except Exception as e:
err_msg = 'error clearing %s in database' % table_name
err_msg = f'error clearing {table_name} in database'
printException(getCallerName(), getFunctionName(), err_msg, e.args)

finally:
Expand All @@ -208,14 +208,14 @@ def clearTable(self, table_name):
self.app.sig_changed_rpcServers.emit()

def removeTable(self, table_name):
printDbg("DB: Dropping table %s..." % table_name)
printDbg(f"DB: Dropping table {table_name}...")
try:
cursor = self.getCursor()
cursor.execute("DROP TABLE IF EXISTS %s" % table_name)
printDbg("DB: Table %s removed" % table_name)
cursor.execute(f"DROP TABLE IF EXISTS {table_name}")
printDbg(f"DB: Table {table_name} removed")

except Exception as e:
err_msg = 'error removing table %s from database' % table_name
err_msg = f'error removing table {table_name} from database'
printException(getCallerName(), getFunctionName(), err_msg, e.args)

finally:
Expand Down Expand Up @@ -247,7 +247,7 @@ def addRPCServer(self, protocol, host, user, passwd):
self.app.sig_changed_rpcServers.emit()

def editRPCServer(self, protocol, host, user, passwd, id):
printDbg("DB: Editing RPC server with id %d" % id)
printDbg(f"DB: Editing RPC server with id {id}")
changed_RPC = False
try:
cursor = self.getCursor()
Expand All @@ -270,15 +270,15 @@ def editRPCServer(self, protocol, host, user, passwd, id):
def getRPCServers(self, custom, id=None):
tableName = "CUSTOM_RPC_SERVERS" if custom else "PUBLIC_RPC_SERVERS"
if id is not None:
printDbg("DB: Getting RPC server with id %d from table %s" % (id, tableName))
printDbg(f"DB: Getting RPC server with id {id} from table {tableName}")
else:
printDbg("DB: Getting all RPC servers from table %s" % tableName)
printDbg(f"DB: Getting all RPC servers from table {tableName}")
try:
cursor = self.getCursor()
if id is None:
cursor.execute("SELECT * FROM %s" % tableName)
cursor.execute(f"SELECT * FROM {tableName}")
else:
cursor.execute("SELECT * FROM %s WHERE id = ?" % tableName, (id,))
cursor.execute(f"SELECT * FROM {tableName} WHERE id = ?", (id,))
rows = cursor.fetchall()

except Exception as e:
Expand All @@ -305,7 +305,7 @@ def getRPCServers(self, custom, id=None):
return server_list

def removeRPCServer(self, id):
printDbg("DB: Remove RPC server with id %d" % id)
printDbg(f"DB: Remove RPC server with id {id}")
removed_RPC = False
try:
cursor = self.getCursor()
Expand Down Expand Up @@ -389,7 +389,7 @@ def addMasternode(self, mn, old_mn=None):
add_defaultKeys_to_dict(mn, DEFAULT_MN_CONF)

if old_mn is not None:
printDbg("DB: Editing masternode %s" % old_mn)
printDbg(f"DB: Editing masternode {old_mn}")
try:
cursor = self.getCursor()

Expand All @@ -415,7 +415,7 @@ def addMasternode(self, mn, old_mn=None):
self.addNewMasternode(mn)

def deleteMasternode(self, mn_name):
printDbg("DB: Deleting masternode %s" % mn_name)
printDbg(f"DB: Deleting masternode {mn_name}")
try:
cursor = self.getCursor()
cursor.execute("DELETE FROM MASTERNODES WHERE name = ? ", (mn_name,))
Expand Down Expand Up @@ -475,22 +475,22 @@ def deleteReward(self, tx_hash, tx_ouput_n):

except Exception as e:
err_msg = 'error deleting UTXO from DB'
printException(getCallerName(), getFunctionName(), err_msg, e.args)
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e.args}")
finally:
self.releaseCursor(vacuum=True)

def getReward(self, tx_hash, tx_ouput_n):
def getReward(self, tx_hash, tx_output_n):
logging.debug("DB: Getting reward")
try:
cursor = self.getCursor()

cursor.execute("SELECT * FROM REWARDS"
" WHERE tx_hash = ? AND tx_ouput_n = ?", (tx_hash, tx_ouput_n))
" WHERE tx_hash = ? AND tx_ouput_n = ?", (tx_hash, tx_output_n))
rows = cursor.fetchall()

except Exception as e:
err_msg = 'error getting reward %s-%d' % (tx_hash, tx_ouput_n)
printException(getCallerName(), getFunctionName(), err_msg, e)
err_msg = f'error getting reward {tx_hash}-{tx_output_n}'
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e}")
rows = []
finally:
self.releaseCursor()
Expand All @@ -499,6 +499,7 @@ def getReward(self, tx_hash, tx_ouput_n):
return self.rewards_from_rows(rows)[0]
return None


def getRewardsList(self, mn_name=None):
try:
cursor = self.getCursor()
Expand All @@ -507,13 +508,13 @@ def getRewardsList(self, mn_name=None):
printDbg("DB: Getting rewards of all masternodes")
cursor.execute("SELECT * FROM REWARDS")
else:
printDbg("DB: Getting rewards of masternode %s" % mn_name)
printDbg(f"DB: Getting rewards of masternode {mn_name}")
cursor.execute("SELECT * FROM REWARDS WHERE mn_name = ?", (mn_name,))
rows = cursor.fetchall()

except Exception as e:
err_msg = 'error getting rewards list for masternode %s' % mn_name
printException(getCallerName(), getFunctionName(), err_msg, e)
err_msg = f'error getting rewards list for masternode {mn_name}'
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e}")
rows = []
finally:
self.releaseCursor()
Expand All @@ -538,7 +539,7 @@ def txes_from_rows(self, rows):
return txes

def addRawTx(self, tx_hash, rawtx, lastfetch=0):
logging.debug("DB: Adding rawtx for %s" % tx_hash)
logging.debug(f"DB: Adding rawtx for {tx_hash}")
try:
cursor = self.getCursor()

Expand All @@ -548,26 +549,26 @@ def addRawTx(self, tx_hash, rawtx, lastfetch=0):
)

except Exception as e:
err_msg = 'error adding rawtx to DB'
printException(getCallerName(), getFunctionName(), err_msg, e)
err_msg = f'error adding rawtx to DB'
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e}")

finally:
self.releaseCursor()

def deleteRawTx(self, tx_hash):
logging.debug("DB: Deleting rawtx for %s" % tx_hash)
logging.debug(f"DB: Deleting rawtx for {tx_hash}")
try:
cursor = self.getCursor()
cursor.execute("DELETE FROM RAWTXES WHERE tx_hash = ?", (tx_hash,))

except Exception as e:
err_msg = 'error deleting rawtx from DB'
printException(getCallerName(), getFunctionName(), err_msg, e.args)
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e.args}")
finally:
self.releaseCursor(vacuum=True)

def getRawTx(self, tx_hash):
logging.debug("DB: Getting rawtx for %s" % tx_hash)
logging.debug(f"DB: Getting rawtx for {tx_hash}")
try:
cursor = self.getCursor()

Expand All @@ -576,8 +577,8 @@ def getRawTx(self, tx_hash):
rows = cursor.fetchall()

except Exception as e:
err_msg = 'error getting raw tx for %s' % tx_hash
printException(getCallerName(), getFunctionName(), err_msg, e)
err_msg = f'error getting raw tx for {tx_hash}'
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e}")
rows = []
finally:
self.releaseCursor()
Expand All @@ -597,7 +598,7 @@ def clearRawTxes(self, minTime):

except Exception as e:
err_msg = 'error deleting rawtx from DB'
printException(getCallerName(), getFunctionName(), err_msg, e.args)
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e.args}")
finally:
self.releaseCursor(vacuum=True)

Expand Down Expand Up @@ -663,7 +664,7 @@ def addProposal(self, p):

except Exception as e:
err_msg = 'error adding proposal to DB'
printException(getCallerName(), getFunctionName(), err_msg, e)
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e}")

finally:
self.releaseCursor()
Expand All @@ -676,13 +677,13 @@ def getMyVotes(self, p_hash=None):
printDbg("DB: Getting votes for all proposals")
cursor.execute("SELECT * FROM MY_VOTES")
else:
printDbg("DB: Getting votes for proposal %s" % p_hash)
printDbg(f"DB: Getting votes for proposal {p_hash}")
cursor.execute("SELECT * FROM MY_VOTES WHERE p_hash = ?", (p_hash,))
rows = cursor.fetchall()

except Exception as e:
err_msg = 'error getting myVotes from DB'
printException(getCallerName(), getFunctionName(), err_msg, e)
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e}")
rows = []
finally:
self.releaseCursor()
Expand All @@ -698,7 +699,7 @@ def getProposalsList(self):

except Exception as e:
err_msg = 'error getting proposals from DB'
printException(getCallerName(), getFunctionName(), err_msg, e)
printException(f"{getCallerName()}", f"{getFunctionName()}", f"{err_msg}", f"{e}")
rows = []
finally:
self.releaseCursor()
Expand Down
Loading