clean up some commented-out stuff

This commit is contained in:
Connor Olding 2021-08-13 02:32:21 -07:00
parent 12d0b4b738
commit f1a5cbe69f
3 changed files with 1 additions and 33 deletions

View File

@ -3,7 +3,7 @@ from .util import concat_nonsense, rot13, head
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)

View File

@ -169,7 +169,6 @@ async def try_ip(db, server_ip, checks, context, opts: Options, callback=None):
await sem.acquire()
if not success:
break
#lament("ENTRY", server_ip, check)
task = create_task(process(check))
tasks.append(task)
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.commit()
#lament("TESTED", server_ip)
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 = []
while (res := await try_me.get()) is not None:
#lament("TRYING", ip)
if len(tasks) > 0:
await sleep(opts.ip_wait)
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:
await task
#lament("EXITING try_all_ips")
def sync_database(db, callback=None):
# NOTE: this no longer takes Options.
@ -260,19 +254,15 @@ async def locate_ips(db, locate_me, ipinfo):
last_save = time()
while (ip := await locate_me.get()) is not None:
if ipinfo is not None and ip not in seen:
#lament("LOCATE", ip)
seen.add(ip)
code = await ipinfo.find_country(ip)
if db is not None:
db.modify_address(ip, country_code=code)
if time() >= last_save + 10.0: # only flush occasionally
#lament("FLUSH", time() - last_save)
ipinfo.flush()
last_save = time()
ipinfo.flush()
#lament("EXITING locate_ips")
async def read_all_ips(filepaths, blocking=False, callback=None):
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:
f = stdin if filepath == "" else open(filepath, "r")
for ip in read_ips(f):
#lament("READ", ip)
await callback(ip)
if f != stdin:
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]
with IpReader(*fps) as reader:
async for ip in reader:
#lament("READ", ip)
await callback(ip, reader.total)
#lament("EXITING read_all_ips")
async def main(db, filepaths, checks, ipinfo, opts: Options):
# 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:
# reading -> trying -> locating
#lament("AWAIT reading")
await reading
#lament("AWAITED reading")
if seen == 0 and db is not None:
#lament("UPDATING country codes")
# no IPs were provided. refresh all the country codes instead.
all_ips = db.all_ips()
for i, ip in enumerate(all_ips):
#lament("UPDATING", ip)
if opts.progress:
lament(f"#{i + 1}/{len(all_ips)}: {ip}")
await locate_me.put(ip)
await try_me.put(None)
#lament("AWAIT trying")
await trying
#lament("AWAITED trying")
while not deferred.empty():
await locate_me.put(deferred.get())
#lament("STOPPING locating")
await locate_me.put(None)
#lament("AWAIT locating")
await locating
#lament("AWAITED locating")
if context is not None and hasattr(context, "finish"):
await context.finish()

View File

@ -70,7 +70,6 @@ class TKind(Base, AttrCheck):
# parents:
exception = relationship("TException", back_populates="kinds")
#exception = Column(xxid, Reference, "TException.exception_id")
# children:
domains = relationship("TDomain", back_populates="kind")
@ -87,7 +86,6 @@ class TDomain(Base, AttrCheck):
# parents:
kind = relationship("TKind", back_populates="domains")
#kind = Column(kind_id, Reference, "TKind.kind_id")
# children:
messages = relationship("TMessage", back_populates="domain")
@ -101,7 +99,6 @@ class TRecord(Base, AttrCheck):
# parents:
address = relationship("TAddress", back_populates="records")
#address = Column(address_id, Reference, "TAddress.address_id")
class TMessage(Base, AttrCheck):
@ -119,7 +116,3 @@ class TMessage(Base, AttrCheck):
server = relationship("TAddress", back_populates="messages")
domain = relationship("TDomain", 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")