2019-12-17 13:50:39 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import database
|
|
|
|
import time
|
|
|
|
import os
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# Parsing arguments
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Database operations")
|
|
|
|
parser.add_argument(
|
|
|
|
'-i', '--initialize', action='store_true',
|
|
|
|
help="Reconstruct the whole database")
|
|
|
|
parser.add_argument(
|
|
|
|
'-p', '--prune', action='store_true',
|
|
|
|
help="Remove old entries from database")
|
|
|
|
parser.add_argument(
|
|
|
|
'-b', '--prune-base', action='store_true',
|
2019-12-19 08:05:05 +01:00
|
|
|
help="With --prune, only prune base rules "
|
|
|
|
"(the ones added by ./feed_rules.py)")
|
2019-12-17 13:50:39 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'-s', '--prune-before', type=int,
|
|
|
|
default=(int(time.time()) - 60*60*24*31*6),
|
2019-12-19 08:05:05 +01:00
|
|
|
help="With --prune, only rules updated before "
|
|
|
|
"this UNIX timestamp will be deleted")
|
2019-12-17 13:50:39 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'-r', '--references', action='store_true',
|
2019-12-19 08:05:05 +01:00
|
|
|
help="DEBUG: Update the reference count")
|
2019-12-17 13:50:39 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if not args.initialize:
|
|
|
|
DB = database.Database()
|
|
|
|
else:
|
|
|
|
if os.path.isfile(database.Database.PATH):
|
|
|
|
os.unlink(database.Database.PATH)
|
|
|
|
DB = database.Database()
|
|
|
|
|
|
|
|
DB.enter_step('main')
|
|
|
|
if args.prune:
|
|
|
|
DB.prune(before=args.prune_before, base_only=args.prune_base)
|
|
|
|
if args.references:
|
|
|
|
DB.update_references()
|
|
|
|
|
|
|
|
DB.save()
|