summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2024-07-03 16:06:06 +0200
committercos <cos>2024-07-03 16:06:15 +0200
commit51a1769361b410d3cc74b9c88c9e3b830070fa57 (patch)
tree0ceb949b10f41c8e759bfaa0aa0b981c9c96c033
parent7cdd2713b3611f2b2ef3c789ea73b6138cef9743 (diff)
downloadAntennaPodDbFixer-51a1769361b410d3cc74b9c88c9e3b830070fa57.zip
Switch to format strings where suitable
-rwxr-xr-xAntennaPodDbFixer.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/AntennaPodDbFixer.py b/AntennaPodDbFixer.py
index f2e487a..979fb3e 100755
--- a/AntennaPodDbFixer.py
+++ b/AntennaPodDbFixer.py
@@ -39,7 +39,7 @@ def integrity_is_ok(fileName):
else:
print(" Errors found.")
if verbose:
- print("sqlite3 '" + fileName + "' 'PRAGMA integrity_check;'")
+ print("sqlite3 '{}' 'PRAGMA integrity_check;'".format(fileName))
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 " + emptyFilePath + ". Giving up!", file=sys.stderr)
+ print("Errors found in {}. Giving up!".format(emptyFilePath), file=sys.stderr)
exit(1)
if verbose:
- print("cp '" + emptyFilePath + "' '" + repairedFilePath + "'")
+ print("cp '{}' '{}'".format(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 '" + inputFilePath + "' '.recover --ignore-freelist' >" + sqlFilePath)
+ print("sqlite3 '{}' '.recover --ignore-freelist' >'{}'".format(inputFilePath, 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 '" + workingcopyFilePath + "' <" + sqlFilePath)
+ print("sqlite3 '{}' <'{}'".format(workingcopyFilePath, sqlFilePath))
subprocess.run(["sqlite3", workingcopyFilePath], stdin=open(sqlFilePath, 'r'))
print()
@@ -158,7 +158,8 @@ 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('" + table + "')"
+ sql = ("SELECT GROUP_CONCAT(NAME,',') AS columns FROM PRAGMA_TABLE_INFO('{}')"
+ ).format(table)
i_print(verbose, [
{"msg": ".", "end": "", "flush": True},
{"msg": "\nsqlite3 '{}'\n{};".format(emptyFilePath, sql)},
@@ -171,8 +172,8 @@ for table in tables:
{"msg": "sqlite3 '{}'\n{};".format(repairedFilePath, sql)},
])
query(repairedFilePath, sql)
- sql = ("attach '" + workingcopyFilePath + "' AS old; INSERT INTO main." + table + " SELECT " +
- columns + " from old." + table + ";")
+ sql = ("attach '{}' AS old; INSERT INTO main.{} SELECT {} from old.{};"
+ ).format(workingcopyFilePath, table, columns, table)
i_print(verbose, [
{"msg": ".", "end": "", "flush": True},
{"msg": "{}".format(sql)},
@@ -183,12 +184,13 @@ print()
# Cleanup
if verbose:
- print("rm '" + sqlFilePath + "' '" + workingcopyFilePath + "'")
+ print("rm '{}' '{}'".format(sqlFilePath, workingcopyFilePath))
os.remove(sqlFilePath)
os.remove(workingcopyFilePath)
if not integrity_is_ok(repairedFilePath):
- print("Integrity check of " + repairedFilePath + " still found errors.", file=sys.stderr)
+ print("Integrity check of {} still found errors.".format(repairedFilePath),
+ file=sys.stderr)
exit(1)
print("Done. Output file: " + repairedFilePath)