From f43d1c092bf5ef2829e7f94c74af55453187b138 Mon Sep 17 00:00:00 2001 From: cos Date: Wed, 3 Jul 2024 16:22:54 +0200 Subject: fixup! Switch to format strings where suitable --- AntennaPodDbFixer.py | 27 +++++++++++++-------------- 1 file 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) -- cgit v1.2.3