Worflow: Fixed rules counts

This commit is contained in:
Geoffrey Frogeye 2019-12-13 18:36:08 +01:00
parent ab7ef609dd
commit 269b8278b5
Signed by: geoffrey
GPG key ID: D8A7ECA00A8CD3DD
5 changed files with 53 additions and 16 deletions

View file

@ -23,7 +23,7 @@ DbValue = typing.Union[None, int, float, str, bytes]
class Database():
VERSION = 4
VERSION = 5
PATH = "blocking.db"
def open(self) -> None:
@ -250,6 +250,24 @@ class Database():
else:
yield val
def count_rules(self,
first_party_only: bool = False,
) -> str:
counts: typing.List[str] = list()
cursor = self.conn.cursor()
for table in ['asn', 'ip4network', 'ip4address', 'zone', 'hostname']:
command = f'SELECT count(*) FROM rules ' \
f'INNER JOIN {table} ON rules.id = {table}.entry ' \
'WHERE rules.level = 0'
if first_party_only:
command += ' AND first_party=1'
cursor.execute(command)
count, = cursor.fetchone()
if count > 0:
counts.append(f'{table}: {count}')
return ', '.join(counts)
def get_domain(self, domain: str) -> typing.Iterable[int]:
self.enter_step('get_domain_prepare')
domain_prep = self.pack_hostname(domain)