From f11398a042a7de218a53d2aa567299515edf9f60 Mon Sep 17 00:00:00 2001 From: cos Date: Wed, 3 Jul 2024 11:28:46 +0200 Subject: Refactor repeated version check into get_db_version() --- AntennaPodDbFixer.py | 19 +++++++++---------- 1 file 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) -- cgit v1.2.3