From ac38dba94b01f593b2da176248e466da6b11f54f Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Thu, 30 Jan 2020 22:19:42 +0000 Subject: [PATCH] Ran scripts invoked from bin/hourly and bin/daily through pyflakes3 and test invocation, and tweaked the code (with an added comment) to consistently require virtualenv to be set up before script invocation. - Legacy-Id: 17269 --- ietf/bin/expire-ids | 9 ++++++++- ietf/bin/expire-last-calls | 10 ++++++++-- ietf/bin/iana-changes-updates | 14 ++++++++------ ietf/bin/iana-protocols-updates | 13 +++++++------ ietf/bin/rfc-editor-index-updates | 9 ++++++--- ietf/bin/send-review-reminders | 15 +++++++-------- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/ietf/bin/expire-ids b/ietf/bin/expire-ids index 866196aa9..7d11a3ba2 100755 --- a/ietf/bin/expire-ids +++ b/ietf/bin/expire-ids @@ -1,6 +1,11 @@ #!/usr/bin/env python -import datetime, os, sys +# This script requires that the proper virtual python environment has been +# invoked before start + +import datetime +import os +import sys import syslog # boilerplate @@ -17,6 +22,8 @@ syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) import django django.setup() +# ---------------------------------------------------------------------- + from ietf.utils.log import logger try: diff --git a/ietf/bin/expire-last-calls b/ietf/bin/expire-last-calls index 1cbdc608f..83b565e19 100755 --- a/ietf/bin/expire-last-calls +++ b/ietf/bin/expire-last-calls @@ -1,6 +1,10 @@ #!/usr/bin/env python -import datetime, os, sys +# This script requires that the proper virtual python environment has been +# invoked before start + +import os +import sys import syslog # boilerplate @@ -17,7 +21,9 @@ syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) import django django.setup() -from ietf.doc.lastcall import * +# ---------------------------------------------------------------------- + +from ietf.doc.lastcall import get_expired_last_calls, expire_last_call drafts = get_expired_last_calls() for doc in drafts: diff --git a/ietf/bin/iana-changes-updates b/ietf/bin/iana-changes-updates index db9a165a1..817f7e533 100755 --- a/ietf/bin/iana-changes-updates +++ b/ietf/bin/iana-changes-updates @@ -1,6 +1,11 @@ #!/usr/bin/env python -import os, sys, re, json, datetime, optparse +# This script requires that the proper virtual python environment has been +# invoked before start + +import datetime +import os +import sys import syslog # boilerplate @@ -8,10 +13,6 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) sys.path = [ basedir ] + sys.path os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings" -virtualenv_activation = os.path.join(basedir, "env", "bin", "activate_this.py") -if os.path.exists(virtualenv_activation): - execfile(virtualenv_activation, dict(__file__=virtualenv_activation)) - import django django.setup() @@ -47,8 +48,9 @@ if options.end: syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) +# ---------------------------------------------------------------------- -from ietf.sync.iana import * +from ietf.sync.iana import fetch_changes_json, parse_changes_json, update_history_with_changes syslog.syslog("Updating history log with new changes from IANA from %s, period %s - %s" % (settings.IANA_SYNC_CHANGES_URL, start, end)) diff --git a/ietf/bin/iana-protocols-updates b/ietf/bin/iana-protocols-updates index 5423ccce6..0c87ccace 100755 --- a/ietf/bin/iana-protocols-updates +++ b/ietf/bin/iana-protocols-updates @@ -1,6 +1,11 @@ #!/usr/bin/env python -import os, sys, re, json, datetime +# This script requires that the proper virtual python environment has been +# invoked before start + +import os +import sys +import datetime import syslog # boilerplate @@ -8,17 +13,13 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) sys.path = [ basedir ] + sys.path os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings" -virtualenv_activation = os.path.join(basedir, "env", "bin", "activate_this.py") -if os.path.exists(virtualenv_activation): - execfile(virtualenv_activation, dict(__file__=virtualenv_activation)) - syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) import django django.setup() from django.conf import settings -from ietf.sync.iana import * +from ietf.sync.iana import fetch_protocol_page, parse_protocol_page, update_rfc_log_from_protocol_page def chunks(l, n): """Split list l up in chunks of max size n.""" diff --git a/ietf/bin/rfc-editor-index-updates b/ietf/bin/rfc-editor-index-updates index 281d8afe0..734c811b9 100755 --- a/ietf/bin/rfc-editor-index-updates +++ b/ietf/bin/rfc-editor-index-updates @@ -1,9 +1,13 @@ #!/usr/bin/env python +# This script requires that the proper virtual python environment has been +# invoked before start + import datetime import json import os import sys +import syslog import traceback from six.moves.urllib.request import urlopen @@ -13,9 +17,8 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) sys.path = [ basedir ] + sys.path os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings" -virtualenv_activation = os.path.join(basedir, "env", "bin", "activate_this.py") -if os.path.exists(virtualenv_activation): - execfile(virtualenv_activation, dict(__file__=virtualenv_activation)) +# Before invoking django +syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) import django django.setup() diff --git a/ietf/bin/send-review-reminders b/ietf/bin/send-review-reminders index 581c8ddc1..f20cc52d4 100755 --- a/ietf/bin/send-review-reminders +++ b/ietf/bin/send-review-reminders @@ -1,5 +1,9 @@ #!/usr/bin/env python +# This script requires that the proper virtual python environment has been +# invoked before start + +import datetime import os import sys import syslog @@ -9,18 +13,13 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) sys.path = [ basedir ] + sys.path os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings" -virtualenv_activation = os.path.join(basedir, "env", "bin", "activate_this.py") -if os.path.exists(virtualenv_activation): - with open(virtualenv_activation, 'rb') as f: - code = compile(f.read(), virtualenv_activation, 'exec') - exec(code, dict(__name__="__main__", __file__=virtualenv_activation)) - +# Before invoking django syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) import django django.setup() -import datetime + from ietf.review.utils import ( review_assignments_needing_reviewer_reminder, email_reviewer_reminder, review_assignments_needing_secretary_reminder, email_secretary_reminder, @@ -53,4 +52,4 @@ for msg in open_reviews_reminders_sent: unconfirmed_assignment_reminders_sent = send_reminder_unconfirmed_assignments(today) for msg in unconfirmed_assignment_reminders_sent: - log(msag) + log(msg)