Commit da4c1acf authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

wip: slapos/recipe: add Python 3 support

parent 7736231c
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from urlparse import urlparse from six.moves.urllib.parse import urlparse
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from __future__ import print_function
import os import os
from slapos import slap from slapos import slap
import signal import signal
...@@ -66,15 +67,15 @@ def runAccords(accords_conf): ...@@ -66,15 +67,15 @@ def runAccords(accords_conf):
signal.signal(signal.SIGTERM, sigtermHandler) signal.signal(signal.SIGTERM, sigtermHandler)
# Launch ACCORDS, parse & broke manifest to deploy instance # Launch ACCORDS, parse & broke manifest to deploy instance
print 'Starting ACCORDS and friends...' print('Starting ACCORDS and friends...')
subprocess.check_call(['./co-start'],cwd=accords_location, env=environment) subprocess.check_call(['./co-start'],cwd=accords_location, env=environment)
print 'Parsing manifest...' print('Parsing manifest...')
subprocess.check_call(['./co-parser', manifest_name], subprocess.check_call(['./co-parser', manifest_name],
cwd=accords_location, env=environment) cwd=accords_location, env=environment)
print 'Brokering manifest...' print('Brokering manifest...')
subprocess.check_call(['./co-broker', manifest_name], subprocess.check_call(['./co-broker', manifest_name],
cwd=accords_location, env=environment) cwd=accords_location, env=environment)
print 'Done.' print('Done.')
# Parse answer # Parse answer
# XXX # XXX
......
...@@ -54,8 +54,10 @@ class Recipe(GenericBaseRecipe): ...@@ -54,8 +54,10 @@ class Recipe(GenericBaseRecipe):
"""Start process which can launch python scripts, move or remove files or """Start process which can launch python scripts, move or remove files or
directories when installing software. directories when installing software.
""" """
if not self.options.has_key('delete') and not self.options.has_key('rename') and not\ for k in ['delete', 'rename', 'chmod', 'script', 'sql-script']:
self.options.has_key('chmod') and not self.options.has_key('script') and not self.options.has_key('sql-script'): if k in self.options:
break
else:
return "" return ""
delete = [] delete = []
chmod = [] chmod = []
...@@ -64,7 +66,7 @@ class Recipe(GenericBaseRecipe): ...@@ -64,7 +66,7 @@ class Recipe(GenericBaseRecipe):
rename_list = "" rename_list = ""
argument = [self.options['lampconfigure'], "-H", mysql_conf['mysql_host'], "-P", mysql_conf['mysql_port'], argument = [self.options['lampconfigure'], "-H", mysql_conf['mysql_host'], "-P", mysql_conf['mysql_port'],
"-p", mysql_conf['mysql_password'], "-u", mysql_conf['mysql_user']] "-p", mysql_conf['mysql_password'], "-u", mysql_conf['mysql_user']]
if not self.options.has_key('file_token'): if 'file_token' not in self.options:
argument = argument + ["-d", mysql_conf['mysql_database'], argument = argument + ["-d", mysql_conf['mysql_database'],
"--table", self.options['table_name'].strip(), "--cond", "--table", self.options['table_name'].strip(), "--cond",
self.options.get('constraint', '1').strip()] self.options.get('constraint', '1').strip()]
...@@ -72,11 +74,11 @@ class Recipe(GenericBaseRecipe): ...@@ -72,11 +74,11 @@ class Recipe(GenericBaseRecipe):
argument = argument + ["-f", self.options['file_token'].strip()] argument = argument + ["-f", self.options['file_token'].strip()]
argument += ["-t", document_root] argument += ["-t", document_root]
if self.options.has_key('delete'): if 'delete' in self.options:
delete = ["delete"] delete = ["delete"]
for fname in self.options['delete'].split(','): for fname in self.options['delete'].split(','):
delete.append(fname.strip()) delete.append(fname.strip())
if self.options.has_key('rename'): if 'rename' in self.options:
for fname in self.options['rename'].split(','): for fname in self.options['rename'].split(','):
if fname.find("=>") < 0: if fname.find("=>") < 0:
old_name = fname old_name = fname
...@@ -86,18 +88,18 @@ class Recipe(GenericBaseRecipe): ...@@ -86,18 +88,18 @@ class Recipe(GenericBaseRecipe):
else: else:
fname = fname.split("=>") fname = fname.split("=>")
cmd = ["rename"] cmd = ["rename"]
if self.options.has_key('rename_chmod'): if 'rename_chmod' in self.options:
cmd += ["--chmod", self.options['rename_chmod'].strip()] cmd += ["--chmod", self.options['rename_chmod'].strip()]
rename.append(cmd + [fname[0].strip(), fname[1].strip()]) rename.append(cmd + [fname[0].strip(), fname[1].strip()])
rename_list += fname[0] + " to " + fname[1] + " " rename_list += fname[0] + " to " + fname[1] + " "
if self.options.has_key('chmod'): if 'chmod' in self.options:
chmod = ["chmod", self.options['mode'].strip()] chmod = ["chmod", self.options['mode'].strip()]
for fname in self.options['chmod'].split(','): for fname in self.options['chmod'].split(','):
chmod.append(fname.strip()) chmod.append(fname.strip())
if self.options.has_key('script') and \ if 'script' in self.options and \
self.options['script'].strip().endswith(".py"): self.options['script'].strip().endswith(".py"):
data = ["run", self.options['script'].strip(), "-v", mysql_conf['mysql_database'], url, document_root] data = ["run", self.options['script'].strip(), "-v", mysql_conf['mysql_database'], url, document_root]
if self.options.has_key('sql-script'): if 'sql-script' in self.options:
data = ["sql", self.options['sql-script'].strip(), "-v", mysql_conf['mysql_database'], url, document_root] data = ["sql", self.options['sql-script'].strip(), "-v", mysql_conf['mysql_database'], url, document_root]
......
from __future__ import print_function
import subprocess import subprocess
def executeRunner(arguments, delete, rename, chmod, data): def executeRunner(arguments, delete, rename, chmod, data):
...@@ -6,17 +7,17 @@ def executeRunner(arguments, delete, rename, chmod, data): ...@@ -6,17 +7,17 @@ def executeRunner(arguments, delete, rename, chmod, data):
exist into database. exist into database.
""" """
if delete: if delete:
print "Calling lampconfigure with 'delete' arguments" print("Calling lampconfigure with 'delete' arguments")
subprocess.call(arguments + delete) subprocess.call(arguments + delete)
if rename: if rename:
for parameters in rename: for parameters in rename:
print "Calling lampconfigure with 'rename' arguments" print("Calling lampconfigure with 'rename' arguments")
subprocess.call(arguments + parameters) subprocess.call(arguments + parameters)
if chmod: if chmod:
print "Calling lampconfigure with 'chmod' arguments" print("Calling lampconfigure with 'chmod' arguments")
subprocess.call(arguments + chmod) subprocess.call(arguments + chmod)
if data: if data:
print "Calling lampconfigure with 'run' arguments" print("Calling lampconfigure with 'run' arguments")
print arguments + data print(arguments + data)
subprocess.call(arguments + data) subprocess.call(arguments + data)
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from __future__ import print_function
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
import os import os
import subprocess import subprocess
...@@ -177,7 +178,7 @@ class Recipe(GenericBaseRecipe): ...@@ -177,7 +178,7 @@ class Recipe(GenericBaseRecipe):
copyright=self.copyright, installroot=self.installroot)) copyright=self.copyright, installroot=self.installroot))
) )
path_list.append(sh_script) path_list.append(sh_script)
os.chmod(bash , 0700) os.chmod(bash , 0o700)
#After make_project run configure_script to perform and restart apache php services #After make_project run configure_script to perform and restart apache php services
service_status = os.path.join(self.home, '.start_service') service_status = os.path.join(self.home, '.start_service')
...@@ -234,9 +235,9 @@ class App(GenericBaseRecipe): ...@@ -234,9 +235,9 @@ class App(GenericBaseRecipe):
downloader = zc.buildout.download.Download(self.buildout['buildout'], downloader = zc.buildout.download.Download(self.buildout['buildout'],
hash_name=True, cache=cache) hash_name=True, cache=cache)
path, _ = downloader(param, md5sum=None) path, _ = downloader(param, md5sum=None)
mode = 0600 mode = 0o600
if key == 'binary': if key == 'binary':
mode = 0700 mode = 0o700
os.chmod(path, mode) os.chmod(path, mode)
app[key] = path app[key] = path
...@@ -278,7 +279,7 @@ class App(GenericBaseRecipe): ...@@ -278,7 +279,7 @@ class App(GenericBaseRecipe):
if not current_app['template-result'] or not current_app['binary'] \ if not current_app['template-result'] or not current_app['binary'] \
or not current_app['input-file'] or not current_app['template-wu'] \ or not current_app['input-file'] or not current_app['template-wu'] \
or not current_app['platform']: or not current_app['platform']:
print "BOINC-APP: ERROR - Invalid argements values for % ...operation cancelled" % app print("BOINC-APP: ERROR - Invalid argements values for % ...operation cancelled" % app)
app_list[app][version] = None app_list[app][version] = None
continue continue
#write application to install #write application to install
...@@ -319,7 +320,7 @@ class App(GenericBaseRecipe): ...@@ -319,7 +320,7 @@ class App(GenericBaseRecipe):
dict(dash=self.options['dash'].strip())) dict(dash=self.options['dash'].strip()))
) )
path_list.append(sh_script) path_list.append(sh_script)
os.chmod(bash , 0700) os.chmod(bash , 0o700)
#If useful, download necessary files and update options path #If useful, download necessary files and update options path
start_boinc = os.path.join(home, '.start_boinc') start_boinc = os.path.join(home, '.start_boinc')
...@@ -339,7 +340,7 @@ class App(GenericBaseRecipe): ...@@ -339,7 +340,7 @@ class App(GenericBaseRecipe):
platform = app_list[appname][version]['platform'] platform = app_list[appname][version]['platform']
application = os.path.join(apps_dir, appname, version, platform) application = os.path.join(apps_dir, appname, version, platform)
if app_list[appname][version]['binary'] and not platform: if app_list[appname][version]['binary'] and not platform:
print "BOINC-APP: WARNING - Cannot specify binary without giving platform value" print("BOINC-APP: WARNING - Cannot specify binary without giving platform value")
app_list[appname][version]['binary'] = '' #Binary will not be updated app_list[appname][version]['binary'] = '' #Binary will not be updated
parameter = dict(installroot=installroot, parameter = dict(installroot=installroot,
......
This diff is collapsed.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
import os import os
import sys import sys
import re import re
...@@ -36,10 +37,10 @@ def createAccount(config, base_cmd): ...@@ -36,10 +37,10 @@ def createAccount(config, base_cmd):
def runBoinc(config): def runBoinc(config):
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "Argument Error: uses %s project_url" % sys.argv[0] print("Argument Error: uses %s project_url" % sys.argv[0])
exit(1) exit(1)
if type(config) == type(""): if type(config) == type(""):
print "Error: bonjourgrid.xml parsing error, file not exist or corrupted" print("Error: bonjourgrid.xml parsing error, file not exist or corrupted")
exit(1) exit(1)
#XXX Using define values here for Boinc Master URL #XXX Using define values here for Boinc Master URL
config['project_url'] = sys.argv[1] config['project_url'] = sys.argv[1]
...@@ -53,7 +54,7 @@ def runBoinc(config): ...@@ -53,7 +54,7 @@ def runBoinc(config):
client_config = os.path.join(config['boinc_install_dir'], 'client_state.xml') client_config = os.path.join(config['boinc_install_dir'], 'client_state.xml')
while not os.path.exists(client_config): while not os.path.exists(client_config):
time.sleep(5) time.sleep(5)
print "Search for file '%r'..." % client_config print("Search for file '%r'..." % client_config)
time.sleep(10) time.sleep(10)
try: try:
#Scan client state xml to find client ipv4 adress #Scan client state xml to find client ipv4 adress
...@@ -64,21 +65,21 @@ def runBoinc(config): ...@@ -64,21 +65,21 @@ def runBoinc(config):
'--passwd', config['boinc_passwd']] '--passwd', config['boinc_passwd']]
#Create Account for current instance on BOINC master #Create Account for current instance on BOINC master
print "Create account for current client..." print("Create account for current client...")
key = createAccount(config, base_cmd) key = createAccount(config, base_cmd)
config['key'] = key config['key'] = key
print "Done. The account key is %s" % key print("Done. The account key is %s" % key)
#Attach project to Boinc Master #Attach project to Boinc Master
print "Attach client to Boinc Master at %s " % config['project_url'] print("Attach client to Boinc Master at %s " % config['project_url'])
try: try:
joinProject(config, base_cmd) joinProject(config, base_cmd)
except Exception, e: except Exception as e:
print e print(e)
print "Done! Waiting for Boinc Client now..." print("Done! Waiting for Boinc Client now...")
except Exception, e: except Exception as e:
#An error occure!!! #An error occure!!!
os.kill(boinc.pid, signal.SIGTERM) os.kill(boinc.pid, signal.SIGTERM)
print e print(e)
#wait for Boinc client execution #wait for Boinc client execution
boinc.wait() boinc.wait()
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
import os import os
import sys import sys
import re import re
...@@ -33,7 +34,7 @@ def updateCondorWrapper(folder, hostname, ipv6): ...@@ -33,7 +34,7 @@ def updateCondorWrapper(folder, hostname, ipv6):
def runCondor(config): def runCondor(config):
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "Argument Error: uses %s hostname" % sys.argv[0] print("Argument Error: uses %s hostname" % sys.argv[0])
exit(1) exit(1)
hostname = sys.argv[1] hostname = sys.argv[1]
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################## ##############################################################################
from __future__ import print_function
import os import os
import subprocess import subprocess
import time import time
...@@ -40,7 +41,7 @@ def runProcess(args, file): ...@@ -40,7 +41,7 @@ def runProcess(args, file):
return process.pid return process.pid
def launchScript(args): def launchScript(args):
print "Sleep for a few second..." print("Sleep for a few second...")
time.sleep(10) time.sleep(10)
pid_list = [] pid_list = []
bg_pid = os.path.join(args['bg_base'], 'pid') bg_pid = os.path.join(args['bg_base'], 'pid')
...@@ -63,6 +64,6 @@ def launchScript(args): ...@@ -63,6 +64,6 @@ def launchScript(args):
pid_list.append(runProcess(args, file)) pid_list.append(runProcess(args, file))
for pid in pid_list: for pid in pid_list:
print "Parent waiting for process child: %s " % pid print("Parent waiting for process child: %s " % pid)
result = os.waitpid(pid, 0) result = os.waitpid(pid, 0)
print "Done...", result print("Done...", result)
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
############################################################################## ##############################################################################
import os import os
import hashlib import hashlib
import six
from six.moves import configparser from six.moves import configparser
import tempfile import tempfile
...@@ -108,6 +109,8 @@ class Request(Recipe): ...@@ -108,6 +109,8 @@ class Request(Recipe):
request_needed = True request_needed = True
name = self.options['name'] name = self.options['name']
if six.PY3 and type(name) is str:
name = name.encode("utf-8")
hash_ = hashlib.sha512(name).hexdigest() hash_ = hashlib.sha512(name).hexdigest()
key = os.path.join(self.ca_private, hash_ + self.ca_key_ext) key = os.path.join(self.ca_private, hash_ + self.ca_key_ext)
certificate = os.path.join(self.ca_certs, hash_ + self.ca_crt_ext) certificate = os.path.join(self.ca_certs, hash_ + self.ca_crt_ext)
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################## ##############################################################################
from __future__ import print_function
import os import os
import subprocess import subprocess
import time import time
...@@ -32,9 +33,9 @@ import time ...@@ -32,9 +33,9 @@ import time
def submitJob(submit, submit_file, appdir, appname, sig_install): def submitJob(submit, submit_file, appdir, appname, sig_install):
"""Run condor_submit (if needed) for job deployment""" """Run condor_submit (if needed) for job deployment"""
time.sleep(10) time.sleep(10)
print "Check if needed to submit %s job's" % appname print("Check if needed to submit %s job's" % appname)
if not os.path.exists(sig_install): if not os.path.exists(sig_install):
print "Nothing for install or update...Exited" print("Nothing for install or update...Exited")
return return
# '-a', "log = out.log", '-a', "error = error.log", # '-a', "log = out.log", '-a', "error = error.log",
launch_args = submit, '-verbose', submit_file launch_args = submit, '-verbose', submit_file
...@@ -42,7 +43,7 @@ def submitJob(submit, submit_file, appdir, appname, sig_install): ...@@ -42,7 +43,7 @@ def submitJob(submit, submit_file, appdir, appname, sig_install):
stderr=subprocess.STDOUT, cwd=appdir) stderr=subprocess.STDOUT, cwd=appdir)
result = process.communicate()[0] result = process.communicate()[0]
if process.returncode is None or process.returncode != 0: if process.returncode is None or process.returncode != 0:
print "Failed to execute condor_submit.\nThe error was: %s" % result print("Failed to execute condor_submit.\nThe error was: %s" % result)
else: else:
os.unlink(sig_install) os.unlink(sig_install)
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
# #
############################################################################## ##############################################################################
import ConfigParser from six.moves import configparser
import uuid import uuid
import os import os
import subprocess import subprocess
...@@ -47,7 +47,7 @@ class Recipe(GenericSlapRecipe): ...@@ -47,7 +47,7 @@ class Recipe(GenericSlapRecipe):
container_uuid = None container_uuid = None
if os.path.exists(config_filename): if os.path.exists(config_filename):
config = ConfigParser.ConfigParser() config = configparser.ConfigParser()
config.read(config_filename) config.read(config_filename)
if config.has_option('requested', 'name'): if config.has_option('requested', 'name'):
container_uuid = uuid.UUID(hex=config.get('requested', 'name')) container_uuid = uuid.UUID(hex=config.get('requested', 'name'))
...@@ -68,7 +68,7 @@ class Recipe(GenericSlapRecipe): ...@@ -68,7 +68,7 @@ class Recipe(GenericSlapRecipe):
self.logger.info("Putting slapcontainer configuration file...") self.logger.info("Putting slapcontainer configuration file...")
config = ConfigParser.ConfigParser() config = configparser.ConfigParser()
config.add_section('requested') config.add_section('requested')
config.set('requested', 'status', config.set('requested', 'status',
self.computer_partition.getState()) self.computer_partition.getState())
......
...@@ -30,13 +30,14 @@ import json ...@@ -30,13 +30,14 @@ import json
import os import os
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
import six
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
def install(self): def install(self):
self.path_list = [] self.path_list = []
options = self.options.copy() options = self.options.copy()
del options['recipe'] del options['recipe']
CONFIG = {k.replace('-', '_'): v for k, v in options.iteritems()} CONFIG = {k.replace('-', '_'): v for k, v in six.iteritems(options)}
CONFIG['PATH'] = os.environ['PATH'] CONFIG['PATH'] = os.environ['PATH']
if self.options['instance-dict']: if self.options['instance-dict']:
...@@ -44,7 +45,7 @@ class Recipe(GenericBaseRecipe): ...@@ -44,7 +45,7 @@ class Recipe(GenericBaseRecipe):
config_instance_dict.add_section('instance_dict') config_instance_dict.add_section('instance_dict')
instance_dict = json.loads(self.options['instance-dict']) instance_dict = json.loads(self.options['instance-dict'])
for k ,v in instance_dict.iteritems(): for k ,v in six.iteritems(instance_dict):
config_instance_dict.set('instance_dict', k, v) config_instance_dict.set('instance_dict', k, v)
value = io.StringIO() value = io.StringIO()
config_instance_dict.write(value) config_instance_dict.write(value)
......
...@@ -29,6 +29,7 @@ from six.moves import configparser ...@@ -29,6 +29,7 @@ from six.moves import configparser
import os import os
import netaddr import netaddr
import socket import socket
from six.moves import range
class Recipe(object): class Recipe(object):
""" """
...@@ -89,7 +90,7 @@ class Recipe(object): ...@@ -89,7 +90,7 @@ class Recipe(object):
This algorithm thus returns always the same value with the same parameters in This algorithm thus returns always the same value with the same parameters in
a standard environment. a standard environment.
""" """
for port in xrange(self.minimum, self.maximum): for port in range(self.minimum, self.maximum):
sock = socket.socket(self.inet_family, socket.SOCK_STREAM) sock = socket.socket(self.inet_family, socket.SOCK_STREAM)
try: try:
sock.bind((self.ip, port)) sock.bind((self.ip, port))
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
from functools import cmp_to_key from functools import cmp_to_key
import zc.buildout import zc.buildout
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
from six.moves import range
@cmp_to_key @cmp_to_key
def compareMimetypeEntryPair(a, b): def compareMimetypeEntryPair(a, b):
......
from __future__ import print_function
import os import os
import subprocess import subprocess
import time import time
...@@ -19,31 +20,31 @@ def updateMysql(mysql_upgrade_binary, mysql_binary, mysql_script_file): ...@@ -19,31 +20,31 @@ def updateMysql(mysql_upgrade_binary, mysql_binary, mysql_script_file):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = mysql_upgrade.communicate()[0] result = mysql_upgrade.communicate()[0]
if mysql_upgrade.returncode: if mysql_upgrade.returncode:
print "Command %r failed with result:\n%s" % (mysql_upgrade_binary, result) print("Command %r failed with result:\n%s" % (mysql_upgrade_binary, result))
break break
print "MySQL database upgraded with result:\n%s" % result print("MySQL database upgraded with result:\n%s" % result)
mysql = subprocess.Popen(mysql_list, stdin=subprocess.PIPE, mysql = subprocess.Popen(mysql_list, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = mysql.communicate(mysql_script)[0] result = mysql.communicate(mysql_script)[0]
if mysql.returncode: if mysql.returncode:
print 'Command %r failed with:\n%s' % (mysql_list, result) print('Command %r failed with:\n%s' % (mysql_list, result))
break break
# import timezone database # import timezone database
mysql_tzinfo_to_sql = subprocess.Popen(mysql_tzinfo_to_sql_list, stdin=subprocess.PIPE, mysql_tzinfo_to_sql = subprocess.Popen(mysql_tzinfo_to_sql_list, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
timezone_sql = mysql_tzinfo_to_sql.communicate()[0] timezone_sql = mysql_tzinfo_to_sql.communicate()[0]
if mysql_tzinfo_to_sql.returncode != 0: if mysql_tzinfo_to_sql.returncode != 0:
print 'Command %r failed with:\n%s' % (mysql_tzinfo_to_sql_list, result) print('Command %r failed with:\n%s' % (mysql_tzinfo_to_sql_list, result))
break break
mysql = subprocess.Popen(mysql_list + ('mysql',), stdin=subprocess.PIPE, mysql = subprocess.Popen(mysql_list + ('mysql',), stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = mysql.communicate(timezone_sql)[0] result = mysql.communicate(timezone_sql)[0]
if mysql.returncode: if mysql.returncode:
print 'Command %r failed with:\n%s' % (mysql_list, result) print('Command %r failed with:\n%s' % (mysql_list, result))
break break
print 'SlapOS initialisation script succesfully applied on database.' print('SlapOS initialisation script succesfully applied on database.')
return return
print 'Sleeping for %ss and retrying' % sleep print('Sleeping for %ss and retrying' % sleep)
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
time.sleep(sleep) time.sleep(sleep)
...@@ -30,13 +30,14 @@ import os ...@@ -30,13 +30,14 @@ import os
from subprocess import check_call from subprocess import check_call
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
import six
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
def install(self): def install(self):
repolist = json.loads(self.options['repos']) repolist = json.loads(self.options['repos'])
for repo, desc in repolist.iteritems(): for repo, desc in six.iteritems(repolist):
absolute_path = os.path.join(self.options['base-directory'], '%s.git' % repo) absolute_path = os.path.join(self.options['base-directory'], '%s.git' % repo)
if not os.path.exists(absolute_path): if not os.path.exists(absolute_path):
check_call([self.options['git-binary'], 'init', check_call([self.options['git-binary'], 'init',
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################## ##############################################################################
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
import six
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
""" """
...@@ -95,7 +96,7 @@ class Recipe(GenericBaseRecipe): ...@@ -95,7 +96,7 @@ class Recipe(GenericBaseRecipe):
# FIXME: maxconn must be provided per-backend, not globally # FIXME: maxconn must be provided per-backend, not globally
maxconn = self.options['maxconn'] maxconn = self.options['maxconn']
i = 0 i = 0
for name, (port, backend_list) in backend_dict.iteritems(): for name, (port, backend_list) in six.iteritems(backend_dict):
server_snippet += self.substituteTemplate( server_snippet += self.substituteTemplate(
listen_snippet_filename, { listen_snippet_filename, {
'name': name, 'name': name,
......
from __future__ import print_function
import socket import socket
from six.moves import input
try: try:
import readline import readline
except ImportError: except ImportError:
...@@ -7,9 +9,9 @@ except ImportError: ...@@ -7,9 +9,9 @@ except ImportError:
def haproxyctl(socket_path): def haproxyctl(socket_path):
while True: while True:
try: try:
l = raw_input('> ') l = input('> ')
except EOFError: except EOFError:
print print()
break break
if l == 'quit': if l == 'quit':
break break
...@@ -20,5 +22,5 @@ def haproxyctl(socket_path): ...@@ -20,5 +22,5 @@ def haproxyctl(socket_path):
r = s.recv(1024) r = s.recv(1024)
if not r: if not r:
break break
print r print(r)
s.close() s.close()
...@@ -130,7 +130,7 @@ class BaseRecipe(BaseSlapRecipe): ...@@ -130,7 +130,7 @@ class BaseRecipe(BaseSlapRecipe):
'template/apache.in'), apache_config)) 'template/apache.in'), apache_config))
self.path_list.append(config_file) self.path_list.append(config_file)
php_ini = pkg_resources.resource_filename(__name__, 'template/php.ini.in') php_ini = pkg_resources.resource_filename(__name__, 'template/php.ini.in')
if self.options.has_key('php_ini'): if 'php_ini' in self.options:
php_ini = os.path.join(self.options['php_ini'], 'php.ini.in') php_ini = os.path.join(self.options['php_ini'], 'php.ini.in')
self.path_list.append(self.createConfigurationFile('php.ini', self.path_list.append(self.createConfigurationFile('php.ini',
self.substituteTemplate(php_ini, dict(tmp_directory=self.tmp_directory)))) self.substituteTemplate(php_ini, dict(tmp_directory=self.tmp_directory))))
...@@ -161,8 +161,7 @@ class BaseRecipe(BaseSlapRecipe): ...@@ -161,8 +161,7 @@ class BaseRecipe(BaseSlapRecipe):
"""Start process which can launch python scripts, move or remove files or """Start process which can launch python scripts, move or remove files or
directories when installing software. directories when installing software.
""" """
if not self.options.has_key('delete') and not self.options.has_key('rename') and not\ if 'delete' not in self.options and 'rename' not in self.options and 'chmod' not in self.options and 'script' not in self.options:
self.options.has_key('chmod') and not self.options.has_key('script'):
return "" return ""
delete = [] delete = []
chmod = [] chmod = []
...@@ -172,7 +171,7 @@ class BaseRecipe(BaseSlapRecipe): ...@@ -172,7 +171,7 @@ class BaseRecipe(BaseSlapRecipe):
argument = [self.options['lampconfigure_directory'].strip(), argument = [self.options['lampconfigure_directory'].strip(),
"-H", mysql_conf['mysql_host'], "-P", mysql_conf['mysql_port'], "-H", mysql_conf['mysql_host'], "-P", mysql_conf['mysql_port'],
"-p", mysql_conf['mysql_password'], "-u", mysql_conf['mysql_user']] "-p", mysql_conf['mysql_password'], "-u", mysql_conf['mysql_user']]
if not self.options.has_key('file_token'): if 'file_token' not in self.options:
argument = argument + ["-d", mysql_conf['mysql_database'], argument = argument + ["-d", mysql_conf['mysql_database'],
"--table", self.options['table_name'].strip(), "--cond", "--table", self.options['table_name'].strip(), "--cond",
self.options['constraint'].strip()] self.options['constraint'].strip()]
...@@ -180,11 +179,11 @@ class BaseRecipe(BaseSlapRecipe): ...@@ -180,11 +179,11 @@ class BaseRecipe(BaseSlapRecipe):
argument = argument + ["-f", self.options['file_token'].strip()] argument = argument + ["-f", self.options['file_token'].strip()]
argument += ["-t", document_root] argument += ["-t", document_root]
if self.options.has_key('delete'): if 'delete' in self.options:
delete = ["delete"] delete = ["delete"]
for fname in self.options['delete'].split(','): for fname in self.options['delete'].split(','):
delete.append(fname.strip()) delete.append(fname.strip())
if self.options.has_key('rename'): if 'rename' in self.options:
for fname in self.options['rename'].split(','): for fname in self.options['rename'].split(','):
if fname.find("=>") < 0: if fname.find("=>") < 0:
old_name = fname old_name = fname
...@@ -194,15 +193,15 @@ class BaseRecipe(BaseSlapRecipe): ...@@ -194,15 +193,15 @@ class BaseRecipe(BaseSlapRecipe):
else: else:
fname = fname.split("=>") fname = fname.split("=>")
cmd = ["rename"] cmd = ["rename"]
if self.options.has_key('rename_chmod'): if 'rename_chmod' in self.options:
cmd += ["--chmod", self.options['rename_chmod'].strip()] cmd += ["--chmod", self.options['rename_chmod'].strip()]
rename.append(cmd + [fname[0].strip(), fname[1].strip()]) rename.append(cmd + [fname[0].strip(), fname[1].strip()])
rename_list += fname[0] + " to " + fname[1] + " " rename_list += fname[0] + " to " + fname[1] + " "
if self.options.has_key('chmod'): if 'chmod' in self.options:
chmod = ["chmod", self.options['mode'].strip()] chmod = ["chmod", self.options['mode'].strip()]
for fname in self.options['chmod'].split(','): for fname in self.options['chmod'].split(','):
chmod.append(fname.strip()) chmod.append(fname.strip())
if self.options.has_key('script') and \ if 'script' in self.options and \
self.options['script'].strip().endswith(".py"): self.options['script'].strip().endswith(".py"):
data = ["run", self.options['script'].strip(), "-v", mysql_conf['mysql_database'], url, document_root] data = ["run", self.options['script'].strip(), "-v", mysql_conf['mysql_database'], url, document_root]
self.path_list.extend(zc.buildout.easy_install.scripts( self.path_list.extend(zc.buildout.easy_install.scripts(
...@@ -237,7 +236,7 @@ class Simple(BaseRecipe): ...@@ -237,7 +236,7 @@ class Simple(BaseRecipe):
if not renamed == "": if not renamed == "":
connectionDict['rename'] = renamed connectionDict['rename'] = renamed
self.setConnectionDict(connectionDict) self.setConnectionDict(connectionDict)
if self.options.has_key('template') and self.options.has_key('configuration'): if 'template' in self.options and 'configuration' in self.options:
self.createConfiguration(self.options['template'], document_root, self.createConfiguration(self.options['template'], document_root,
self.options['configuration'], mysql_conf) self.options['configuration'], mysql_conf)
return self.path_list return self.path_list
......
from __future__ import print_function
import os import os
import sys import sys
import time import time
...@@ -10,7 +11,7 @@ def runApache(args): ...@@ -10,7 +11,7 @@ def runApache(args):
ready = True ready = True
for f in conf.get('required_path_list', []): for f in conf.get('required_path_list', []):
if not os.path.exists(f): if not os.path.exists(f):
print 'File %r does not exists, sleeping for %s' % (f, sleep) print('File %r does not exists, sleeping for %s' % (f, sleep))
ready = False ready = False
if ready: if ready:
break break
......
from __future__ import print_function
import os import os
import subprocess import subprocess
import time import time
...@@ -20,15 +21,15 @@ def runMysql(args): ...@@ -20,15 +21,15 @@ def runMysql(args):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = popen.communicate()[0] result = popen.communicate()[0]
if popen.returncode is None or popen.returncode != 0: if popen.returncode is None or popen.returncode != 0:
print "Failed to initialise server.\nThe error was: %s" % result print("Failed to initialise server.\nThe error was: %s" % result)
print "Waiting for %ss and retrying" % sleep print("Waiting for %ss and retrying" % sleep)
time.sleep(sleep) time.sleep(sleep)
else: else:
print "Mysql properly initialised" print("Mysql properly initialised")
break break
else: else:
print "MySQL already initialised" print("MySQL already initialised")
print "Starting %r" % mysqld_wrapper_list[0] print("Starting %r" % mysqld_wrapper_list[0])
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
os.execl(mysqld_wrapper_list[0], *mysqld_wrapper_list) os.execl(mysqld_wrapper_list[0], *mysqld_wrapper_list)
...@@ -46,13 +47,13 @@ def updateMysql(args): ...@@ -46,13 +47,13 @@ def updateMysql(args):
if mysql_upgrade.returncode is None: if mysql_upgrade.returncode is None:
mysql_upgrade.kill() mysql_upgrade.kill()
if mysql_upgrade.returncode != 0 and not 'is already upgraded' in result: if mysql_upgrade.returncode != 0 and not 'is already upgraded' in result:
print "Command %r failed with result:\n%s" % (mysql_upgrade_list, result) print("Command %r failed with result:\n%s" % (mysql_upgrade_list, result))
print 'Sleeping for %ss and retrying' % sleep print('Sleeping for %ss and retrying' % sleep)
else: else:
if mysql_upgrade.returncode == 0: if mysql_upgrade.returncode == 0:
print "MySQL database upgraded with result:\n%s" % result print("MySQL database upgraded with result:\n%s" % result)
else: else:
print "No need to upgrade MySQL database" print("No need to upgrade MySQL database")
mysql_script = conf.get('mysql_script') mysql_script = conf.get('mysql_script')
if mysql_script: if mysql_script:
mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']] mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']]
...@@ -62,11 +63,11 @@ def updateMysql(args): ...@@ -62,11 +63,11 @@ def updateMysql(args):
if mysql.returncode is None: if mysql.returncode is None:
mysql.kill() mysql.kill()
if mysql.returncode != 0: if mysql.returncode != 0:
print 'Command %r failed with:\n%s' % (mysql_list, result) print('Command %r failed with:\n%s' % (mysql_list, result))
print 'Sleeping for %ss and retrying' % sleep print('Sleeping for %ss and retrying' % sleep)
else: else:
is_succeed = True is_succeed = True
print 'SlapOS initialisation script succesfully applied on database.' print('SlapOS initialisation script succesfully applied on database.')
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
time.sleep(sleep) time.sleep(sleep)
from __future__ import print_function
import sys import sys
import subprocess import subprocess
...@@ -8,20 +9,20 @@ def executeRunner(args): ...@@ -8,20 +9,20 @@ def executeRunner(args):
""" """
arguments, delete, rename, chmod, data = args arguments, delete, rename, chmod, data = args
if delete != []: if delete != []:
print "Calling lampconfigure with 'delete' arguments" print("Calling lampconfigure with 'delete' arguments")
result = subprocess.Popen(arguments + delete) result = subprocess.Popen(arguments + delete)
result.wait() result.wait()
if rename != []: if rename != []:
for parameters in rename: for parameters in rename:
print "Calling lampconfigure with 'rename' arguments" print("Calling lampconfigure with 'rename' arguments")
result = subprocess.Popen(arguments + parameters) result = subprocess.Popen(arguments + parameters)
result.wait() result.wait()
if chmod != []: if chmod != []:
print "Calling lampconfigure with 'chmod' arguments" print("Calling lampconfigure with 'chmod' arguments")
result = subprocess.Popen(arguments + chmod) result = subprocess.Popen(arguments + chmod)
result.wait() result.wait()
if data != []: if data != []:
print "Calling lampconfigure with 'run' arguments" print("Calling lampconfigure with 'run' arguments")
result = subprocess.Popen(arguments + data) result = subprocess.Popen(arguments + data)
result.wait() result.wait()
return return
...@@ -8,6 +8,7 @@ from collections import defaultdict ...@@ -8,6 +8,7 @@ from collections import defaultdict
from inotify_simple import INotify, flags from inotify_simple import INotify, flags
import six import six
from six.moves import range
def _wait_files_creation(file_list): def _wait_files_creation(file_list):
# Establish a list of directory and subfiles. # Establish a list of directory and subfiles.
...@@ -66,7 +67,7 @@ def generic_exec(args, extra_environ=None, wait_list=None, ...@@ -66,7 +67,7 @@ def generic_exec(args, extra_environ=None, wait_list=None,
else: else:
# With chained shebangs, several paths may be inserted at the beginning. # With chained shebangs, several paths may be inserted at the beginning.
n = len(args) n = len(args)
for i in xrange(1+len(running)-n): for i in range(1+len(running)-n):
if args == running[i:n+i]: if args == running[i:n+i]:
sys.exit("Already running with pid %s." % pid) sys.exit("Already running with pid %s." % pid)
with open(pidfile, 'w') as f: with open(pidfile, 'w') as f:
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################## ##############################################################################
from __future__ import print_function
import os import os
import pprint import pprint
import re import re
...@@ -215,7 +216,7 @@ Include conf/extra/httpd-autoindex.conf ...@@ -215,7 +216,7 @@ Include conf/extra/httpd-autoindex.conf
if not stat.S_ISFIFO(os.stat(fifo).st_mode): if not stat.S_ISFIFO(os.stat(fifo).st_mode):
raise Exception("The file "+fifo+" exists but is not a FIFO.") raise Exception("The file "+fifo+" exists but is not a FIFO.")
else: else:
os.mkfifo(fifo, 0600) os.mkfifo(fifo, 0o600)
site_perl_bin = os.path.join(self.options['site_perl'], 'bin') site_perl_bin = os.path.join(self.options['site_perl'], 'bin')
mioga_conf_path = os.path.join(mioga_base, 'conf', 'Mioga.conf') mioga_conf_path = os.path.join(mioga_base, 'conf', 'Mioga.conf')
...@@ -253,7 +254,7 @@ Include conf/extra/httpd-autoindex.conf ...@@ -253,7 +254,7 @@ Include conf/extra/httpd-autoindex.conf
pass pass
os.chdir(former_directory) os.chdir(former_directory)
print "Mioga instantiate.py::install finished!" print("Mioga instantiate.py::install finished!")
return path_list return path_list
......
from __future__ import print_function
import os import os
import subprocess import subprocess
import time import time
...@@ -20,15 +21,15 @@ def runMysql(conf): ...@@ -20,15 +21,15 @@ def runMysql(conf):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=conf['cwd']) stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=conf['cwd'])
result = popen.communicate()[0] result = popen.communicate()[0]
if popen.returncode is None or popen.returncode != 0: if popen.returncode is None or popen.returncode != 0:
print "Failed to initialise server.\nThe error was: %s" % result print("Failed to initialise server.\nThe error was: %s" % result)
print "Waiting for %ss and retrying" % sleep print("Waiting for %ss and retrying" % sleep)
time.sleep(sleep) time.sleep(sleep)
else: else:
print "Mysql properly initialised" print("Mysql properly initialised")
break break
else: else:
print "MySQL already initialised" print("MySQL already initialised")
print "Starting %r" % mysqld_wrapper_list[0] print("Starting %r" % mysqld_wrapper_list[0])
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
os.execl(mysqld_wrapper_list[0], *mysqld_wrapper_list) os.execl(mysqld_wrapper_list[0], *mysqld_wrapper_list)
...@@ -45,13 +46,13 @@ def updateMysql(conf): ...@@ -45,13 +46,13 @@ def updateMysql(conf):
if mysql_upgrade.returncode is None: if mysql_upgrade.returncode is None:
mysql_upgrade.kill() mysql_upgrade.kill()
if mysql_upgrade.returncode != 0 and not 'is already upgraded' in result: if mysql_upgrade.returncode != 0 and not 'is already upgraded' in result:
print "Command %r failed with result:\n%s" % (mysql_upgrade_list, result) print("Command %r failed with result:\n%s" % (mysql_upgrade_list, result))
print 'Sleeping for %ss and retrying' % sleep print('Sleeping for %ss and retrying' % sleep)
else: else:
if mysql_upgrade.returncode == 0: if mysql_upgrade.returncode == 0:
print "MySQL database upgraded with result:\n%s" % result print("MySQL database upgraded with result:\n%s" % result)
else: else:
print "No need to upgrade MySQL database" print("No need to upgrade MySQL database")
mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']] mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']]
mysql = subprocess.Popen(mysql_list, stdin=subprocess.PIPE, mysql = subprocess.Popen(mysql_list, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
...@@ -59,11 +60,11 @@ def updateMysql(conf): ...@@ -59,11 +60,11 @@ def updateMysql(conf):
if mysql.returncode is None: if mysql.returncode is None:
mysql.kill() mysql.kill()
if mysql.returncode != 0: if mysql.returncode != 0:
print 'Command %r failed with:\n%s' % (mysql_list, result) print('Command %r failed with:\n%s' % (mysql_list, result))
print 'Sleeping for %ss and retrying' % sleep print('Sleeping for %ss and retrying' % sleep)
else: else:
is_succeed = True is_succeed = True
print 'SlapOS initialisation script succesfully applied on database.' print('SlapOS initialisation script succesfully applied on database.')
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
time.sleep(sleep) time.sleep(sleep)
...@@ -28,6 +28,7 @@ import os ...@@ -28,6 +28,7 @@ import os
import shlex import shlex
from zc.buildout import UserError from zc.buildout import UserError
from .librecipe import GenericBaseRecipe from .librecipe import GenericBaseRecipe
import six
class Cluster(object): class Cluster(object):
...@@ -41,7 +42,7 @@ class Cluster(object): ...@@ -41,7 +42,7 @@ class Cluster(object):
for node in sorted(options['nodes'].split()): for node in sorted(options['nodes'].split()):
node = buildout[node] node = buildout[node]
node_list.append(node) node_list.append(node)
for k, v in result_dict.iteritems(): for k, v in six.iteritems(result_dict):
x = node[k] x = node[k]
if x: if x:
v.append(x) v.append(x)
......
...@@ -37,8 +37,8 @@ class NoSQLTestBed(BaseSlapRecipe): ...@@ -37,8 +37,8 @@ class NoSQLTestBed(BaseSlapRecipe):
def _install(self): def _install(self):
self.parameter_dict = self.computer_partition.getInstanceParameterDict() self.parameter_dict = self.computer_partition.getInstanceParameterDict()
try: try:
entry_point = pkg_resources.iter_entry_points(group='slapos.recipe.nosqltestbed.plugin', entry_point = next(pkg_resources.iter_entry_points(group='slapos.recipe.nosqltestbed.plugin',
name=self.parameter_dict.get('plugin', 'kumo')).next() name=self.parameter_dict.get('plugin', 'kumo')))
plugin_class = entry_point.load() plugin_class = entry_point.load()
testbed = plugin_class() testbed = plugin_class()
......
...@@ -35,9 +35,11 @@ from __future__ import absolute_import ...@@ -35,9 +35,11 @@ from __future__ import absolute_import
import errno import errno
import os import os
import random import random
import six
import string import string
from .librecipe import GenericBaseRecipe from .librecipe import GenericBaseRecipe
from .publish_early import volatileOptions from .publish_early import volatileOptions
from six.moves import range
class Integer(object): class Integer(object):
""" """
...@@ -174,7 +176,10 @@ class Password(object): ...@@ -174,7 +176,10 @@ class Password(object):
fd = os.open(self.storage_path, fd = os.open(self.storage_path,
os.O_CREAT | os.O_EXCL | os.O_WRONLY | os.O_TRUNC, 0o600) os.O_CREAT | os.O_EXCL | os.O_WRONLY | os.O_TRUNC, 0o600)
try: try:
os.write(fd, self.passwd) passwd = self.passwd
if six.PY3 and type(passwd) is str:
passwd = passwd.encode('utf-8')
os.write(fd, passwd)
finally: finally:
os.close(fd) os.close(fd)
if not self.create_once: if not self.create_once:
......
...@@ -34,6 +34,7 @@ import string, random ...@@ -34,6 +34,7 @@ import string, random
import json import json
import traceback import traceback
from slapos import slap from slapos import slap
from six.moves import range
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
...@@ -154,7 +155,7 @@ class Recipe(GenericBaseRecipe): ...@@ -154,7 +155,7 @@ class Recipe(GenericBaseRecipe):
hash_path = os.path.join(self.options['conf-dir'], '%s-hash' % length) hash_path = os.path.join(self.options['conf-dir'], '%s-hash' % length)
if not os.path.exists(hash_path): if not os.path.exists(hash_path):
pool = string.letters + string.digits pool = string.letters + string.digits
hash_string = ''.join(random.choice(pool) for i in xrange(length)) hash_string = ''.join(random.choice(pool) for i in range(length))
self.writeFile(hash_path, hash_string) self.writeFile(hash_path, hash_string)
else: else:
hash_string = self.readFile(hash_path) hash_string = self.readFile(hash_path)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import httplib import six.moves.http_client
import logging import logging
import json import json
import os import os
...@@ -8,6 +8,7 @@ import slapos ...@@ -8,6 +8,7 @@ import slapos
import traceback import traceback
import logging import logging
from re6st import registry from re6st import registry
import six
log = logging.getLogger('SLAPOS-RE6STNET') log = logging.getLogger('SLAPOS-RE6STNET')
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
...@@ -93,7 +94,7 @@ def requestRemoveToken(client, token_base_path): ...@@ -93,7 +94,7 @@ def requestRemoveToken(client, token_base_path):
reference = reference_key.split('.')[0] reference = reference_key.split('.')[0]
try: try:
result = client.deleteToken(token) result = client.deleteToken(token)
except httplib.NOT_FOUND: except six.moves.http_client.NOT_FOUND:
# Token is alread removed. # Token is alread removed.
result = True result = True
except Exception: except Exception:
...@@ -128,7 +129,7 @@ def checkService(client, token_base_path, token_json, computer_partition): ...@@ -128,7 +129,7 @@ def checkService(client, token_base_path, token_json, computer_partition):
return return
# Check token status # Check token status
for slave_reference, token in token_dict.iteritems(): for slave_reference, token in six.iteritems(token_dict):
log.info("%s %s" % (slave_reference, token)) log.info("%s %s" % (slave_reference, token))
status_file = os.path.join(token_base_path, '%s.status' % slave_reference) status_file = os.path.join(token_base_path, '%s.status' % slave_reference)
if not os.path.exists(status_file): if not os.path.exists(status_file):
......
...@@ -46,7 +46,7 @@ class Recipe(object): ...@@ -46,7 +46,7 @@ class Recipe(object):
try: try:
with open(storage_path) as f: with open(storage_path) as f:
readline = f.readline() readline = f.readline()
except IOError, e: except IOError as e:
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
readline = None readline = None
......
from __future__ import with_statement from __future__ import with_statement
import six
from six.moves import range
from six.moves import zip
"Core exceptions raised by the Redis client" "Core exceptions raised by the Redis client"
...@@ -85,7 +88,7 @@ class PythonParser(object): ...@@ -85,7 +88,7 @@ class PythonParser(object):
# no length, read a full line # no length, read a full line
return self._fp.readline()[:-2] return self._fp.readline()[:-2]
except (socket.error, socket.timeout), e: except (socket.error, socket.timeout) as e:
raise ConnectionError("Error while reading from socket: %s" % \ raise ConnectionError("Error while reading from socket: %s" % \
(e.args,)) (e.args,))
...@@ -110,7 +113,7 @@ class PythonParser(object): ...@@ -110,7 +113,7 @@ class PythonParser(object):
return response return response
# int value # int value
elif byte == ':': elif byte == ':':
return long(response) return int(response)
# bulk response # bulk response
elif byte == '$': elif byte == '$':
length = int(response) length = int(response)
...@@ -123,7 +126,7 @@ class PythonParser(object): ...@@ -123,7 +126,7 @@ class PythonParser(object):
length = int(response) length = int(response)
if length == -1: if length == -1:
return None return None
return [self.read_response() for i in xrange(length)] return [self.read_response() for i in range(length)]
raise InvalidResponse("Protocol Error") raise InvalidResponse("Protocol Error")
class HiredisParser(object): class HiredisParser(object):
...@@ -151,7 +154,7 @@ class HiredisParser(object): ...@@ -151,7 +154,7 @@ class HiredisParser(object):
while response is False: while response is False:
try: try:
buffer = self._sock.recv(4096) buffer = self._sock.recv(4096)
except (socket.error, socket.timeout), e: except (socket.error, socket.timeout) as e:
raise ConnectionError("Error while reading from socket: %s" % \ raise ConnectionError("Error while reading from socket: %s" % \
(e.args,)) (e.args,))
if not buffer: if not buffer:
...@@ -197,7 +200,7 @@ class Connection(object): ...@@ -197,7 +200,7 @@ class Connection(object):
return return
try: try:
sock = self._connect() sock = self._connect()
except socket.error, e: except socket.error as e:
raise ConnectionError(self._error_message(e)) raise ConnectionError(self._error_message(e))
self._sock = sock self._sock = sock
...@@ -253,7 +256,7 @@ class Connection(object): ...@@ -253,7 +256,7 @@ class Connection(object):
self.connect() self.connect()
try: try:
self._sock.sendall(command) self._sock.sendall(command)
except socket.error, e: except socket.error as e:
self.disconnect() self.disconnect()
if len(e.args) == 1: if len(e.args) == 1:
_errno, errmsg = 'UNKNOWN', e.args[0] _errno, errmsg = 'UNKNOWN', e.args[0]
...@@ -470,7 +473,7 @@ def zset_score_pairs(response, **options): ...@@ -470,7 +473,7 @@ def zset_score_pairs(response, **options):
return response return response
score_cast_func = options.get('score_cast_func', float) score_cast_func = options.get('score_cast_func', float)
it = iter(response) it = iter(response)
return zip(it, imap(score_cast_func, it)) return list(zip(it, imap(score_cast_func, it)))
def int_or_none(response): def int_or_none(response):
if response is None: if response is None:
...@@ -513,7 +516,7 @@ class StrictRedis(object): ...@@ -513,7 +516,7 @@ class StrictRedis(object):
string_keys_to_dict( string_keys_to_dict(
# these return OK, or int if redis-server is >=1.3.4 # these return OK, or int if redis-server is >=1.3.4
'LPUSH RPUSH', 'LPUSH RPUSH',
lambda r: isinstance(r, long) and r or r == 'OK' lambda r: isinstance(r, int) and r or r == 'OK'
), ),
string_keys_to_dict('ZSCORE ZINCRBY', float_or_none), string_keys_to_dict('ZSCORE ZINCRBY', float_or_none),
string_keys_to_dict( string_keys_to_dict(
...@@ -824,7 +827,7 @@ class StrictRedis(object): ...@@ -824,7 +827,7 @@ class StrictRedis(object):
def mset(self, mapping): def mset(self, mapping):
"Sets each key in the ``mapping`` dict to its corresponding value" "Sets each key in the ``mapping`` dict to its corresponding value"
items = [] items = []
for pair in mapping.iteritems(): for pair in six.iteritems(mapping):
items.extend(pair) items.extend(pair)
return self.execute_command('MSET', *items) return self.execute_command('MSET', *items)
...@@ -834,7 +837,7 @@ class StrictRedis(object): ...@@ -834,7 +837,7 @@ class StrictRedis(object):
none of the keys are already set none of the keys are already set
""" """
items = [] items = []
for pair in mapping.iteritems(): for pair in six.iteritems(mapping):
items.extend(pair) items.extend(pair)
return self.execute_command('MSETNX', *items) return self.execute_command('MSETNX', *items)
...@@ -1218,7 +1221,7 @@ class StrictRedis(object): ...@@ -1218,7 +1221,7 @@ class StrictRedis(object):
raise RedisError("ZADD requires an equal number of " raise RedisError("ZADD requires an equal number of "
"values and scores") "values and scores")
pieces.extend(args) pieces.extend(args)
for pair in kwargs.iteritems(): for pair in six.iteritems(kwargs):
pieces.append(pair[1]) pieces.append(pair[1])
pieces.append(pair[0]) pieces.append(pair[0])
return self.execute_command('ZADD', name, *pieces) return self.execute_command('ZADD', name, *pieces)
...@@ -1383,7 +1386,7 @@ class StrictRedis(object): ...@@ -1383,7 +1386,7 @@ class StrictRedis(object):
def _zaggregate(self, command, dest, keys, aggregate=None): def _zaggregate(self, command, dest, keys, aggregate=None):
pieces = [command, dest, len(keys)] pieces = [command, dest, len(keys)]
if isinstance(keys, dict): if isinstance(keys, dict):
keys, weights = keys.keys(), keys.values() keys, weights = list(keys.keys()), list(keys.values())
else: else:
weights = None weights = None
pieces.extend(keys) pieces.extend(keys)
...@@ -1446,7 +1449,7 @@ class StrictRedis(object): ...@@ -1446,7 +1449,7 @@ class StrictRedis(object):
if not mapping: if not mapping:
raise DataError("'hmset' with 'mapping' of length 0") raise DataError("'hmset' with 'mapping' of length 0")
items = [] items = []
for pair in mapping.iteritems(): for pair in six.iteritems(mapping):
items.extend(pair) items.extend(pair)
return self.execute_command('HMSET', name, *items) return self.execute_command('HMSET', name, *items)
...@@ -1540,7 +1543,7 @@ class Redis(StrictRedis): ...@@ -1540,7 +1543,7 @@ class Redis(StrictRedis):
raise RedisError("ZADD requires an equal number of " raise RedisError("ZADD requires an equal number of "
"values and scores") "values and scores")
pieces.extend(reversed(args)) pieces.extend(reversed(args))
for pair in kwargs.iteritems(): for pair in six.iteritems(kwargs):
pieces.append(pair[1]) pieces.append(pair[1])
pieces.append(pair[0]) pieces.append(pair[0])
return self.execute_command('ZADD', name, *pieces) return self.execute_command('ZADD', name, *pieces)
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
import string, random import string, random
import os import os
from six.moves import range
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
...@@ -35,7 +36,7 @@ class Recipe(GenericBaseRecipe): ...@@ -35,7 +36,7 @@ class Recipe(GenericBaseRecipe):
base_path = options['base-path'] base_path = options['base-path']
if options.get('use-hash-url', 'True') in ['true', 'True']: if options.get('use-hash-url', 'True') in ['true', 'True']:
pool = string.letters + string.digits pool = string.letters + string.digits
hash_string = ''.join(random.choice(pool) for i in xrange(64)) hash_string = ''.join(random.choice(pool) for i in range(64))
path = os.path.join(base_path, hash_string) path = os.path.join(base_path, hash_string)
if os.path.exists(base_path): if os.path.exists(base_path):
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from SimpleHTTPServer import SimpleHTTPRequestHandler from six.moves.SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer from six.moves.BaseHTTPServer import HTTPServer
import ssl import ssl
import os import os
import logging import logging
...@@ -46,7 +46,7 @@ class ServerHandler(SimpleHTTPRequestHandler): ...@@ -46,7 +46,7 @@ class ServerHandler(SimpleHTTPRequestHandler):
name = form['path'].value name = form['path'].value
content = form['content'].value content = form['content'].value
method = 'a' method = 'a'
if form.has_key('clear') and form['clear'].value == '1': if 'clear' in form and form['clear'].value == '1':
method = 'w' method = 'w'
self.writeFile(name, content, method) self.writeFile(name, content, method)
self.respond(200, type=self.headers['Content-Type']) self.respond(200, type=self.headers['Content-Type'])
...@@ -97,7 +97,7 @@ def run(args): ...@@ -97,7 +97,7 @@ def run(args):
httpd = server((host, port), Handler) httpd = server((host, port), Handler)
scheme = 'http' scheme = 'http'
if args.has_key('cert-file') and args.has_key('key-file') and \ if 'cert-file' in args and 'key-file' in args and \
os.path.exists(args['cert-file']) and os.path.exists(args['key-file']): os.path.exists(args['cert-file']) and os.path.exists(args['key-file']):
scheme = 'https' scheme = 'https'
httpd.socket = ssl.wrap_socket (httpd.socket, httpd.socket = ssl.wrap_socket (httpd.socket,
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from __future__ import print_function
import sys import sys
import time import time
...@@ -33,8 +34,8 @@ def log(filename): ...@@ -33,8 +34,8 @@ def log(filename):
prefix = time.strftime('%Y-%m-%d.%H:%M.%s:') prefix = time.strftime('%Y-%m-%d.%H:%M.%s:')
with open(filename, 'a') as logfile: with open(filename, 'a') as logfile:
for line in sys.stdin: for line in sys.stdin:
print >> logfile, prefix, line, print(prefix, line, end=' ', file=logfile)
print >> logfile, prefix, '------------------------' print(prefix, '------------------------', file=logfile)
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
import os import os
import sys import sys
import copy import copy
from ConfigParser import ConfigParser from six.moves.configparser import ConfigParser
import json import json
import subprocess import subprocess
import slapos.slap import slapos.slap
...@@ -38,6 +38,7 @@ import errno ...@@ -38,6 +38,7 @@ import errno
import re import re
import zc.buildout import zc.buildout
import six
class SlapConfigParser(ConfigParser, object): class SlapConfigParser(ConfigParser, object):
""" """
...@@ -138,9 +139,9 @@ class Recipe: ...@@ -138,9 +139,9 @@ class Recipe:
for name, ip in self.parameter_dict['ip_list']: for name, ip in self.parameter_dict['ip_list']:
if name: if name:
return name return name
raise AttributeError, "Not network interface found" raise AttributeError("Not network interface found")
def mkdir_p(self, path, mode=0700): def mkdir_p(self, path, mode=0o700):
""" """
Creates a directory and its parents, if needed. Creates a directory and its parents, if needed.
NB: If the directory already exists, it does not change its permission. NB: If the directory already exists, it does not change its permission.
...@@ -193,7 +194,10 @@ class Recipe: ...@@ -193,7 +194,10 @@ class Recipe:
raise zc.buildout.UserError("The specified buildout config file %r does " raise zc.buildout.UserError("The specified buildout config file %r does "
"not exist." % instance_file_path) "not exist." % instance_file_path)
buildout = SlapConfigParser() try:
buildout = SlapConfigParser(strict=False)
except TypeError:
buildout = SlapConfigParser()
with open(instance_file_path) as instance_path: with open(instance_file_path) as instance_path:
buildout.readfp(instance_path) buildout.readfp(instance_path)
...@@ -231,7 +235,7 @@ class Recipe: ...@@ -231,7 +235,7 @@ class Recipe:
# Copy/paste slap_connection # Copy/paste slap_connection
buildout.add_section('slap-connection') buildout.add_section('slap-connection')
for key, value in self.buildout['slap_connection'].iteritems(): for key, value in six.iteritems(self.buildout['slap_connection']):
# XXX: Waiting for SlapBaseRecipe to use dash instead of underscores # XXX: Waiting for SlapBaseRecipe to use dash instead of underscores
buildout.set('slap-connection', key.replace('_', '-'), value) buildout.set('slap-connection', key.replace('_', '-'), value)
# XXX: Needed for lxc. Use non standard API # XXX: Needed for lxc. Use non standard API
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
############################################################################## ##############################################################################
import os, subprocess, sys import os, subprocess, sys
import six
class Recipe: class Recipe:
...@@ -41,7 +42,7 @@ class Recipe: ...@@ -41,7 +42,7 @@ class Recipe:
# XXX-Antoine: We gotta find a better way to do this. I tried to check # XXX-Antoine: We gotta find a better way to do this. I tried to check
# out how slapgrid-cp was running buildout. But it is worse than that. # out how slapgrid-cp was running buildout. But it is worse than that.
args = sys.argv[:] args = sys.argv[:]
for x in self.buildout["slap-connection"].iteritems(): for x in six.iteritems(self.buildout["slap-connection"]):
args.append("slap-connection:%s=%s" % x) args.append("slap-connection:%s=%s" % x)
for x in "directory", "eggs-directory", "develop-eggs-directory": for x in "directory", "eggs-directory", "develop-eggs-directory":
args.append("buildout:%s=%s" % (x, self.buildout["buildout"][x])) args.append("buildout:%s=%s" % (x, self.buildout["buildout"][x]))
......
...@@ -32,6 +32,7 @@ import shutil ...@@ -32,6 +32,7 @@ import shutil
import json import json
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
import six
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
...@@ -141,7 +142,7 @@ class Recipe(GenericBaseRecipe): ...@@ -141,7 +142,7 @@ class Recipe(GenericBaseRecipe):
self.logger.info("Finished initializing %s reposiroty" % svn_repo) self.logger.info("Finished initializing %s reposiroty" % svn_repo)
repolist = json.loads(self.options.get('git-project-list', '{}')) repolist = json.loads(self.options.get('git-project-list', '{}'))
for repo, desc in repolist.iteritems(): for repo, desc in six.iteritems(repolist):
absolute_path = os.path.join(self.options['git-dir'], '%s.git' % repo) absolute_path = os.path.join(self.options['git-dir'], '%s.git' % repo)
if not os.path.exists(absolute_path): if not os.path.exists(absolute_path):
self.logger.info("Initializing %s GIT repository..." % repo) self.logger.info("Initializing %s GIT repository..." % repo)
......
from __future__ import print_function
import os import os
import subprocess import subprocess
import time import time
...@@ -16,7 +17,7 @@ def get_pid(filename): ...@@ -16,7 +17,7 @@ def get_pid(filename):
pid_file = None pid_file = None
def sig_handler(s, frame): def sig_handler(s, frame):
print "Killing on signal %s:" % s, print("Killing on signal %s:" % s, end=' ')
global pid_file global pid_file
if pid_file is not None: if pid_file is not None:
pid = get_pid(pid_file) pid = get_pid(pid_file)
...@@ -33,11 +34,11 @@ def sig_handler(s, frame): ...@@ -33,11 +34,11 @@ def sig_handler(s, frame):
except Exception: except Exception:
pass pass
else: else:
print 'with SIGKILL...', print('with SIGKILL...', end=' ')
os.kill(pid, signal.SIGKILL) os.kill(pid, signal.SIGKILL)
else: else:
raise ValueError('Pid is none.') raise ValueError('Pid is none.')
print 'done.' print('done.')
sys.exit(0) sys.exit(0)
signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGINT, sig_handler)
...@@ -51,7 +52,7 @@ def svcdaemon(args): ...@@ -51,7 +52,7 @@ def svcdaemon(args):
global pid_file global pid_file
pid_file = args[0]['pid_file'] pid_file = args[0]['pid_file']
subprocess.check_call(real_binary) subprocess.check_call(real_binary)
print 'Started %r' % real_binary print('Started %r' % real_binary)
while True: while True:
time.sleep(5) time.sleep(5)
pid = get_pid(pid_file) pid = get_pid(pid_file)
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
# #
############################################################################## ##############################################################################
import ConfigParser import six.moves.configparser
import os import os
import zc.buildout import zc.buildout
...@@ -53,7 +53,7 @@ class WriteRecipe(GenericBaseRecipe): ...@@ -53,7 +53,7 @@ class WriteRecipe(GenericBaseRecipe):
def install(self): def install(self):
# Set up the parser, and write config file if needed # Set up the parser, and write config file if needed
self.parser = ConfigParser.ConfigParser() self.parser = six.moves.configparser.ConfigParser()
try: try:
self.parser.read(self.path) self.parser.read(self.path)
#clean_options(options) #clean_options(options)
...@@ -63,7 +63,7 @@ class WriteRecipe(GenericBaseRecipe): ...@@ -63,7 +63,7 @@ class WriteRecipe(GenericBaseRecipe):
with open(self.path, 'w') as file: with open(self.path, 'w') as file:
self.parser.write(file) self.parser.write(file)
# If the file or section do not exist # If the file or section do not exist
except (ConfigParser.NoSectionError, IOError) as e: except (six.moves.configparser.NoSectionError, IOError) as e:
self.full_install() self.full_install()
def full_install(self): def full_install(self):
...@@ -94,7 +94,7 @@ class ReadRecipe(GenericBaseRecipe): ...@@ -94,7 +94,7 @@ class ReadRecipe(GenericBaseRecipe):
self.path = options['file-path'].strip() self.path = options['file-path'].strip()
# Set up the parser, and write config file if needed # Set up the parser, and write config file if needed
self.parser = ConfigParser.ConfigParser() self.parser = six.moves.configparser.ConfigParser()
if os.path.exists(self.path): if os.path.exists(self.path):
self.parser.read(self.path) self.parser.read(self.path)
for section in self.parser.sections(): for section in self.parser.sections():
......
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