From 76d98e639a9a2d25cdd472f81e605bbac0190840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 14 Oct 2024 16:53:32 +0200 Subject: [PATCH] prune_old_logs: add --private option --- app/prune_old_logs.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/prune_old_logs.py b/app/prune_old_logs.py index 54c63c563..fadbe4ff5 100755 --- a/app/prune_old_logs.py +++ b/app/prune_old_logs.py @@ -17,11 +17,13 @@ parser = argparse.ArgumentParser(description='Remove old log files & DB entries') parser.add_argument('--max-age', action='store', type=int, default=30, - help='maximum age in days (delete logs older than this, default=30)') + help='maximum age in days (delete logs older than this, default=30)') parser.add_argument('--source', action='store', default='CI', - help='Source DB entry tag to match (empty=all, default=CI)') + help='Source DB entry tag to match (empty=all, default=CI)') parser.add_argument('--interactive', '-i', action='store_true', default=False, - help='Interative mode: ask whether to delete the entries') + help='Interative mode: ask whether to delete the entries') +parser.add_argument('--private', action='store_true', default=False, + help='Select private logs only') args = parser.parse_args() @@ -29,16 +31,23 @@ max_age = args.max_age source = args.source interactive = args.interactive +private = args.private con = sqlite3.connect(get_db_filename(), detect_types=sqlite3.PARSE_DECLTYPES) with con: cur = con.cursor() log_ids_to_remove = [] + private_filter = '' + if len(source) == 0: - cur.execute('select Id, Date, Description from Logs') + if private: + private_filter = 'where public = 0' + cur.execute(f'select Id, Date, Description from Logs {private_filter}') else: - cur.execute('select Id, Date, Description from Logs where Source = ?', [source]) + if private: + private_filter = 'and public = 0' + cur.execute(f'select Id, Date, Description from Logs where Source = ? {private_filter}', [source]) db_tuples = cur.fetchall() print('will delete the following:')