Commit d60cf318 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼 Committed by Rafael Monnerat

Add support for Python 3

parent 169a3705
...@@ -22,6 +22,7 @@ setup(name=name, ...@@ -22,6 +22,7 @@ setup(name=name,
install_requires=[ install_requires=[
'slapos.libnetworkcache>=0.14.1', 'slapos.libnetworkcache>=0.14.1',
'iniparse', 'iniparse',
'six',
], ],
zip_safe=False, zip_safe=False,
entry_points={ entry_points={
......
...@@ -34,7 +34,7 @@ import logging ...@@ -34,7 +34,7 @@ import logging
from optparse import OptionParser, Option from optparse import OptionParser, Option
from time import time from time import time
import sys import sys
from signature import Config from slapcache.signature import Config
import os import os
class Parser(OptionParser): class Parser(OptionParser):
...@@ -82,10 +82,10 @@ def mkdir_p(path): ...@@ -82,10 +82,10 @@ def mkdir_p(path):
if not os.path.exists(path): if not os.path.exists(path):
os.makedirs(path) os.makedirs(path)
def create(path, text=None, mode=0666): def create(path, text=None, mode=0o666):
fd = os.open(path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, mode) fd = os.open(path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, mode)
try: try:
os.write(fd, text) os.write(fd, text.encode('utf-8'))
finally: finally:
os.close(fd) os.close(fd)
......
...@@ -28,12 +28,12 @@ ...@@ -28,12 +28,12 @@
# #
############################################################################## ##############################################################################
import ConfigParser from six.moves import configparser
import datetime import datetime
from optparse import OptionParser, Option from optparse import OptionParser, Option
import sys import sys
from signature import Signature, Config from slapcache.signature import Signature, Config
class Parser(OptionParser): class Parser(OptionParser):
""" """
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
# #
############################################################################## ##############################################################################
import ConfigParser from six.moves import configparser
import os import os
import time import time
import traceback import traceback
...@@ -39,8 +39,8 @@ import base64 ...@@ -39,8 +39,8 @@ import base64
from random import choice from random import choice
from string import ascii_lowercase from string import ascii_lowercase
from slapos.networkcachehelper import NetworkcacheClient, \ from slapos.libnetworkcache import NetworkcacheClient
helper_download_network_cached from slapos.networkcachehelper import helper_download_network_cached
class NetworkCache: class NetworkCache:
...@@ -51,7 +51,7 @@ class NetworkCache: ...@@ -51,7 +51,7 @@ class NetworkCache:
self._load() self._load()
def _load(self): def _load(self):
network_cache_info = ConfigParser.RawConfigParser() network_cache_info = configparser.RawConfigParser()
network_cache_info.read(self.configuration) network_cache_info.read(self.configuration)
network_cache_info_dict = dict(network_cache_info.items('networkcache')) network_cache_info_dict = dict(network_cache_info.items('networkcache'))
def get_(name): def get_(name):
...@@ -161,10 +161,10 @@ class Signature: ...@@ -161,10 +161,10 @@ class Signature:
if self.logger is not None: if self.logger is not None:
self.logger.debug(message) self.logger.debug(message)
else: else:
print message print(message)
def get_file_hash(self, path): def get_file_hash(self, path):
with open(path) as f: with open(path, 'rb') as f:
h = hashlib.sha256() h = hashlib.sha256()
h.update(f.read()) h.update(f.read())
base = base64.b64encode(h.digest()) base = base64.b64encode(h.digest())
...@@ -172,7 +172,7 @@ class Signature: ...@@ -172,7 +172,7 @@ class Signature:
def save_file_hash(self, path, destination): def save_file_hash(self, path, destination):
base = self.get_file_hash(path) base = self.get_file_hash(path)
with open(destination, "w") as f: with open(destination, "wb") as f:
f.write(base) f.write(base)
def _download(self, path): def _download(self, path):
...@@ -194,7 +194,7 @@ class Signature: ...@@ -194,7 +194,7 @@ class Signature:
if shacache.download(path=sha256path, required_key_list=['timestamp'], if shacache.download(path=sha256path, required_key_list=['timestamp'],
strategy=strategy, is_sha256file=True): strategy=strategy, is_sha256file=True):
self.log('File downloaded on temp. %s' % sha256path) self.log('File downloaded on temp. %s' % sha256path)
with open(sha256path) as f: with open(sha256path, 'rb') as f:
expected_sha256 = f.read() expected_sha256 = f.read()
if current_sha256 == expected_sha256: if current_sha256 == expected_sha256:
......
...@@ -28,12 +28,12 @@ ...@@ -28,12 +28,12 @@
# #
############################################################################## ##############################################################################
import ConfigParser from six.moves import configparser
import datetime import datetime
from optparse import OptionParser, Option from optparse import OptionParser, Option
import sys import sys
from signature import Signature, Config from slapcache.signature import Signature, Config
class Parser(OptionParser): class Parser(OptionParser):
""" """
......
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