From 6d56fc39ec01ffe01475d5a3aaa0775bf77b77f0 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 28 Sep 2020 11:25:59 -0700 Subject: [PATCH] Coverage now uses a SQLite database, so it's much easier to edit the data directly --- fixpaths.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fixpaths.py b/fixpaths.py index 3fa1a27..ce2f2cd 100755 --- a/fixpaths.py +++ b/fixpaths.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 +import sqlite3 import os from argparse import ArgumentParser -from coverage import CoverageData - def get_args(): parser = ArgumentParser() @@ -12,19 +11,21 @@ def get_args(): def fix_paths(coverage_file): + # Get the file name, and extrapolate the base path file_name = os.path.abspath(coverage_file) base_path = os.path.dirname(file_name) - data = CoverageData() - data.read_file(file_name) - new_lines = {} - for fname, report in data._lines.items(): - if fname.startswith('C:\\'): - # This is a Windows path, let's fudge it - fname = fname.replace('C:', '').replace('\\', '/') - new_fname = os.path.join(base_path, fname.split('openlp/openlp/')[-1]) - new_lines[new_fname] = report - data._lines = new_lines - data.write_file(file_name) + # Open a connection to the SQLite database + db = sqlite3.connect(file_name) + cursor = db.cursor() + # Get all the files in the database and update their filenames + cursor.execute('SELECT id, path FROM file') + new_files = [] + for row in cursor.fetchall(): + new_files.append((os.path.join(base_path, row[1].split('openlp/openlp/')[-1]), row[0])) + cursor.executemany('UPDATE file SET path = ? WHERE id = ?', new_files) + db.commit() + cursor.close() + db.close() if __name__ == '__main__':