|
|
@ -149,6 +149,8 @@ class Database(): |
|
|
|
total = 0 |
|
|
|
for i, octet in enumerate(address.split('.')): |
|
|
|
total += int(octet) << (3-i)*8 |
|
|
|
if total > 0xFFFFFFFF: |
|
|
|
raise ValueError |
|
|
|
return total |
|
|
|
# return '{:02x}{:02x}{:02x}{:02x}'.format( |
|
|
|
# *[int(c) for c in address.split('.')]) |
|
|
@ -192,10 +194,13 @@ class Database(): |
|
|
|
'(SELECT count(*) FROM rules ' |
|
|
|
'WHERE source=r.id)') |
|
|
|
|
|
|
|
def prune(self, before: int) -> None: |
|
|
|
def prune(self, before: int, base_only: bool = False) -> None: |
|
|
|
self.enter_step('prune') |
|
|
|
cursor = self.conn.cursor() |
|
|
|
cursor.execute('DELETE FROM rules WHERE updated<?', (before,)) |
|
|
|
cmd = 'DELETE FROM rules WHERE updated<?' |
|
|
|
if base_only: |
|
|
|
cmd += ' AND level=0' |
|
|
|
cursor.execute(cmd, (before,)) |
|
|
|
|
|
|
|
def explain(self, entry: int) -> str: |
|
|
|
# Format current |
|
|
@ -541,7 +546,14 @@ if __name__ == '__main__': |
|
|
|
help="Reconstruct the whole database") |
|
|
|
parser.add_argument( |
|
|
|
'-p', '--prune', action='store_true', |
|
|
|
help="Remove old (+6 months) entries from database") |
|
|
|
help="Remove old entries from database") |
|
|
|
parser.add_argument( |
|
|
|
'-b', '--prune-base', action='store_true', |
|
|
|
help="TODO") |
|
|
|
parser.add_argument( |
|
|
|
'-s', '--prune-before', type=int, |
|
|
|
default=(int(time.time()) - 60*60*24*31*6), |
|
|
|
help="TODO") |
|
|
|
parser.add_argument( |
|
|
|
'-r', '--references', action='store_true', |
|
|
|
help="Update the reference count") |
|
|
@ -552,8 +564,8 @@ if __name__ == '__main__': |
|
|
|
if args.initialize: |
|
|
|
DB.initialize() |
|
|
|
if args.prune: |
|
|
|
DB.prune(before=int(time.time()) - 60*60*24*31*6) |
|
|
|
if args.references and not args.prune: |
|
|
|
DB.prune(before=args.prune_before, base_only=args.prune_base) |
|
|
|
if args.references: |
|
|
|
DB.update_references() |
|
|
|
|
|
|
|
DB.close() |