summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2024-07-03 15:51:22 +0200
committercos <cos>2024-07-03 16:06:15 +0200
commit7cdd2713b3611f2b2ef3c789ea73b6138cef9743 (patch)
treea42d65da5b442cf8327f21817fd24e39c500df4b
parent42f3528e064cdf29baea2025949ae5c14a658a7b (diff)
downloadAntennaPodDbFixer-7cdd2713b3611f2b2ef3c789ea73b6138cef9743.zip
Wrap normal/debug prints in an indexed print function
-rwxr-xr-xAntennaPodDbFixer.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/AntennaPodDbFixer.py b/AntennaPodDbFixer.py
index 85d0e12..f2e487a 100755
--- a/AntennaPodDbFixer.py
+++ b/AntennaPodDbFixer.py
@@ -9,6 +9,16 @@ import getopt
def usage():
return sys.argv[0] + " [--help] [--verbose] [corrupt.db] [empty.db]"
+def i_print(index, alternatives):
+ if type(index) == bool:
+ if index:
+ index = 1
+ else:
+ index = 0
+ args = alternatives[index]
+ msg = args.pop("msg")
+ print(msg, **args)
+
def get_db_version(fileName):
return subprocess.run(
["sqlite3", fileName, "PRAGMA user_version;"],
@@ -18,8 +28,6 @@ def get_db_version(fileName):
def integrity_is_ok(fileName):
print("Checking integrity of " + fileName + ".", end="")
- if verbose:
- print("sqlite3 '" + fileName + "' 'PRAGMA integrity_check;'")
integrityCheck = subprocess.run(
["sqlite3", fileName, "PRAGMA integrity_check;"],
capture_output=True,
@@ -31,6 +39,8 @@ def integrity_is_ok(fileName):
else:
print(" Errors found.")
if verbose:
+ print("sqlite3 '" + fileName + "' 'PRAGMA integrity_check;'")
+ if verbose:
print(integrityCheck)
return is_ok
@@ -149,27 +159,24 @@ 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 + "')"
- if verbose:
- print()
- print("sqlite3 '" + emptyFilePath + "'")
- print(sql + ";")
- else:
- print(".", end="", flush=True)
+ i_print(verbose, [
+ {"msg": ".", "end": "", "flush": True},
+ {"msg": "\nsqlite3 '{}'\n{};".format(emptyFilePath, sql)},
+ ])
columns = query(emptyFilePath, sql)[0]["columns"]
sql ="DELETE FROM " + table
- if verbose:
- print("sqlite3 '" + repairedFilePath + "'")
- print(sql + ";")
- else:
- print(".", end="", flush=True)
+ i_print(verbose, [
+ {"msg": ".", "end": "", "flush": True},
+ {"msg": "sqlite3 '{}'\n{};".format(repairedFilePath, sql)},
+ ])
query(repairedFilePath, sql)
sql = ("attach '" + workingcopyFilePath + "' AS old; INSERT INTO main." + table + " SELECT " +
columns + " from old." + table + ";")
- if verbose:
- print(sql + ";")
- else:
- print(".", end="", flush=True)
+ i_print(verbose, [
+ {"msg": ".", "end": "", "flush": True},
+ {"msg": "{}".format(sql)},
+ ])
query(repairedFilePath, sql)
print()
print()