aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ritter <tom@ritter.vg>2020-09-07 23:54:47 -0400
committerTom Ritter <tom@ritter.vg>2020-09-07 23:54:47 -0400
commit7deaed5205d0db6139f1c5e1f7c2b72181b1a208 (patch)
treea9f11fe72bf4b20d787bd90bbcb7a78902dac1ae
parent4671e0dec5eab28941e598f109dbf77ed551a707 (diff)
Run futurize on the codebase for python3
-rwxr-xr-xjobmanager.py4
-rwxr-xr-xjobs/EmailChecker.py4
-rwxr-xr-xjobs/HTTPServerChecker.py6
-rwxr-xr-xjobs/JobBase.py8
-rwxr-xr-xjobs/JobSpawner.py3
-rwxr-xr-xjobs/PeerChecker.py6
-rwxr-xr-xjobs/TCPServerChecker.py6
-rwxr-xr-xjobs/TLSCertExpiration.py12
-rwxr-xr-xjobs/__init__.py4
-rw-r--r--jobstate.py4
-rwxr-xr-xmain.py12
-rwxr-xr-xsamplejobs/BWAuthChecker.py5
-rwxr-xr-xsamplejobs/MetricsChecker.py1
-rwxr-xr-xstatustracker.py3
14 files changed, 54 insertions, 24 deletions
diff --git a/jobmanager.py b/jobmanager.py
index 5ba58b5..da4f356 100755
--- a/jobmanager.py
+++ b/jobmanager.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+from builtins import str
+from builtins import object
import os
import time
import logging
@@ -9,7 +11,7 @@ import requests
from jobs import JobFinder, JobBase
from jobstate import JobState
-class JobManager:
+class JobManager(object):
def __init__(self, config):
jobsFinder = JobFinder(config)
self.jobs = jobsFinder.get_jobs()
diff --git a/jobs/EmailChecker.py b/jobs/EmailChecker.py
index 74b41d9..11f1f86 100755
--- a/jobs/EmailChecker.py
+++ b/jobs/EmailChecker.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+from __future__ import absolute_import
+from builtins import str
import os
import base64
import datetime
@@ -7,7 +9,7 @@ import logging
import imaplib
-import JobBase
+from . import JobBase
class EmailChecker(JobBase.JobBase):
def executeEvery(self):
diff --git a/jobs/HTTPServerChecker.py b/jobs/HTTPServerChecker.py
index df96c1e..260f36f 100755
--- a/jobs/HTTPServerChecker.py
+++ b/jobs/HTTPServerChecker.py
@@ -1,10 +1,12 @@
#!/usr/bin/env python
+from __future__ import absolute_import
+from builtins import str
import logging
import requests
-import JobBase
-import JobSpawner
+from . import JobBase
+from . import JobSpawner
class HTTPServerChecker(JobSpawner.JobSpawner):
servers = [
diff --git a/jobs/JobBase.py b/jobs/JobBase.py
index 3561992..fc1d459 100755
--- a/jobs/JobBase.py
+++ b/jobs/JobBase.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+from builtins import str
+from builtins import object
import time
import random
import base64
@@ -8,13 +10,13 @@ import datetime
import smtplib
-class JobFrequency:
+class JobFrequency(object):
MINUTE = "minute"
HOUR = "hour"
DAY = "day"
DAY_NOON = "day_noon"
-class JobFailureNotificationFrequency:
+class JobFailureNotificationFrequency(object):
EVERYTIME = "every"
EVERYFIVEMINUTES = "5min"
EVERYTENMINUTES = "10min"
@@ -22,7 +24,7 @@ class JobFailureNotificationFrequency:
EVERYDAY = "day"
ONSTATECHANGE = "state_change"
-class JobFailureCountMinimumBeforeNotification:
+class JobFailureCountMinimumBeforeNotification(object):
ONE = 1
TWO = 2
FIVE = 5
diff --git a/jobs/JobSpawner.py b/jobs/JobSpawner.py
index ff9744f..6e2c636 100755
--- a/jobs/JobSpawner.py
+++ b/jobs/JobSpawner.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
-class JobSpawner:
+from builtins import object
+class JobSpawner(object):
"""OVERRIDE ME
Returns an array (or using 'yield') of Job objects to run"""
def get_sub_jobs(self, config):
diff --git a/jobs/PeerChecker.py b/jobs/PeerChecker.py
index 77df4ce..93c6df3 100755
--- a/jobs/PeerChecker.py
+++ b/jobs/PeerChecker.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+from __future__ import absolute_import
+from builtins import str
import os
import base64
import datetime
@@ -7,8 +9,8 @@ import datetime
import imaplib
import requests
-import JobBase
-import JobSpawner
+from . import JobBase
+from . import JobSpawner
class PeerChecker(JobSpawner.JobSpawner):
class IndividualPeerChecker(JobBase.JobBase):
diff --git a/jobs/TCPServerChecker.py b/jobs/TCPServerChecker.py
index 6098977..b516cfa 100755
--- a/jobs/TCPServerChecker.py
+++ b/jobs/TCPServerChecker.py
@@ -1,11 +1,13 @@
#!/usr/bin/env python
+from __future__ import absolute_import
+from builtins import str
import os
import socket
import logging
-import JobBase
-import JobSpawner
+from . import JobBase
+from . import JobSpawner
class TCPServerChecker(JobSpawner.JobSpawner):
servers = [
diff --git a/jobs/TLSCertExpiration.py b/jobs/TLSCertExpiration.py
index e4b05b7..e0fb689 100755
--- a/jobs/TLSCertExpiration.py
+++ b/jobs/TLSCertExpiration.py
@@ -1,14 +1,18 @@
#!/usr/bin/env python
+from __future__ import absolute_import
+from future import standard_library
+standard_library.install_aliases()
+from builtins import str
import ssl
import time
import logging
-import httplib
+import http.client
import OpenSSL
import datetime
-import JobBase
-import JobSpawner
+from . import JobBase
+from . import JobSpawner
class TLSCertExpiration(JobSpawner.JobSpawner):
servers = [
@@ -35,7 +39,7 @@ class TLSCertExpiration(JobSpawner.JobSpawner):
def execute(self):
try:
context = ssl._create_unverified_context()
- c = httplib.HTTPSConnection(self.url, context=context)
+ c = http.client.HTTPSConnection(self.url, context=context)
c.request("GET", "/")
asn1 = c.sock.getpeercert(True)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, asn1)
diff --git a/jobs/__init__.py b/jobs/__init__.py
index 0e780eb..a6eff83 100755
--- a/jobs/__init__.py
+++ b/jobs/__init__.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+from builtins import str
+from builtins import object
import os
import sys
import inspect
@@ -11,7 +13,7 @@ import jobs
import jobs.JobBase
import jobs.JobSpawner
-class JobFinder:
+class JobFinder(object):
def __init__(self, config):
"""
Opens the jobs folder and looks at every .py module in that directory.
diff --git a/jobstate.py b/jobstate.py
index f3e7796..8ae05d0 100644
--- a/jobstate.py
+++ b/jobstate.py
@@ -1,10 +1,12 @@
#!/usr/bin/env python
+from builtins import str
+from builtins import object
import time
import logging
import datetime
-class JobState:
+class JobState(object):
def __init__(self, name, friendlyname):
self.name = name
self.friendlyname = friendlyname
diff --git a/main.py b/main.py
index 7ee5a16..63b0bca 100755
--- a/main.py
+++ b/main.py
@@ -1,5 +1,9 @@
#!/usr/bin/env python
+from __future__ import print_function
+from future import standard_library
+standard_library.install_aliases()
+from builtins import str
import os
import sys
import json
@@ -8,7 +12,7 @@ import hashlib
import logging
import argparse
import binascii
-import ConfigParser
+import configparser
import requests
@@ -45,7 +49,7 @@ if __name__ == "__main__":
args = parser.parse_args()
- config = ConfigParser.ConfigParser()
+ config = configparser.ConfigParser()
configfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'settings.cfg')
config.read(configfile)
if args.nomail:
@@ -57,11 +61,11 @@ if __name__ == "__main__":
not config.get('email', 'smtpserver') or \
not config.get('email', 'smtpport') or \
not config.get('email', 'imapserver')):
- print "Sending email address is not configured"
+ print("Sending email address is not configured")
sys.exit(1)
if not config.get('general', 'servername') or \
not config.get('general', 'alertcontact'):
- print "Default alert contact is not configured"
+ print("Default alert contact is not configured")
sys.exit(1)
diff --git a/samplejobs/BWAuthChecker.py b/samplejobs/BWAuthChecker.py
index 618075e..ff59516 100755
--- a/samplejobs/BWAuthChecker.py
+++ b/samplejobs/BWAuthChecker.py
@@ -1,5 +1,8 @@
#!/usr/bin/env python
+from __future__ import division
+from builtins import str
+from past.utils import old_div
import os
import re
import time
@@ -29,7 +32,7 @@ class BWAuthChecker(JobBase.JobBase):
now = datetime.datetime.utcfromtimestamp(time.time())
if now - then > datetime.timedelta(hours=4):
body = "The bandwidth file is more than 4 hours old.\n"
- body += str((now-then).seconds / 60) + " minutes old.\n"
+ body += str(old_div((now-then).seconds, 60)) + " minutes old.\n"
elif len(lines) < 8300:
body = "The bandwidth file has a low number of relays: " + str(len(lines)) + "\n"
except Exception as e:
diff --git a/samplejobs/MetricsChecker.py b/samplejobs/MetricsChecker.py
index 762e46f..c0254b3 100755
--- a/samplejobs/MetricsChecker.py
+++ b/samplejobs/MetricsChecker.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
+from builtins import str
import os
import base64
import logging
diff --git a/statustracker.py b/statustracker.py
index d092266..f212566 100755
--- a/statustracker.py
+++ b/statustracker.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python
+from builtins import object
import time
import logging
-class StatusTracker:
+class StatusTracker(object):
emailNotificationsAreWorking = False
lastRunJob = 0
def __init__(self, config):