Worflow: Fixed rules counts
This commit is contained in:
parent
ab7ef609dd
commit
269b8278b5
5 changed files with 53 additions and 16 deletions
20
database.py
20
database.py
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue