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