Python 2/3 changes pulled from the production server after the switch to python 3.

- Legacy-Id: 17327
This commit is contained in:
Henrik Levkowetz 2020-02-23 01:34:52 +00:00
parent cf56beb8cc
commit d2ad86c5df
5 changed files with 19 additions and 8 deletions

View file

@ -23,7 +23,7 @@ from ietf.sync.iana import fetch_protocol_page, parse_protocol_page, update_rfc_
def chunks(l, n):
"""Split list l up in chunks of max size n."""
return (l[i:i+n] for i in xrange(0, len(l), n))
return (l[i:i+n] for i in range(0, len(l), n))
syslog.syslog("Updating history log with new RFC entries from IANA protocols page %s" % settings.IANA_SYNC_PROTOCOLS_URL)

View file

@ -37,9 +37,11 @@
from __future__ import absolute_import, print_function, unicode_literals
import locale
import os
import six
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
import django

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2012-2019, All Rights Reserved
# Copyright The IETF Trust 2012-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -13,7 +13,7 @@ import re
from six.moves.urllib.request import Request, urlopen
from django.conf import settings
from django.utils.encoding import force_str
from django.utils.encoding import smart_bytes, force_str
from django.utils.http import urlquote
import debug # pyflakes:ignore
@ -31,14 +31,14 @@ from ietf.utils.timezone import local_timezone_to_utc, email_time_to_local_timez
def fetch_protocol_page(url):
f = urlopen(settings.IANA_SYNC_PROTOCOLS_URL)
text = f.read()
text = force_str(f.read())
f.close()
return text
def parse_protocol_page(text):
"""Parse IANA protocols page to extract referenced RFCs (as
rfcXXXX document names)."""
matches = re.findall('RFC [0-9]+', text)
matches = re.findall('RFC [0-9]+', force_str(text))
res = set()
for m in matches:
res.add("rfc" + m[len("RFC "):])
@ -78,7 +78,7 @@ def fetch_changes_json(url, start, end):
# HTTP basic auth
username = "ietfsync"
password = settings.IANA_SYNC_PASSWORD
request.add_header("Authorization", "Basic %s" % base64.encodestring("%s:%s" % (username, password)).replace("\n", ""))
request.add_header("Authorization", "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""))
f = urlopen(request)
text = f.read()
f.close()

View file

@ -1,3 +1,7 @@
# Copyright The IETF Trust 2012-2020, All Rights Reserved
# -*- coding: utf-8 -*-
import datetime
import subprocess
import os
@ -73,10 +77,13 @@ def notify(request, org, notification):
if request.method == "POST":
def runscript(name):
cmd = ["python", os.path.join(SYNC_BIN_PATH, name)]
python = os.path.join(settings.BASE_DIR, "env", "bin", "python")
cmd = [python, os.path.join(SYNC_BIN_PATH, name)]
cmdstring = " ".join(cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
out = out.decode('utf-8')
err = err.decode('utf-8')
if p.returncode:
log("Subprocess error %s when running '%s': %s %s" % (p.returncode, cmd, err, out))
raise subprocess.CalledProcessError(p.returncode, cmdstring, "\n".join([err, out]))

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2017-2019, All Rights Reserved
# Copyright The IETF Trust 2017-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -30,6 +30,8 @@ class Command(BaseCommand):
for c in VersionInfo.objects.filter(used=True):
cmd = "%s %s" % (c.command, c.switch)
code, out, err = pipe(cmd)
out = out.decode('utf-8')
err = err.decode('utf-8')
if code != 0:
sys.stderr.write("Command '%s' retuned %s: \n%s\n%s\n" % (cmd, code, out, err))
else: