diff options
author | Scott Kuhl <kuhl@mtu.edu> | 2020-12-29 12:58:44 -0500 |
---|---|---|
committer | Brian May <brian@linuxpenguins.xyz> | 2021-01-01 19:32:48 +1100 |
commit | 7fc33c00201b483f75d3ca9817001fc095f23d2f (patch) | |
tree | 333f7ff3541a5757a3ee426bff23d1a78927187f /sshuttle/helpers.py | |
parent | 563f41478a2f5381ca6fa5da57d8dd9927182404 (diff) |
Refactor debug, log and Fatal messages.
This commit rewrites the log() function so that it will append a
newline at the end of the message if none is present. It doesn't make
sense to print a log message without a newline since the next log
message (which will write a prefix) expects to be starting at the
beginning of a line.
Although it isn't strictly necessary, this commit also removes any
newlines at the ends of messages. If I missed any, including the
newline at the end of the message will continue to work as it did
before.
Previously, some calls were missing the newline at the end even though
including it was necessary for subsequent messages to appear
correctly.
This code also cleans up some redundant prefixes. The log() method
will prepend the prefix and the different processes should set their
prefix as soon as they start.
Multiline messages are still supported (although the prefix for the
additional lines was changed to match the length of the prefix used
for the first line).
Diffstat (limited to 'sshuttle/helpers.py')
-rw-r--r-- | sshuttle/helpers.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/sshuttle/helpers.py b/sshuttle/helpers.py index 9f51586..372feb3 100644 --- a/sshuttle/helpers.py +++ b/sshuttle/helpers.py @@ -15,12 +15,16 @@ def log(s): global logprefix try: sys.stdout.flush() + # Put newline at end of string if line doesn't have one. + if not s.endswith("\n"): + s = s+"\n" + # Allow multi-line messages if s.find("\n") != -1: prefix = logprefix s = s.rstrip("\n") for line in s.split("\n"): sys.stderr.write(prefix + line + "\n") - prefix = "---> " + prefix = " " else: sys.stderr.write(logprefix + s) sys.stderr.flush() @@ -91,11 +95,11 @@ def resolvconf_nameservers(systemd_resolved): words = line.lower().split() if len(words) >= 2 and words[0] == 'nameserver': this_file_nsservers.append(family_ip_tuple(words[1])) - debug2("Found DNS servers in %s: %s\n" % + debug2("Found DNS servers in %s: %s" % (f, [n[1] for n in this_file_nsservers])) nsservers += this_file_nsservers except OSError as e: - debug3("Failed to read %s when looking for DNS servers: %s\n" % + debug3("Failed to read %s when looking for DNS servers: %s" % (f, e.strerror)) return nsservers @@ -215,7 +219,7 @@ def which(file, mode=os.F_OK | os.X_OK): path = get_path() rv = _which(file, mode, path) if rv: - debug2("which() found '%s' at %s\n" % (file, rv)) + debug2("which() found '%s' at %s" % (file, rv)) else: - debug2("which() could not find '%s' in %s\n" % (file, path)) + debug2("which() could not find '%s' in %s" % (file, path)) return rv |