summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2024-07-03 11:28:46 +0200
committercos <cos>2024-07-03 16:06:15 +0200
commitf11398a042a7de218a53d2aa567299515edf9f60 (patch)
treef354c9f1d86ef3c780a83bc961c4ad3c78588532
parentc44a17383be213b28c4cf880d23a4bd80a48c2bd (diff)
downloadAntennaPodDbFixer-f11398a042a7de218a53d2aa567299515edf9f60.zip
Refactor repeated version check into get_db_version()
-rwxr-xr-xAntennaPodDbFixer.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/AntennaPodDbFixer.py b/AntennaPodDbFixer.py
index 9966209..5e78924 100755
--- a/AntennaPodDbFixer.py
+++ b/AntennaPodDbFixer.py
@@ -9,6 +9,13 @@ import getopt
def usage():
return sys.argv[0] + " [--help] [--verbose] [corrupt.db] [empty.db]"
+def get_db_version(fileName):
+ return subprocess.run(
+ ["sqlite3", fileName, "PRAGMA user_version;"],
+ capture_output=True,
+ text=True
+ ).stdout.strip()
+
def integrity_is_ok(fileName):
print("Checking integrity of " + fileName + ".", end="")
if verbose:
@@ -62,11 +69,7 @@ else:
if verbose:
print("It seems sqlite3 on this system has the dbpage extension. Good!")
-corruptedVersion = subprocess.run(
- ["sqlite3", inputFilePath, "PRAGMA user_version;"],
- capture_output=True,
- text=True
- ).stdout.strip()
+corruptedVersion = get_db_version(inputFilePath)
if corruptedVersion == "0":
print("Error: File not found, not a database, or too corrupted for this script.", file=sys.stderr)
exit(1)
@@ -81,11 +84,7 @@ else:
if not os.path.isfile(emptyFilePath):
print("If needed, you can download old app versions on F-Droid and export an empty database.")
emptyFilePath = input("Enter file path to an EMPTY AntennaPod database with the same version: ")
-emptyVersion = subprocess.run(
- ["sqlite3", emptyFilePath, "PRAGMA user_version;"],
- capture_output=True,
- text=True
- ).stdout.strip()
+emptyVersion = get_db_version(emptyFilePath)
print("Empty file version: " + emptyVersion)
if corruptedVersion != emptyVersion:
print("Error: Application version differs between database files.", file=sys.stderr)