Workflow: POO and individual tables per types
Mostly for performances reasons. First one to implement threading later. Second one to speed up the dichotomy, but it doesn't seem that much better so far.
This commit is contained in:
parent
1484733a90
commit
57416b6e2c
10 changed files with 525 additions and 360 deletions
52
feed_dns.py
52
feed_dns.py
|
|
@ -3,42 +3,56 @@
|
|||
import database
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
FUNCTION_MAP = {
|
||||
b'a': database.feed_a,
|
||||
b'cname': database.feed_cname,
|
||||
}
|
||||
import logging
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
# Parsing arguments
|
||||
log = logging.getLogger('feed_dns')
|
||||
parser = argparse.ArgumentParser(
|
||||
description="TODO")
|
||||
parser.add_argument(
|
||||
'-i', '--input', type=argparse.FileType('rb'), default=sys.stdin.buffer,
|
||||
# '-i', '--input', type=argparse.FileType('rb'), default=sys.stdin.buffer,
|
||||
'-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
|
||||
help="TODO")
|
||||
args = parser.parse_args()
|
||||
|
||||
database.open_db()
|
||||
DB = database.Database()
|
||||
|
||||
try:
|
||||
database.time_step('iowait')
|
||||
line: bytes
|
||||
DB.enter_step('iowait')
|
||||
# line: bytes
|
||||
line: str
|
||||
for line in args.input:
|
||||
database.time_step('feed_json_parse')
|
||||
split = line.split(b'"')
|
||||
name = split[7]
|
||||
dtype = split[11]
|
||||
value = split[15]
|
||||
DB.enter_step('feed_json_parse')
|
||||
# split = line.split(b'"')
|
||||
split = line.split('"')
|
||||
try:
|
||||
name = split[7]
|
||||
dtype = split[11]
|
||||
value = split[15]
|
||||
except IndexError:
|
||||
log.error("Invalid JSON: %s", line)
|
||||
continue
|
||||
# DB.enter_step('feed_json_assert')
|
||||
# data = json.loads(line)
|
||||
# assert dtype == data['type']
|
||||
# assert name == data['name']
|
||||
# assert value == data['value']
|
||||
database.time_step('feed_switch')
|
||||
FUNCTION_MAP[dtype](name, value)
|
||||
database.time_step('iowait')
|
||||
|
||||
DB.enter_step('feed_switch')
|
||||
if dtype == 'a':
|
||||
for rule in DB.get_ip4(value):
|
||||
DB.set_hostname(name, source=rule)
|
||||
elif dtype == 'cname':
|
||||
for rule in DB.get_domain(value):
|
||||
DB.set_hostname(name, source=rule)
|
||||
elif dtype == 'ptr':
|
||||
for rule in DB.get_domain(value):
|
||||
DB.set_ip4address(name, source=rule)
|
||||
DB.enter_step('iowait')
|
||||
except KeyboardInterrupt:
|
||||
print("Interupted.")
|
||||
log.warning("Interupted.")
|
||||
pass
|
||||
|
||||
database.close_db()
|
||||
DB.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue