clean up some commented-out stuff
This commit is contained in:
parent
12d0b4b738
commit
f1a5cbe69f
3 changed files with 1 additions and 33 deletions
|
@ -3,7 +3,7 @@ from .util import concat_nonsense, rot13, head
|
||||||
from .structs import Check
|
from .structs import Check
|
||||||
|
|
||||||
|
|
||||||
def order_by_failures(checks): # descending
|
def order_by_failures(checks): # descending order
|
||||||
return sorted(checks, key=lambda check: -check.failures)
|
return sorted(checks, key=lambda check: -check.failures)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,6 @@ async def try_ip(db, server_ip, checks, context, opts: Options, callback=None):
|
||||||
await sem.acquire()
|
await sem.acquire()
|
||||||
if not success:
|
if not success:
|
||||||
break
|
break
|
||||||
#lament("ENTRY", server_ip, check)
|
|
||||||
task = create_task(process(check))
|
task = create_task(process(check))
|
||||||
tasks.append(task)
|
tasks.append(task)
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
|
@ -183,8 +182,6 @@ async def try_ip(db, server_ip, checks, context, opts: Options, callback=None):
|
||||||
db.push_entry(entry)
|
db.push_entry(entry)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
#lament("TESTED", server_ip)
|
|
||||||
|
|
||||||
return None if success else find_failure(entries)
|
return None if success else find_failure(entries)
|
||||||
|
|
||||||
|
|
||||||
|
@ -222,7 +219,6 @@ async def try_all_ips(db, try_me, checks, context, opts: Options, callback=None)
|
||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
while (res := await try_me.get()) is not None:
|
while (res := await try_me.get()) is not None:
|
||||||
#lament("TRYING", ip)
|
|
||||||
if len(tasks) > 0:
|
if len(tasks) > 0:
|
||||||
await sleep(opts.ip_wait)
|
await sleep(opts.ip_wait)
|
||||||
ip, total = res
|
ip, total = res
|
||||||
|
@ -234,8 +230,6 @@ async def try_all_ips(db, try_me, checks, context, opts: Options, callback=None)
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
await task
|
await task
|
||||||
|
|
||||||
#lament("EXITING try_all_ips")
|
|
||||||
|
|
||||||
|
|
||||||
def sync_database(db, callback=None):
|
def sync_database(db, callback=None):
|
||||||
# NOTE: this no longer takes Options.
|
# NOTE: this no longer takes Options.
|
||||||
|
@ -260,19 +254,15 @@ async def locate_ips(db, locate_me, ipinfo):
|
||||||
last_save = time()
|
last_save = time()
|
||||||
while (ip := await locate_me.get()) is not None:
|
while (ip := await locate_me.get()) is not None:
|
||||||
if ipinfo is not None and ip not in seen:
|
if ipinfo is not None and ip not in seen:
|
||||||
#lament("LOCATE", ip)
|
|
||||||
seen.add(ip)
|
seen.add(ip)
|
||||||
code = await ipinfo.find_country(ip)
|
code = await ipinfo.find_country(ip)
|
||||||
if db is not None:
|
if db is not None:
|
||||||
db.modify_address(ip, country_code=code)
|
db.modify_address(ip, country_code=code)
|
||||||
if time() >= last_save + 10.0: # only flush occasionally
|
if time() >= last_save + 10.0: # only flush occasionally
|
||||||
#lament("FLUSH", time() - last_save)
|
|
||||||
ipinfo.flush()
|
ipinfo.flush()
|
||||||
last_save = time()
|
last_save = time()
|
||||||
ipinfo.flush()
|
ipinfo.flush()
|
||||||
|
|
||||||
#lament("EXITING locate_ips")
|
|
||||||
|
|
||||||
|
|
||||||
async def read_all_ips(filepaths, blocking=False, callback=None):
|
async def read_all_ips(filepaths, blocking=False, callback=None):
|
||||||
assert callback is not None, "that doesn't make sense!"
|
assert callback is not None, "that doesn't make sense!"
|
||||||
|
@ -281,7 +271,6 @@ async def read_all_ips(filepaths, blocking=False, callback=None):
|
||||||
for filepath in filepaths:
|
for filepath in filepaths:
|
||||||
f = stdin if filepath == "" else open(filepath, "r")
|
f = stdin if filepath == "" else open(filepath, "r")
|
||||||
for ip in read_ips(f):
|
for ip in read_ips(f):
|
||||||
#lament("READ", ip)
|
|
||||||
await callback(ip)
|
await callback(ip)
|
||||||
if f != stdin:
|
if f != stdin:
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -290,11 +279,8 @@ async def read_all_ips(filepaths, blocking=False, callback=None):
|
||||||
fps = [stdin if fp == "" else fp for fp in filepaths]
|
fps = [stdin if fp == "" else fp for fp in filepaths]
|
||||||
with IpReader(*fps) as reader:
|
with IpReader(*fps) as reader:
|
||||||
async for ip in reader:
|
async for ip in reader:
|
||||||
#lament("READ", ip)
|
|
||||||
await callback(ip, reader.total)
|
await callback(ip, reader.total)
|
||||||
|
|
||||||
#lament("EXITING read_all_ips")
|
|
||||||
|
|
||||||
|
|
||||||
async def main(db, filepaths, checks, ipinfo, opts: Options):
|
async def main(db, filepaths, checks, ipinfo, opts: Options):
|
||||||
# ipinfo can be None.
|
# ipinfo can be None.
|
||||||
|
@ -331,35 +317,24 @@ async def main(db, filepaths, checks, ipinfo, opts: Options):
|
||||||
# these tasks feed each other with queues, so order them as such:
|
# these tasks feed each other with queues, so order them as such:
|
||||||
# reading -> trying -> locating
|
# reading -> trying -> locating
|
||||||
|
|
||||||
#lament("AWAIT reading")
|
|
||||||
await reading
|
await reading
|
||||||
#lament("AWAITED reading")
|
|
||||||
|
|
||||||
if seen == 0 and db is not None:
|
if seen == 0 and db is not None:
|
||||||
#lament("UPDATING country codes")
|
|
||||||
# no IPs were provided. refresh all the country codes instead.
|
# no IPs were provided. refresh all the country codes instead.
|
||||||
all_ips = db.all_ips()
|
all_ips = db.all_ips()
|
||||||
for i, ip in enumerate(all_ips):
|
for i, ip in enumerate(all_ips):
|
||||||
#lament("UPDATING", ip)
|
|
||||||
if opts.progress:
|
if opts.progress:
|
||||||
lament(f"#{i + 1}/{len(all_ips)}: {ip}")
|
lament(f"#{i + 1}/{len(all_ips)}: {ip}")
|
||||||
await locate_me.put(ip)
|
await locate_me.put(ip)
|
||||||
|
|
||||||
await try_me.put(None)
|
await try_me.put(None)
|
||||||
|
|
||||||
#lament("AWAIT trying")
|
|
||||||
await trying
|
await trying
|
||||||
#lament("AWAITED trying")
|
|
||||||
|
|
||||||
while not deferred.empty():
|
while not deferred.empty():
|
||||||
await locate_me.put(deferred.get())
|
await locate_me.put(deferred.get())
|
||||||
|
|
||||||
#lament("STOPPING locating")
|
|
||||||
await locate_me.put(None)
|
await locate_me.put(None)
|
||||||
|
|
||||||
#lament("AWAIT locating")
|
|
||||||
await locating
|
await locating
|
||||||
#lament("AWAITED locating")
|
|
||||||
|
|
||||||
if context is not None and hasattr(context, "finish"):
|
if context is not None and hasattr(context, "finish"):
|
||||||
await context.finish()
|
await context.finish()
|
||||||
|
|
|
@ -70,7 +70,6 @@ class TKind(Base, AttrCheck):
|
||||||
|
|
||||||
# parents:
|
# parents:
|
||||||
exception = relationship("TException", back_populates="kinds")
|
exception = relationship("TException", back_populates="kinds")
|
||||||
#exception = Column(xxid, Reference, "TException.exception_id")
|
|
||||||
|
|
||||||
# children:
|
# children:
|
||||||
domains = relationship("TDomain", back_populates="kind")
|
domains = relationship("TDomain", back_populates="kind")
|
||||||
|
@ -87,7 +86,6 @@ class TDomain(Base, AttrCheck):
|
||||||
|
|
||||||
# parents:
|
# parents:
|
||||||
kind = relationship("TKind", back_populates="domains")
|
kind = relationship("TKind", back_populates="domains")
|
||||||
#kind = Column(kind_id, Reference, "TKind.kind_id")
|
|
||||||
|
|
||||||
# children:
|
# children:
|
||||||
messages = relationship("TMessage", back_populates="domain")
|
messages = relationship("TMessage", back_populates="domain")
|
||||||
|
@ -101,7 +99,6 @@ class TRecord(Base, AttrCheck):
|
||||||
|
|
||||||
# parents:
|
# parents:
|
||||||
address = relationship("TAddress", back_populates="records")
|
address = relationship("TAddress", back_populates="records")
|
||||||
#address = Column(address_id, Reference, "TAddress.address_id")
|
|
||||||
|
|
||||||
|
|
||||||
class TMessage(Base, AttrCheck):
|
class TMessage(Base, AttrCheck):
|
||||||
|
@ -119,7 +116,3 @@ class TMessage(Base, AttrCheck):
|
||||||
server = relationship("TAddress", back_populates="messages")
|
server = relationship("TAddress", back_populates="messages")
|
||||||
domain = relationship("TDomain", back_populates="messages")
|
domain = relationship("TDomain", back_populates="messages")
|
||||||
exception = relationship("TException", back_populates="messages")
|
exception = relationship("TException", back_populates="messages")
|
||||||
#execution = Column(execution_id, Reference, "TExecution.execution_id")
|
|
||||||
#server = Column(server_id, Reference, "TAddress.address_id")
|
|
||||||
#domain = Column(domain_id, Reference, "TDomain.domain_id")
|
|
||||||
#exception = Column(exception_id, Reference, "TException.exception_id")
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue