From da4e7dcfbe4add5b560d9cf689f87a3439341288 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 31 Dec 2017 00:19:41 +0100 Subject: [PATCH] hush a bunch of not-really-problems caught by the lgtm.com static analyzer This is all minor stuff: unreachable debug code (that should be commented-out instead of in an 'if False:' block), unnecessary 'pass' and 'global' statements, redundantly-initialized variables. No behavior changes. Nothing here was actually broken, it just looked suspicious to the static analysis at https://lgtm.com/projects/g/tahoe-lafs/tahoe-lafs/alerts/?mode=list . --- integration/conftest.py | 4 ++-- misc/build_helpers/show-tool-versions.py | 7 ------- misc/simulators/ringsim.py | 4 ++-- misc/simulators/simulator.py | 1 - misc/simulators/sizes.py | 2 +- src/allmydata/__init__.py | 3 +-- src/allmydata/frontends/magic_folder.py | 9 ++++----- src/allmydata/immutable/downloader/status.py | 2 -- src/allmydata/immutable/happiness_upload.py | 3 --- src/allmydata/immutable/offloaded.py | 1 - src/allmydata/mutable/publish.py | 1 - src/allmydata/node.py | 1 + src/allmydata/scripts/magic_folder_cli.py | 6 +++--- src/allmydata/scripts/tahoe_status.py | 1 - src/allmydata/scripts/tahoe_stop.py | 3 +-- src/allmydata/uri.py | 1 - src/allmydata/util/connection_status.py | 1 + src/allmydata/util/rrefutil.py | 1 - src/allmydata/web/check_results.py | 16 ++++++++-------- 19 files changed, 24 insertions(+), 43 deletions(-) diff --git a/integration/conftest.py b/integration/conftest.py index 19f5600d1..1c75f0792 100644 --- a/integration/conftest.py +++ b/integration/conftest.py @@ -331,7 +331,7 @@ def alice_invite(reactor, alice, temp_dir, request): # fairly consistently fail if we don't hack in this pause...) import time ; time.sleep(5) proto = _CollectOutputProtocol() - transport = reactor.spawnProcess( + reactor.spawnProcess( proto, sys.executable, [ @@ -345,7 +345,7 @@ def alice_invite(reactor, alice, temp_dir, request): pytest.blockon(proto.done) proto = _CollectOutputProtocol() - transport = reactor.spawnProcess( + reactor.spawnProcess( proto, sys.executable, [ diff --git a/misc/build_helpers/show-tool-versions.py b/misc/build_helpers/show-tool-versions.py index 9fd9666c3..2aa1aba19 100644 --- a/misc/build_helpers/show-tool-versions.py +++ b/misc/build_helpers/show-tool-versions.py @@ -21,7 +21,6 @@ def print_platform(): sys.stderr.write("\nGot exception using 'platform'. Exception follows\n") traceback.print_exc(file=sys.stderr) sys.stderr.flush() - pass def print_python_ver(): print "python:", foldlines(sys.version) @@ -50,7 +49,6 @@ def print_stdout(cmdlist, label=None, numlines=None): sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % (cmdlist[0],)) traceback.print_exc(file=sys.stderr) sys.stderr.flush() - pass def print_as_ver(): if os.path.exists('a.out'): @@ -66,7 +64,6 @@ def print_as_ver(): sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % ('as',)) traceback.print_exc(file=sys.stderr) sys.stderr.flush() - pass def print_setuptools_ver(): try: @@ -77,10 +74,8 @@ def print_setuptools_ver(): sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of setuptools. Exception follows\n") traceback.print_exc(file=sys.stderr) sys.stderr.flush() - pass except pkg_resources.DistributionNotFound: print 'setuptools: DistributionNotFound' - pass def print_py_pkg_ver(pkgname, modulename=None): if modulename is None: @@ -94,10 +89,8 @@ def print_py_pkg_ver(pkgname, modulename=None): sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of %s. Exception follows.\n" % (pkgname,)) traceback.print_exc(file=sys.stderr) sys.stderr.flush() - pass except pkg_resources.DistributionNotFound: print pkgname + ': DistributionNotFound' - pass try: __import__(modulename) except ImportError: diff --git a/misc/simulators/ringsim.py b/misc/simulators/ringsim.py index 74c603a66..368bd1a4c 100644 --- a/misc/simulators/ringsim.py +++ b/misc/simulators/ringsim.py @@ -38,12 +38,12 @@ def abbreviate_space(s, SI=True): def make_up_a_file_size(seed): h = int(myhash(seed).hexdigest(),16) - max=2**31 if 1: # exponential distribution e = 8 + (h % (31-8)) return 2 ** e # uniform distribution - return h % max # avg 1GB + #max=2**31 + #return h % max # avg 1GB sizes = [make_up_a_file_size(str(i)) for i in range(10000)] avg_filesize = sum(sizes)/len(sizes) diff --git a/misc/simulators/simulator.py b/misc/simulators/simulator.py index 972c95827..c1f9e9b54 100644 --- a/misc/simulators/simulator.py +++ b/misc/simulators/simulator.py @@ -268,7 +268,6 @@ class Simulator: avg_tried = sum(self.published_files) / len(self.published_files) print time, etype, self.added_data, self.failed_files, self.lost_data_bytes, avg_tried, len(self.introducer.living_files), self.introducer.utilization -global s s = None def main(): diff --git a/misc/simulators/sizes.py b/misc/simulators/sizes.py index b61eb152a..119d5b42b 100644 --- a/misc/simulators/sizes.py +++ b/misc/simulators/sizes.py @@ -166,7 +166,7 @@ def text(): print " (bytes) (%)" print "------- ------- -------- -------- ---- -- --------" #sizes = [2 ** i for i in range(7, 41)] - radix = math.sqrt(10); expstep = 2 + #radix = math.sqrt(10); expstep = 2 radix = 2; expstep = 2 #radix = 10; expstep = 1 maxexp = int(math.ceil(math.log(1e12, radix)))+2 diff --git a/src/allmydata/__init__.py b/src/allmydata/__init__.py index 4f876d6cf..1b6a5b19c 100644 --- a/src/allmydata/__init__.py +++ b/src/allmydata/__init__.py @@ -44,7 +44,6 @@ _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I) _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I) _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I) -global _distname,_version _distname = None _version = None @@ -203,7 +202,7 @@ def get_package_versions_and_locations(): pass finally: # Leave suppressions for UserWarnings and global_deprecation_messages active. - for ign in runtime_warning_messages + deprecation_messages: + for _ in runtime_warning_messages + deprecation_messages: warnings.filters.pop() packages = [] diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index da23bf455..34de0ed18 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -892,11 +892,10 @@ class WriteFileMixin(object): self._log("_rename_conflicted_file(%r, %r)" % (abspath_u, replacement_path_u)) conflict_path_u = self._get_conflicted_filename(abspath_u) - if False: - if os.path.isfile(replacement_path_u): - print "%r exists" % (replacement_path_u,) - if os.path.isfile(conflict_path_u): - print "%r exists" % (conflict_path_u,) + #if os.path.isfile(replacement_path_u): + # print "%r exists" % (replacement_path_u,) + #if os.path.isfile(conflict_path_u): + # print "%r exists" % (conflict_path_u,) fileutil.rename_no_overwrite(replacement_path_u, conflict_path_u) return conflict_path_u diff --git a/src/allmydata/immutable/downloader/status.py b/src/allmydata/immutable/downloader/status.py index 74e5fc7b6..1d6246cea 100644 --- a/src/allmydata/immutable/downloader/status.py +++ b/src/allmydata/immutable/downloader/status.py @@ -207,8 +207,6 @@ class DownloadStatus(object): return self.size def get_status(self): # mention all outstanding segment requests - outstanding = set() - errorful = set() outstanding = set([s_ev["segment_number"] for s_ev in self.segment_events if s_ev["finish_time"] is None]) diff --git a/src/allmydata/immutable/happiness_upload.py b/src/allmydata/immutable/happiness_upload.py index 49f701a5a..758102ab4 100644 --- a/src/allmydata/immutable/happiness_upload.py +++ b/src/allmydata/immutable/happiness_upload.py @@ -329,10 +329,7 @@ def share_placement(peers, readonly_peers, shares, peers_to_shares): if not peers: return dict() - homeless_shares = set() - # First calculate share placement for the readonly servers. - readonly_peers = readonly_peers readonly_shares = set() readonly_map = {} for peer in sorted(peers_to_shares.keys()): diff --git a/src/allmydata/immutable/offloaded.py b/src/allmydata/immutable/offloaded.py index 5b9e5803b..ac4bb795c 100644 --- a/src/allmydata/immutable/offloaded.py +++ b/src/allmydata/immutable/offloaded.py @@ -76,7 +76,6 @@ class CHKCheckerAndUEBFetcher: if f.check(DeadReferenceError): return log.err(f, parent=self._logparent) - pass def _get_uri_extension(self, res): # assume that we can pull the UEB from any share. If we get an error, diff --git a/src/allmydata/mutable/publish.py b/src/allmydata/mutable/publish.py index 4dbbd832a..ee17847e4 100644 --- a/src/allmydata/mutable/publish.py +++ b/src/allmydata/mutable/publish.py @@ -1077,7 +1077,6 @@ class Publish: # of highest-replaceable-seqnum or lower, we're allowed # to replace it: send out a new writev (or rather add it # to self.goal and loop). - pass surprised = True diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 2cb2a7466..8631d8580 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -413,6 +413,7 @@ class Node(service.MultiService): if cfg_location is None: cfg_location = "AUTO" + local_portnum = None # needed to hush lgtm.com static analyzer # Replace the location "AUTO", if present, with the detected local # addresses. Don't probe for local addresses unless necessary. split_location = cfg_location.split(",") diff --git a/src/allmydata/scripts/magic_folder_cli.py b/src/allmydata/scripts/magic_folder_cli.py index 8680ec5e7..53b9a3090 100644 --- a/src/allmydata/scripts/magic_folder_cli.py +++ b/src/allmydata/scripts/magic_folder_cli.py @@ -521,9 +521,9 @@ def status(options): downloads = [item for item in magic_data if item['kind'] == 'download'] longest = max([len(item['path']) for item in magic_data]) - if True: # maybe --show-completed option or something? - uploads = [item for item in uploads if item['status'] != 'success'] - downloads = [item for item in downloads if item['status'] != 'success'] + # maybe gate this with --show-completed option or something? + uploads = [item for item in uploads if item['status'] != 'success'] + downloads = [item for item in downloads if item['status'] != 'success'] if len(uploads): print diff --git a/src/allmydata/scripts/tahoe_status.py b/src/allmydata/scripts/tahoe_status.py index a926939f1..f66fdf9c5 100644 --- a/src/allmydata/scripts/tahoe_status.py +++ b/src/allmydata/scripts/tahoe_status.py @@ -137,7 +137,6 @@ def do_status(options): ) print(u"\u255f\u2500{}\u2500\u256b\u2500{}\u2500\u256b\u2500{}\u2500\u256b\u2500{}".format(u'\u2500' * 5, u'\u2500' * 26, u'\u2500' * 22, u'\u2500' * 20), file=options.stdout) for op in status_data['active']: - op_type = 'UKN ' if 'progress-hash' in op: op_type = ' put ' total = (op['progress-hash'] + op['progress-ciphertext'] + op['progress-encode-push']) / 3.0 diff --git a/src/allmydata/scripts/tahoe_stop.py b/src/allmydata/scripts/tahoe_stop.py index 1653fe3c7..804c16116 100644 --- a/src/allmydata/scripts/tahoe_stop.py +++ b/src/allmydata/scripts/tahoe_stop.py @@ -79,5 +79,4 @@ def stop(config): (pid, (time.time() - start)) wait = 10 time.sleep(1) - # we define rc=1 to mean "I think something is still running, sorry" - return 1 + # control never reaches here: no timeout diff --git a/src/allmydata/uri.py b/src/allmydata/uri.py index f4f1b1542..b2159c026 100644 --- a/src/allmydata/uri.py +++ b/src/allmydata/uri.py @@ -747,7 +747,6 @@ def from_string(u, deep_immutable=False, name=u""): s = s[len(ALLEGED_READONLY_PREFIX):] error = None - kind = "cap" try: if s.startswith('URI:CHK:'): return CHKFileURI.init_from_string(s) diff --git a/src/allmydata/util/connection_status.py b/src/allmydata/util/connection_status.py index 7cc2791b2..3f5dd5278 100644 --- a/src/allmydata/util/connection_status.py +++ b/src/allmydata/util/connection_status.py @@ -31,6 +31,7 @@ def from_foolscap_reconnector(rc, last_received): connected = False last_connected = None others = set(ci.connectorStatuses.keys()) + summary = None if state == "connected": connected = True diff --git a/src/allmydata/util/rrefutil.py b/src/allmydata/util/rrefutil.py index 6481cabc9..0dde651d3 100644 --- a/src/allmydata/util/rrefutil.py +++ b/src/allmydata/util/rrefutil.py @@ -21,7 +21,6 @@ def add_version_to_remote_reference(rref, default): def trap_and_discard(f, *errorTypes): f.trap(*errorTypes) - pass def trap_deadref(f): return trap_and_discard(f, DeadReferenceError) diff --git a/src/allmydata/web/check_results.py b/src/allmydata/web/check_results.py index c3864926b..d5178d476 100644 --- a/src/allmydata/web/check_results.py +++ b/src/allmydata/web/check_results.py @@ -250,16 +250,16 @@ class CheckResultsRenderer(CheckerBase, rend.Page, ResultsBase): def render_repair(self, ctx, data): if data.is_healthy(): return "" - repair = T.form(action=".", method="post", - enctype="multipart/form-data")[ - T.fieldset[ - T.input(type="hidden", name="t", value="check"), - T.input(type="hidden", name="repair", value="true"), - T.input(type="submit", value="Repair"), - ]] + #repair = T.form(action=".", method="post", + # enctype="multipart/form-data")[ + # T.fieldset[ + # T.input(type="hidden", name="t", value="check"), + # T.input(type="hidden", name="repair", value="true"), + # T.input(type="submit", value="Repair"), + # ]] + #return ctx.tag[repair] return "" # repair button disabled until we make it work correctly, # see #622 for details - return ctx.tag[repair] def render_results(self, ctx, data): cr = self._render_results(ctx, data)