Commit ae0c991a authored by Aurel's avatar Aurel

futurize stage1

parent 36685c06
......@@ -9,6 +9,7 @@
# versioneer-0.18 (https://github.com/warner/python-versioneer)
"""Git implementation of _version.py."""
from __future__ import print_function
import errno
import os
......
......@@ -398,7 +398,7 @@ class Kedifa(object):
request_body = environ['wsgi.input'].read(request_body_size)
try:
certificate = self.checkKeyCertificate(request_body)
except CertificateError, e:
except CertificateError as e:
start_response('422 Unprocessable Entity', headers_text_plain)
return e
else:
......
from __future__ import print_function
from __future__ import absolute_import
# Copyright (C) 2018 Nexedi SA
# Lukasz Nowak <luke@nexedi.com>
#
......@@ -22,8 +24,8 @@ import httplib
import requests
import sys
import app
from updater import Updater
from . import app
from .updater import Updater
def http(*args):
......@@ -120,12 +122,12 @@ def getter(*args):
response = requests.get(url, verify=parsed.server_ca_certificate.name,
cert=parsed.identity.name)
except Exception as e:
print '%r not downloaded, problem %s' % (url, e)
print('%r not downloaded, problem %s' % (url, e))
sys.exit(1)
else:
if response.status_code != httplib.OK:
print '%r not downloaded, HTTP code %s' % (
url, response.status_code)
print('%r not downloaded, HTTP code %s' % (
url, response.status_code))
sys.exit(1)
if len(response.text) > 0:
with open(parsed.out, 'w') as out:
......
from __future__ import absolute_import
# Copyright (C) 2018 Nexedi SA
# Lukasz Nowak <luke@nexedi.com>
#
......@@ -17,7 +18,7 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import StringIO
from io import StringIO
import contextlib
import datetime
import httplib
......@@ -48,8 +49,8 @@ from cryptography.x509.oid import NameOID
import caucase.cli
import caucase.http
import cli
import updater
from . import cli
from . import updater
def findFreeTCPPort(ip=''):
......@@ -702,7 +703,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def test_GET_invalid_yet(self):
from app import SQLite3Storage
from .app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
_, key_pem, _, certificate_pem = self.generateKeyCertificateData()
not_valid_before = datetime.datetime.utcnow() + datetime.timedelta(days=10)
......@@ -770,7 +771,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def test_GET_expired(self):
from app import SQLite3Storage
from .app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
_, key_pem, _, certificate_pem = self.generateKeyCertificateData()
not_valid_before = datetime.datetime.utcnow() - datetime.timedelta(days=10)
......@@ -1060,7 +1061,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def addExpiredNonvalidyetCertificate(self, key):
from app import SQLite3Storage
from .app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
not_valid_before_valid = datetime.datetime.utcnow() - \
......@@ -1090,7 +1091,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def _getDBCertificateCount(self):
from app import SQLite3Storage
from .app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
return pocket_db._executeSingleRow(
'SELECT COUNT(*) FROM certificate')['COUNT(*)']
......
from __future__ import print_function
import httplib
import json
import os
......@@ -38,11 +39,11 @@ class Updater(object):
elif len(line_content) == 3:
url, certificate, fallback = line_content
else:
print 'Line %r is incorrect' % (line,)
print('Line %r is incorrect' % (line,))
continue
if certificate in self.mapping:
print 'Line %r is incorrect, duplicated certificate %r' % (
line, certificate)
print('Line %r is incorrect, duplicated certificate %r' % (
line, certificate))
raise ValueError
self.mapping[certificate] = (url, fallback)
......@@ -53,16 +54,16 @@ class Updater(object):
url, verify=self.server_ca_certificate_file, cert=self.identity_file,
timeout=10)
except Exception as e:
print 'Certificate %r: problem with %r not downloaded: %s' % (
certificate_file, url, e)
print('Certificate %r: problem with %r not downloaded: %s' % (
certificate_file, url, e))
else:
if response.status_code != httplib.OK:
print 'Certificate %r: %r not downloaded, HTTP code %s' % (
certificate_file, url, response.status_code)
print('Certificate %r: %r not downloaded, HTTP code %s' % (
certificate_file, url, response.status_code))
else:
certificate = response.text
if len(certificate) == 0:
print 'Certificate %r: %r is empty' % (certificate_file, url,)
print('Certificate %r: %r is empty' % (certificate_file, url,))
return certificate
def updateCertificate(self, certificate_file, master_content=None):
......@@ -98,7 +99,7 @@ class Updater(object):
if current != certificate:
with open(certificate_file, 'w') as fh:
fh.write(certificate)
print 'Certificate %r: updated from %r' % (certificate_file, url)
print('Certificate %r: updated from %r' % (certificate_file, url))
return True
else:
return False
......@@ -106,7 +107,7 @@ class Updater(object):
def callOnUpdate(self):
if self.on_update is not None:
status = os.system(self.on_update)
print 'Called %r with status %i' % (self.on_update, status)
print('Called %r with status %i' % (self.on_update, status))
def readState(self):
self.state_dict = {}
......@@ -137,8 +138,8 @@ class Updater(object):
open(self.master_certificate_file, 'w').write(
open(master_certificate_file_fallback, 'r').read()
)
print 'Prepare: Used %r for %r' % (
master_certificate_file_fallback, self.master_certificate_file)
print('Prepare: Used %r for %r' % (
master_certificate_file_fallback, self.master_certificate_file))
master_content = None
if self.master_certificate_file and os.path.exists(
......@@ -150,11 +151,11 @@ class Updater(object):
continue
if fallback and os.path.exists(fallback):
open(certificate, 'w').write(open(fallback, 'r').read())
print 'Prepare: Used %r for %r' % (fallback, certificate)
print('Prepare: Used %r for %r' % (fallback, certificate))
elif master_content:
open(certificate, 'w').write(master_content)
print 'Prepare: Used %r for %r' % (
self.master_certificate_file, certificate)
print('Prepare: Used %r for %r' % (
self.master_certificate_file, certificate))
def action(self):
self.readState()
......@@ -170,8 +171,8 @@ class Updater(object):
with open(self.master_certificate_file, 'r') as fh:
master_content = fh.read() or None
if master_content:
print 'Using master certificate from %r' % (
self.master_certificate_file,)
print('Using master certificate from %r' % (
self.master_certificate_file,))
except IOError:
pass
......@@ -189,12 +190,12 @@ class Updater(object):
if not self.prepare_only:
lock = zc.lockfile.LockFile(self.state_lock_file)
except zc.lockfile.LockError as e:
print e,
print(e, end=' ')
if self.once or self.prepare_only:
print '...exiting.'
print('...exiting.')
sys.exit(1)
else:
print "...will try again later."
print("...will try again later.")
else:
try:
self.prepare()
......@@ -206,8 +207,8 @@ class Updater(object):
try:
os.unlink(self.state_lock_file)
except Exception as e:
print 'Problem while unlinking %r' % (self.state_lock_file,)
print('Problem while unlinking %r' % (self.state_lock_file,))
if self.once or self.prepare_only:
break
print 'Sleeping for %is' % (self.sleep,)
print('Sleeping for %is' % (self.sleep,))
time.sleep(self.sleep)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment