From 9068136a8ef8bcfd2eb37f532390ae5946dd8c6f Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Thu, 18 Jun 2020 20:22:37 -0500 Subject: [PATCH] Add a CLI argument for the location of the DB. --- metrics | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/metrics b/metrics index 4cdde40..f332226 100755 --- a/metrics +++ b/metrics @@ -15,13 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import argparse import sqlite3 from modules.jenkins import JenkinsModule ENABLED_MODULES = [JenkinsModule] -def sqlite_run(command, db=":memory:", return_output=False): +def sqlite_run(command, db, return_output=False): """Run the given SQLite command on our db command must be a command that SQLite can run @@ -51,9 +52,17 @@ def main(module): run.append(module.sqlite_setup()) run.append(module.sqlite_add()) run.append(module.sqlite_time_range(days=10)) - print(sqlite_run(run, return_output=True)) + + # Use --db-location to pass to sqlite + print(sqlite_run(run, db=args.db_location, return_output=True)) if __name__ == "__main__": + # Parse CLI arguments + parser = argparse.ArgumentParser() + parser.add_argument("--db-location", type=str, default=":memory:", + help="Specify the location for the SQLite database") + args = parser.parse_args() + for module in ENABLED_MODULES: main(module)