hush some unreachable-code errors found by lgtm.com

This comments out some "if 0: debug()" stuff I keep around to investigate
problems, since lgtm thinks of it as accidentally-unreachable code.

I also deleted a server usage command
entirely (src/wormhole/server/cmd_usage.py show_usage) which was disabled
while I rewrote that schema: the new plan is to move the server into a new
repository altogether, and use a completely different approach to the
usage database.
This commit is contained in:
Brian Warner 2018-01-01 16:53:18 +01:00
parent cb67511848
commit e13f3e3e13
4 changed files with 5 additions and 69 deletions

View File

@ -43,9 +43,8 @@ def web():
root.putChild("lib", static.File(lib_root))
class Shutdown(resource.Resource):
def render_GET(self, request):
if 0:
print("timeline ready, server shutting down")
reactor.stop()
#print("timeline ready, server shutting down")
#reactor.stop()
return "shutting down"
root.putChild("done", Shutdown())
site = server.Site(root)

View File

@ -1,5 +1,5 @@
from __future__ import print_function, unicode_literals
import os, traceback
import traceback
from sys import stderr
try:
import readline
@ -12,8 +12,8 @@ from twisted.internet.threads import deferToThread, blockingCallFromThread
from .errors import KeyFormatError, AlreadyInputNameplateError
errf = None
if 0:
errf = open("err", "w") if os.path.exists("err") else None
# uncomment this to enable tab-completion debugging
#import os ; errf = open("err", "w") if os.path.exists("err") else None
def debug(*args, **kwargs):
if errf:
print(*args, file=errf, **kwargs)
@ -150,7 +150,6 @@ def _input_code_with_completion(prompt, input_helper, reactor):
debug("==== readline-based completion is prepared")
else:
debug("==== unable to import readline, disabling completion")
pass
code = input(prompt)
# Code is str(bytes) on py2, and str(unicode) on py3. We want unicode.
if isinstance(code, bytes):

View File

@ -1,6 +1,5 @@
from __future__ import print_function, unicode_literals
import os, time, json
from collections import defaultdict
import click
from humanize import naturalsize
from .database import get_db
@ -32,65 +31,6 @@ def print_event(event):
def show_usage(args):
print("closed for renovation")
return 0
if not os.path.exists("relay.sqlite"):
raise click.UsageError(
"cannot find relay.sqlite, please run from the server directory"
)
oldest = None
newest = None
rendezvous_counters = defaultdict(int)
transit_counters = defaultdict(int)
total_transit_bytes = 0
db = get_db("relay.sqlite")
c = db.execute("SELECT * FROM `usage`"
" ORDER BY `started` ASC LIMIT ?",
(args.n,))
for row in c.fetchall():
if row["type"] == "rendezvous":
counters = rendezvous_counters
elif row["type"] == "transit":
counters = transit_counters
total_transit_bytes += row["total_bytes"]
else:
continue
counters["total"] += 1
counters[row["result"]] += 1
if oldest is None or row["started"] < oldest:
oldest = row["started"]
if newest is None or row["started"] > newest:
newest = row["started"]
event = (row["type"], row["started"], row["result"],
row["total_bytes"], row["waiting_time"], row["total_time"])
print_event(event)
if rendezvous_counters["total"] or transit_counters["total"]:
print("---")
print("(most recent started %s ago)" % abbrev(time.time() - newest))
if rendezvous_counters["total"]:
print("rendezvous events:")
counters = rendezvous_counters
elapsed = time.time() - oldest
total = counters["total"]
print(" %d events in %s (%.2f per hour)" % (total, abbrev(elapsed),
(3600 * total / elapsed)))
print("", ", ".join(["%s=%d (%d%%)" %
(k, counters[k], (100.0 * counters[k] / total))
for k in sorted(counters)
if k != "total"]))
if transit_counters["total"]:
print("transit events:")
counters = transit_counters
elapsed = time.time() - oldest
total = counters["total"]
print(" %d events in %s (%.2f per hour)" % (total, abbrev(elapsed),
(3600 * total / elapsed)))
rate = total_transit_bytes / elapsed
print(" %s total bytes, %sps" % (naturalsize(total_transit_bytes),
naturalsize(rate)))
print("", ", ".join(["%s=%d (%d%%)" %
(k, counters[k], (100.0 * counters[k] / total))
for k in sorted(counters)
if k != "total"]))
return 0
def tail_usage(args):
if not os.path.exists("relay.sqlite"):
@ -117,7 +57,6 @@ def tail_usage(args):
time.sleep(2)
except KeyboardInterrupt:
return 0
return 0
def count_channels(args):
if not os.path.exists("relay.sqlite"):

View File

@ -510,7 +510,6 @@ class InboundConnectionFactory(protocol.ClientFactory):
def _proto_failed(self, f):
# ignore these two, let Twisted log everything else
f.trap(BadHandshake, defer.CancelledError)
pass
def allocate_tcp_port():
"""Return an (integer) available TCP port on localhost. This briefly