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:
parent
cb67511848
commit
e13f3e3e13
|
@ -43,9 +43,8 @@ def web():
|
||||||
root.putChild("lib", static.File(lib_root))
|
root.putChild("lib", static.File(lib_root))
|
||||||
class Shutdown(resource.Resource):
|
class Shutdown(resource.Resource):
|
||||||
def render_GET(self, request):
|
def render_GET(self, request):
|
||||||
if 0:
|
#print("timeline ready, server shutting down")
|
||||||
print("timeline ready, server shutting down")
|
#reactor.stop()
|
||||||
reactor.stop()
|
|
||||||
return "shutting down"
|
return "shutting down"
|
||||||
root.putChild("done", Shutdown())
|
root.putChild("done", Shutdown())
|
||||||
site = server.Site(root)
|
site = server.Site(root)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
import os, traceback
|
import traceback
|
||||||
from sys import stderr
|
from sys import stderr
|
||||||
try:
|
try:
|
||||||
import readline
|
import readline
|
||||||
|
@ -12,8 +12,8 @@ from twisted.internet.threads import deferToThread, blockingCallFromThread
|
||||||
from .errors import KeyFormatError, AlreadyInputNameplateError
|
from .errors import KeyFormatError, AlreadyInputNameplateError
|
||||||
|
|
||||||
errf = None
|
errf = None
|
||||||
if 0:
|
# uncomment this to enable tab-completion debugging
|
||||||
errf = open("err", "w") if os.path.exists("err") else None
|
#import os ; errf = open("err", "w") if os.path.exists("err") else None
|
||||||
def debug(*args, **kwargs):
|
def debug(*args, **kwargs):
|
||||||
if errf:
|
if errf:
|
||||||
print(*args, file=errf, **kwargs)
|
print(*args, file=errf, **kwargs)
|
||||||
|
@ -150,7 +150,6 @@ def _input_code_with_completion(prompt, input_helper, reactor):
|
||||||
debug("==== readline-based completion is prepared")
|
debug("==== readline-based completion is prepared")
|
||||||
else:
|
else:
|
||||||
debug("==== unable to import readline, disabling completion")
|
debug("==== unable to import readline, disabling completion")
|
||||||
pass
|
|
||||||
code = input(prompt)
|
code = input(prompt)
|
||||||
# Code is str(bytes) on py2, and str(unicode) on py3. We want unicode.
|
# Code is str(bytes) on py2, and str(unicode) on py3. We want unicode.
|
||||||
if isinstance(code, bytes):
|
if isinstance(code, bytes):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
import os, time, json
|
import os, time, json
|
||||||
from collections import defaultdict
|
|
||||||
import click
|
import click
|
||||||
from humanize import naturalsize
|
from humanize import naturalsize
|
||||||
from .database import get_db
|
from .database import get_db
|
||||||
|
@ -32,65 +31,6 @@ def print_event(event):
|
||||||
def show_usage(args):
|
def show_usage(args):
|
||||||
print("closed for renovation")
|
print("closed for renovation")
|
||||||
return 0
|
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):
|
def tail_usage(args):
|
||||||
if not os.path.exists("relay.sqlite"):
|
if not os.path.exists("relay.sqlite"):
|
||||||
|
@ -117,7 +57,6 @@ def tail_usage(args):
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return 0
|
return 0
|
||||||
return 0
|
|
||||||
|
|
||||||
def count_channels(args):
|
def count_channels(args):
|
||||||
if not os.path.exists("relay.sqlite"):
|
if not os.path.exists("relay.sqlite"):
|
||||||
|
|
|
@ -510,7 +510,6 @@ class InboundConnectionFactory(protocol.ClientFactory):
|
||||||
def _proto_failed(self, f):
|
def _proto_failed(self, f):
|
||||||
# ignore these two, let Twisted log everything else
|
# ignore these two, let Twisted log everything else
|
||||||
f.trap(BadHandshake, defer.CancelledError)
|
f.trap(BadHandshake, defer.CancelledError)
|
||||||
pass
|
|
||||||
|
|
||||||
def allocate_tcp_port():
|
def allocate_tcp_port():
|
||||||
"""Return an (integer) available TCP port on localhost. This briefly
|
"""Return an (integer) available TCP port on localhost. This briefly
|
||||||
|
|
Loading…
Reference in New Issue
Block a user