Skip to content

Commit

Permalink
PEP-498: F Strings update
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquid369 committed Apr 8, 2024
1 parent 0c8c3f4 commit 65f2459
Show file tree
Hide file tree
Showing 33 changed files with 363 additions and 367 deletions.
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
52 changes: 26 additions & 26 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 @@ -489,7 +489,7 @@ def getReward(self, tx_hash, tx_ouput_n):
rows = cursor.fetchall()

except Exception as e:
err_msg = 'error getting reward %s-%d' % (tx_hash, tx_ouput_n)
err_msg = f'error getting reward {tx_hash}-{tx_output}'
printException(getCallerName(), getFunctionName(), err_msg, e)
rows = []
finally:
Expand All @@ -507,12 +507,12 @@ 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
err_msg = f'error getting rewards list for masternode {mn_name}'
printException(getCallerName(), getFunctionName(), err_msg, e)
rows = []
finally:
Expand All @@ -538,7 +538,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 @@ -555,7 +555,7 @@ def addRawTx(self, tx_hash, rawtx, lastfetch=0):
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,))
Expand All @@ -567,7 +567,7 @@ def deleteRawTx(self, tx_hash):
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,7 +576,7 @@ def getRawTx(self, tx_hash):
rows = cursor.fetchall()

except Exception as e:
err_msg = 'error getting raw tx for %s' % tx_hash
err_msg = f'error getting raw tx for {tx_hash}'
printException(getCallerName(), getFunctionName(), err_msg, e)
rows = []
finally:
Expand Down Expand Up @@ -676,13 +676,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 Down
16 changes: 8 additions & 8 deletions src/hwdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def check_api_init(func):
def func_int(*args, **kwargs):
hwDevice = args[0]
if hwDevice.api is None:
logging.warning("%s: hwDevice.api is None" % func.__name__)
logging.warning(f"{func.__name__}: hwDevice.api is None")
raise Exception("HW device: client not initialized")
return func(*args, **kwargs)

Expand All @@ -38,7 +38,7 @@ def __init__(self, main_wnd, *args, **kwargs):
printOK("HW: Class initialized")

def initDevice(self, hw_index):
printDbg("HW: initializing hw device with index %d" % hw_index)
printDbg(f"HW: initializing hw device with index {hw_index}")
if hw_index >= len(HW_devices):
raise Exception("Invalid HW index")

Expand All @@ -53,7 +53,7 @@ def initDevice(self, hw_index):
self.api.initDevice()
self.sig1done = self.api.sig1done
self.api.sig_disconnected.connect(self.main_wnd.clearHWstatus)
printOK("HW: hw device with index %d initialized" % hw_index)
printOK(f"HW: hw device with index {hw_index} initialized")

@check_api_init
def clearDevice(self):
Expand All @@ -68,7 +68,7 @@ def clearDevice(self):
@check_api_init
def getStatus(self):
printDbg("HW: checking device status...")
printOK("Status: %d" % self.api.status)
printOK(f"Status: {self.api.status}")
return self.api.model, self.api.status, self.api.messages[self.api.status]

def prepare_transfer_tx(self, caller, bip32_path, utxos_to_spend, dest_address, tx_fee, isTestnet=False):
Expand All @@ -86,17 +86,17 @@ def prepare_transfer_tx_bulk(self, caller, rewardsArray, dest_address, tx_fee, i

@check_api_init
def scanForAddress(self, account, spath, isTestnet=False):
printOK("HW: Scanning for Address n. %d on account n. %d" % (spath, account))
printOK(f"HW: Scanning for Address n. {spath} on account n. {account}")
return self.api.scanForAddress(account, spath, isTestnet)

@check_api_init
def scanForBip32(self, account, address, starting_spath=0, spath_count=10, isTestnet=False):
printOK("HW: Scanning for Bip32 path of address: %s" % address)
printOK(f"HW: Scanning for Bip32 path of address: {address}")
found = False
spath = -1

for i in range(starting_spath, starting_spath + spath_count):
printDbg("HW: checking path... %d'/0/%d" % (account, i))
printDbg(f"HW: checking path... {account}'/0/{i}")
curr_addr = self.api.scanForAddress(account, i, isTestnet)

if curr_addr == address:
Expand All @@ -110,7 +110,7 @@ def scanForBip32(self, account, address, starting_spath=0, spath_count=10, isTes

@check_api_init
def scanForPubKey(self, account, spath, isTestnet=False):
printOK("HW: Scanning for PubKey of address n. %d on account n. %d" % (spath, account))
printOK(f"HW: Scanning for PubKey of address n. {spath} on account n. {account}")
return self.api.scanForPubKey(account, spath, isTestnet)

@check_api_init
Expand Down
Loading

0 comments on commit 65f2459

Please sign in to comment.