[Git][NTPsec/ntpsec][master] 3 commits: Import io module when using Python 3
Eric S. Raymond
gitlab at mg.gitlab.com
Mon Oct 3 18:55:07 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
4a8b77dc by Matt Selsky at 2016-10-03T00:12:51-04:00
Import io module when using Python 3
Avoids:
NameError: name 'io' is not defined
- - - - -
0977006a by Matt Selsky at 2016-10-03T14:24:54-04:00
Fix exception handling in ntptrace
Reference CalledProcessError exception correctly. Fixes:
NameError: global name 'CalledProcessError' is not defined
Use python2/python3 compatible format for exceptions.
Force stderr to stdout in subprocess.check_output() so that e.output has data later.
- - - - -
6293b0b1 by Matt Selsky at 2016-10-03T14:29:24-04:00
Make sure that subprocess module calls are handling OSError exceptions
- - - - -
4 changed files:
- contrib/smartctl-temp-log
- ntpq/pyntpq
- ntptrace/ntptrace
- ntpwait/ntpwait
Changes:
=====================================
contrib/smartctl-temp-log
=====================================
--- a/contrib/smartctl-temp-log
+++ b/contrib/smartctl-temp-log
@@ -56,6 +56,9 @@ except subprocess.CalledProcessError as e:
sys.stderr.write( e.output )
sys.stderr.write( "Return code: %s\n" % e.returncode )
raise SystemExit(2)
+except OSError as e:
+ sys.stderr.write("ERROR: Could not start smartctl: %s\n" % e.strerror)
+ raise SystemExit(2)
lines = output.split( '\n' )
=====================================
ntpq/pyntpq
=====================================
--- a/ntpq/pyntpq
+++ b/ntpq/pyntpq
@@ -63,6 +63,7 @@ if str is bytes: # Python 2
return fp
else: # Python 3
+ import io
def polystr(o):
"Polymorphic string factory function"
=====================================
ntptrace/ntptrace
=====================================
--- a/ntptrace/ntptrace
+++ b/ntptrace/ntptrace
@@ -56,9 +56,12 @@ def ntp_read_vars(peer, vars, host):
cmd.append(host)
try:
- output = subprocess.check_output(cmd).decode('utf-8').splitlines()
- except CalledProcessError:
- print("Could not start ntpq: %s" % CalledProcessError.output, file=sys.stderr)
+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode('utf-8').splitlines()
+ except subprocess.CalledProcessError as e:
+ print("Could not start ntpq: %s" % e.output, file=sys.stderr)
+ raise SystemExit(1)
+ except OSError as e:
+ print("Could not start ntpq: %s" % e.strerror, file=sys.stderr)
raise SystemExit(1)
for line in output:
=====================================
ntpwait/ntpwait
=====================================
--- a/ntpwait/ntpwait
+++ b/ntpwait/ntpwait
@@ -57,6 +57,7 @@ if str is bytes: # Python 2
return fp
else: # Python 3
+ import io
def polystr(o):
"Polymorphic string factory function"
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7d6693b815eeb845b211c65e42b36ad9d0f8040f...6293b0b1e5d778f075f5b342f1b36e5db41efe12
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161003/bf03fcd5/attachment.html>
More information about the vc
mailing list