[Git][NTPsec/ntpsec][master] 5 commits: ntpsnmpd: Fix an error message

Eric S. Raymond gitlab at mg.gitlab.com
Thu Dec 21 04:12:19 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
a30ba8f4 by Richard Laager at 2017-12-20T21:29:36-06:00
ntpsnmpd: Fix an error message

The ntp imports were copied from ntpq without correcting the command
name.

- - - - -
051622b8 by Richard Laager at 2017-12-20T21:33:54-06:00
Always use custom errors for ntp imports

Most of the utilities were already printing custom errors when importing
the ntp.* modules failed.  Now they all are.

- - - - -
a0f926a1 by Richard Laager at 2017-12-20T21:35:43-06:00
Make the NTP import errors consistent

Now all of the NTP import error messages are the same.

- - - - -
f83174f5 by Richard Laager at 2017-12-20T21:36:34-06:00
ntploggps: Fix a typo

This fixes a typo in an error message.

- - - - -
987483eb by Richard Laager at 2017-12-20T21:38:30-06:00
Sort ntp imports

- - - - -


9 changed files:

- ntpclients/ntpdig.py
- ntpclients/ntploggps.py
- ntpclients/ntplogtemp.py
- ntpclients/ntpmon.py
- ntpclients/ntpsnmpd.py
- ntpclients/ntpsweep.py
- ntpclients/ntptrace.py
- ntpclients/ntpviz.py
- ntpclients/ntpwait.py


Changes:

=====================================
ntpclients/ntpdig.py
=====================================
--- a/ntpclients/ntpdig.py
+++ b/ntpclients/ntpdig.py
@@ -47,9 +47,9 @@ import getopt
 import math
 
 try:
+    import ntp.magic
     import ntp.packet
     import ntp.util
-    import ntp.magic
 except ImportError as e:
     sys.stderr.write(
         "ntpdig: can't find Python NTP library.\n")


=====================================
ntpclients/ntploggps.py
=====================================
--- a/ntpclients/ntploggps.py
+++ b/ntpclients/ntploggps.py
@@ -28,25 +28,29 @@ import threading
 import time
 
 try:
-    package = 'GPSD'  # pylint: disable=invalid-name
-    import gps
-    package = 'NTP'  # pylint: disable=invalid-name
-    import ntp.util
-except ImportError as e:
-    sys.stderr.write("ntploggps: can't find Python %s modules.\n" % package)
-    sys.stderr.write("%s\n" % e)
-    sys.exit(1)
-
-try:
     import argparse
 except ImportError:
     sys.stderr.write("""
-ntpologgps: can't find the Python argparse module
+ntploggps: can't find the Python argparse module
          If your Python version is < 2.7, then manual installation is needed:
          # pip install argparse
 """)
     sys.exit(1)
 
+try:
+    import gps
+except ImportError as e:
+    sys.stderr.write("ntploggps: can't find Python GPSD library.\n")
+    sys.stderr.write("%s\n" % e)
+    sys.exit(1)
+
+try:
+    import ntp.util
+except ImportError as e:
+    sys.stderr.write(
+        "ntploggps: can't find Python NTP library.\n")
+    sys.stderr.write("%s\n" % e)
+    sys.exit(1)
 
 def logging_setup():
     "Create logging object"


=====================================
ntpclients/ntplogtemp.py
=====================================
--- a/ntpclients/ntplogtemp.py
+++ b/ntpclients/ntplogtemp.py
@@ -34,10 +34,11 @@ import time
 try:
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntplogtemp: can't find Python NTP modules.\n%s\n" % e)
+    sys.stderr.write(
+        "ntplogtemp: can't find Python NTP library.\n")
+    sys.stderr.write("%s\n" % e)
     sys.exit(1)
 
-
 def run_binary(cmd):
     """\
 Run a binary


=====================================
ntpclients/ntpmon.py
=====================================
--- a/ntpclients/ntpmon.py
+++ b/ntpclients/ntpmon.py
@@ -32,12 +32,12 @@ import sys
 import time
 
 try:
+    import ntp.control
+    import ntp.magic
+    import ntp.ntpc
     import ntp.packet
     import ntp.util
-    import ntp.ntpc
     import ntp.version
-    import ntp.control
-    import ntp.magic
 except ImportError as e:
     sys.stderr.write(
         "ntpmon: can't find Python NTP library.\n")


=====================================
ntpclients/ntpsnmpd.py
=====================================
--- a/ntpclients/ntpsnmpd.py
+++ b/ntpclients/ntpsnmpd.py
@@ -12,13 +12,13 @@ import select
 import subprocess
 
 try:
-    import ntp.packet
-    import ntp.util
     import ntp.agentx
     ax = ntp.agentx
+    import ntp.packet
+    import ntp.util
 except ImportError as e:
     sys.stderr.write(
-        "ntpq: can't find Python NTP library -- check PYTHONPATH.\n")
+        "ntpsnmpd: can't find Python NTP library.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpsweep.py
=====================================
--- a/ntpclients/ntpsweep.py
+++ b/ntpclients/ntpsweep.py
@@ -27,9 +27,15 @@ from __future__ import print_function
 import os
 import sys
 import getopt
-import ntp.packet
-import ntp.util
 
+try:
+    import ntp.packet
+    import ntp.util
+except ImportError as e:
+    sys.stderr.write(
+        "ntpsweep: can't find Python NTP library.\n")
+    sys.stderr.write("%s\n" % e)
+    sys.exit(1)
 
 def ntp_peers(host):
     """Return: a list of peer IP addrs for a specified host,


=====================================
ntpclients/ntptrace.py
=====================================
--- a/ntpclients/ntptrace.py
+++ b/ntpclients/ntptrace.py
@@ -17,8 +17,14 @@ import getopt
 import re
 import subprocess
 import sys
-import ntp.util
 
+try:
+    import ntp.util
+except ImportError as e:
+    sys.stderr.write(
+        "ntptrace: can't find Python NTP library.\n")
+    sys.stderr.write("%s\n" % e)
+    sys.exit(1)
 
 def get_info(host):
     info = ntp_read_vars(0, [], host)


=====================================
ntpclients/ntpviz.py
=====================================
--- a/ntpclients/ntpviz.py
+++ b/ntpclients/ntpviz.py
@@ -113,7 +113,8 @@ try:
     import ntp.statfiles
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntpviz: can't find Python NTP modules.\n")
+    sys.stderr.write(
+        "ntpviz: can't find Python NTP library.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpwait.py
=====================================
--- a/ntpclients/ntpwait.py
+++ b/ntpclients/ntpwait.py
@@ -25,10 +25,16 @@ import getopt
 import re
 import time
 import socket
-import ntp.magic
-import ntp.packet
-import ntp.util
 
+try:
+    import ntp.magic
+    import ntp.packet
+    import ntp.util
+except ImportError as e:
+    sys.stderr.write(
+        "ntpwait: can't find Python NTP library.\n")
+    sys.stderr.write("%s\n" % e)
+    sys.exit(1)
 
 class Unbuffered(object):
     def __init__(self, stream):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fd8417a90b86c14922fa7676f5ddbfd29738bbb8...987483eb58d80ee22ae4fd2aadbfcade3f083173

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fd8417a90b86c14922fa7676f5ddbfd29738bbb8...987483eb58d80ee22ae4fd2aadbfcade3f083173
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171221/4e535350/attachment.html>


More information about the vc mailing list