summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2024-07-03 16:22:54 +0200
committercos <cos>2024-07-03 16:22:54 +0200
commitf43d1c092bf5ef2829e7f94c74af55453187b138 (patch)
tree13a5a53a2940829edbaacfe3d38eb2a43d55ca32
parent51a1769361b410d3cc74b9c88c9e3b830070fa57 (diff)
downloadAntennaPodDbFixer-changes.zip
fixup! Switch to format strings where suitablechanges
-rwxr-xr-xAntennaPodDbFixer.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/AntennaPodDbFixer.py b/AntennaPodDbFixer.py
index 979fb3e..aff6eb6 100755
--- a/AntennaPodDbFixer.py
+++ b/AntennaPodDbFixer.py
@@ -39,7 +39,7 @@ def integrity_is_ok(fileName):
else:
print(" Errors found.")
if verbose:
- print("sqlite3 '{}' 'PRAGMA integrity_check;'".format(fileName))
+ print(f"sqlite3 '{fileName}' 'PRAGMA integrity_check;'")
if verbose:
print(integrityCheck)
return is_ok
@@ -123,11 +123,11 @@ sqlFilePath = inputFilePath + ".sql.tmp"
workingcopyFilePath = inputFilePath + ".tmp"
if not integrity_is_ok(emptyFilePath):
- print("Errors found in {}. Giving up!".format(emptyFilePath), file=sys.stderr)
+ print(f"Errors found in {emptyFilePath}. Giving up!", file=sys.stderr)
exit(1)
if verbose:
- print("cp '{}' '{}'".format(emptyFilePath, repairedFilePath))
+ print(f"cp '{emptyFilePath}' '{repairedFilePath}'")
shutil.copyfile(emptyFilePath, repairedFilePath, follow_symlinks=True)
if os.path.exists(sqlFilePath): os.remove(sqlFilePath)
if os.path.exists(workingcopyFilePath): os.remove(workingcopyFilePath)
@@ -135,7 +135,7 @@ if os.path.exists(workingcopyFilePath): os.remove(workingcopyFilePath)
# Recover to SQL commands and insert back into a database
print("Recovering database.")
if verbose:
- print("sqlite3 '{}' '.recover --ignore-freelist' >'{}'".format(inputFilePath, sqlFilePath))
+ print(f"sqlite3 '{inputFilePath}' '.recover --ignore-freelist' >'{sqlFilePath}'")
subprocess.run(
["sqlite3", inputFilePath, ".recover --ignore-freelist"],
check=True,
@@ -149,7 +149,7 @@ f = open(sqlFilePath,'w')
f.write(filedata.replace("CREATE TABLE sqlite_sequence(name,seq);",""))
f.close()
if verbose:
- print("sqlite3 '{}' <'{}'".format(workingcopyFilePath, sqlFilePath))
+ print(f"sqlite3 '{workingcopyFilePath}' <'{sqlFilePath}'")
subprocess.run(["sqlite3", workingcopyFilePath], stdin=open(sqlFilePath, 'r'))
print()
@@ -158,25 +158,24 @@ tables = query(emptyFilePath, "SELECT name FROM sqlite_schema WHERE type='table'
for table in tables:
table = table["name"]
print("Copying " + table, end="", flush=True)
- sql = ("SELECT GROUP_CONCAT(NAME,',') AS columns FROM PRAGMA_TABLE_INFO('{}')"
- ).format(table)
+ sql = f"SELECT GROUP_CONCAT(NAME,',') AS columns FROM PRAGMA_TABLE_INFO('{table}')"
i_print(verbose, [
{"msg": ".", "end": "", "flush": True},
- {"msg": "\nsqlite3 '{}'\n{};".format(emptyFilePath, sql)},
+ {"msg": f"\nsqlite3 '{emptyFilePath}'\n{sql};"},
])
columns = query(emptyFilePath, sql)[0]["columns"]
sql ="DELETE FROM " + table
i_print(verbose, [
{"msg": ".", "end": "", "flush": True},
- {"msg": "sqlite3 '{}'\n{};".format(repairedFilePath, sql)},
+ {"msg": f"sqlite3 '{repairedFilePath}'\n{sql};"},
])
query(repairedFilePath, sql)
- sql = ("attach '{}' AS old; INSERT INTO main.{} SELECT {} from old.{};"
- ).format(workingcopyFilePath, table, columns, table)
+ sql = (f"attach '{workingcopyFilePath}' AS old; INSERT INTO main.{table} "
+ + f"SELECT {columns} from old.{table};")
i_print(verbose, [
{"msg": ".", "end": "", "flush": True},
- {"msg": "{}".format(sql)},
+ {"msg": f"{sql}"},
])
query(repairedFilePath, sql)
print()
@@ -184,12 +183,12 @@ print()
# Cleanup
if verbose:
- print("rm '{}' '{}'".format(sqlFilePath, workingcopyFilePath))
+ print(f"rm '{sqlFilePath}' '{workingcopyFilePath}'")
os.remove(sqlFilePath)
os.remove(workingcopyFilePath)
if not integrity_is_ok(repairedFilePath):
- print("Integrity check of {} still found errors.".format(repairedFilePath),
+ print(f"Integrity check of {repairedFilePath} still found errors.",
file=sys.stderr)
exit(1)