diff --git a/slapos/recipe/_urlparse.py b/slapos/recipe/_urlparse.py index 0a04c80cdb90dc81d60da37577271935713e2c11..2ba2869982baa088b99b3446e659e680dfb55a8c 100644 --- a/slapos/recipe/_urlparse.py +++ b/slapos/recipe/_urlparse.py @@ -24,7 +24,7 @@ # 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 diff --git a/slapos/recipe/accords/accords.py b/slapos/recipe/accords/accords.py index 88760135df217ae9ef1caa30d0d1d35187990ae6..dcc8453155de482b543ee8112c87625a53f5901a 100644 --- a/slapos/recipe/accords/accords.py +++ b/slapos/recipe/accords/accords.py @@ -26,6 +26,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## +from __future__ import print_function import os from slapos import slap import signal @@ -66,15 +67,15 @@ def runAccords(accords_conf): signal.signal(signal.SIGTERM, sigtermHandler) # 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) - print 'Parsing manifest...' + print('Parsing manifest...') subprocess.check_call(['./co-parser', manifest_name], cwd=accords_location, env=environment) - print 'Brokering manifest...' + print('Brokering manifest...') subprocess.check_call(['./co-broker', manifest_name], cwd=accords_location, env=environment) - print 'Done.' + print('Done.') # Parse answer # XXX diff --git a/slapos/recipe/apachephpconfigure/__init__.py b/slapos/recipe/apachephpconfigure/__init__.py index 263c6862f0fc20bb9365db8fe662c42092ae6828..14fe8c2416d6451e157fc40b3c1b6be97b85f5aa 100644 --- a/slapos/recipe/apachephpconfigure/__init__.py +++ b/slapos/recipe/apachephpconfigure/__init__.py @@ -54,8 +54,10 @@ class Recipe(GenericBaseRecipe): """Start process which can launch python scripts, move or remove files or directories when installing software. """ - if not self.options.has_key('delete') and not self.options.has_key('rename') and not\ - self.options.has_key('chmod') and not self.options.has_key('script') and not self.options.has_key('sql-script'): + for k in ['delete', 'rename', 'chmod', 'script', 'sql-script']: + if k in self.options: + break + else: return "" delete = [] chmod = [] @@ -64,7 +66,7 @@ class Recipe(GenericBaseRecipe): rename_list = "" argument = [self.options['lampconfigure'], "-H", mysql_conf['mysql_host'], "-P", mysql_conf['mysql_port'], "-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'], "--table", self.options['table_name'].strip(), "--cond", self.options.get('constraint', '1').strip()] @@ -72,11 +74,11 @@ class Recipe(GenericBaseRecipe): argument = argument + ["-f", self.options['file_token'].strip()] argument += ["-t", document_root] - if self.options.has_key('delete'): + if 'delete' in self.options: delete = ["delete"] for fname in self.options['delete'].split(','): delete.append(fname.strip()) - if self.options.has_key('rename'): + if 'rename' in self.options: for fname in self.options['rename'].split(','): if fname.find("=>") < 0: old_name = fname @@ -86,18 +88,18 @@ class Recipe(GenericBaseRecipe): else: fname = fname.split("=>") cmd = ["rename"] - if self.options.has_key('rename_chmod'): + if 'rename_chmod' in self.options: cmd += ["--chmod", self.options['rename_chmod'].strip()] rename.append(cmd + [fname[0].strip(), fname[1].strip()]) rename_list += fname[0] + " to " + fname[1] + " " - if self.options.has_key('chmod'): + if 'chmod' in self.options: chmod = ["chmod", self.options['mode'].strip()] for fname in self.options['chmod'].split(','): chmod.append(fname.strip()) - if self.options.has_key('script') and \ + if 'script' in self.options and \ self.options['script'].strip().endswith(".py"): 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] diff --git a/slapos/recipe/apachephpconfigure/runner.py b/slapos/recipe/apachephpconfigure/runner.py index c2bf820d72f4114ca49436461ba8c7f3fb7e99dd..7d6795debf5ff45544ce8159f51b982562a7b5e8 100644 --- a/slapos/recipe/apachephpconfigure/runner.py +++ b/slapos/recipe/apachephpconfigure/runner.py @@ -1,3 +1,4 @@ +from __future__ import print_function import subprocess def executeRunner(arguments, delete, rename, chmod, data): @@ -6,17 +7,17 @@ def executeRunner(arguments, delete, rename, chmod, data): exist into database. """ if delete: - print "Calling lampconfigure with 'delete' arguments" + print("Calling lampconfigure with 'delete' arguments") subprocess.call(arguments + delete) if rename: for parameters in rename: - print "Calling lampconfigure with 'rename' arguments" + print("Calling lampconfigure with 'rename' arguments") subprocess.call(arguments + parameters) if chmod: - print "Calling lampconfigure with 'chmod' arguments" + print("Calling lampconfigure with 'chmod' arguments") subprocess.call(arguments + chmod) if data: - print "Calling lampconfigure with 'run' arguments" - print arguments + data + print("Calling lampconfigure with 'run' arguments") + print(arguments + data) subprocess.call(arguments + data) diff --git a/slapos/recipe/boinc/__init__.py b/slapos/recipe/boinc/__init__.py index 7f79accf1e26565806382bcee3dc5419ead84561..7985661e8a5d5dbf7fc54d5c333594f2400caca4 100644 --- a/slapos/recipe/boinc/__init__.py +++ b/slapos/recipe/boinc/__init__.py @@ -24,6 +24,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## +from __future__ import print_function from slapos.recipe.librecipe import GenericBaseRecipe import os import subprocess @@ -177,7 +178,7 @@ class Recipe(GenericBaseRecipe): copyright=self.copyright, installroot=self.installroot)) ) 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 service_status = os.path.join(self.home, '.start_service') @@ -234,9 +235,9 @@ class App(GenericBaseRecipe): downloader = zc.buildout.download.Download(self.buildout['buildout'], hash_name=True, cache=cache) path, _ = downloader(param, md5sum=None) - mode = 0600 + mode = 0o600 if key == 'binary': - mode = 0700 + mode = 0o700 os.chmod(path, mode) app[key] = path @@ -278,7 +279,7 @@ class App(GenericBaseRecipe): 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['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 continue #write application to install @@ -319,7 +320,7 @@ class App(GenericBaseRecipe): dict(dash=self.options['dash'].strip())) ) path_list.append(sh_script) - os.chmod(bash , 0700) + os.chmod(bash , 0o700) #If useful, download necessary files and update options path start_boinc = os.path.join(home, '.start_boinc') @@ -339,7 +340,7 @@ class App(GenericBaseRecipe): platform = app_list[appname][version]['platform'] application = os.path.join(apps_dir, appname, version, 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 parameter = dict(installroot=installroot, diff --git a/slapos/recipe/boinc/configure.py b/slapos/recipe/boinc/configure.py index 238f1b423b8789a8a63549490a74716f4b9b4eb0..40a2858ae5a5584576118b3fcdaa0630ecdd840f 100644 --- a/slapos/recipe/boinc/configure.py +++ b/slapos/recipe/boinc/configure.py @@ -25,6 +25,7 @@ # ############################################################################## +from __future__ import print_function import os import sys import subprocess @@ -34,6 +35,7 @@ import re import filecmp from lock_file import LockFile +from six.moves import range def checkMysql(environment, connect_kw, file_status=None): sys.path += environment['PYTHONPATH'].split(':') @@ -43,20 +45,20 @@ def checkMysql(environment, connect_kw, file_status=None): try: MySQLdb.connect(**connect_kw).close() break - except Exception, ex: - print "The result is: \n" + ex.message - print "Could not connect to MySQL database... sleep for 2 secondes" + except Exception as ex: + print("The result is: \n" + ex.message) + print("Could not connect to MySQL database... sleep for 2 secondes") time.sleep(2) - print "Successfully connect to MySQL database... " + print("Successfully connect to MySQL database... ") if file_status: writeFile(file_status, "starting") def checkFile(file, stime): """Loop until 'file' is created (exist)""" while True: - print "Search for file %s..." % file + print("Search for file %s..." % file) if not os.path.exists(file): - print "File not found... sleep for %s secondes" % stime + print("File not found... sleep for %s secondes" % stime) time.sleep(stime) else: break @@ -69,22 +71,22 @@ def restart_boinc(args): checkFile(args['service_status'], 3) else: checkMysql(environment, args['mysql_dict'], args.get('file_status')) - print "Restart Boinc..." + print("Restart Boinc...") env = os.environ.copy() env.update(environment) subprocess.call((os.path.join(args['installroot'], 'bin', 'stop'),), env=env) subprocess.call((os.path.join(args['installroot'], 'bin', 'start'),), env=env) writeFile(args['start_boinc'], "started") - print "Done." + print("Done.") def check_installRequest(args): - print "Cheking if needed to install %s..." % args['appname'] + print("Cheking if needed to install %s..." % args['appname']) install_request_file = os.path.join(args['home_dir'], '.install_' + args['appname'] + args['version']) if not os.path.exists(install_request_file): - print "No install or update request for %s version %s..." % ( - args['appname'], args['version']) + print("No install or update request for %s version %s..." % ( + args['appname'], args['version'])) return False os.unlink(install_request_file) return True @@ -110,7 +112,7 @@ def startProcess(launch_args, env=None, cwd=None, stdout=subprocess.PIPE): cwd=cwd) result = process.communicate()[0] if process.returncode is None or process.returncode != 0: - print "Failed to execute executable.\nThe error was: %s" % result + print("Failed to execute executable.\nThe error was: %s" % result) return False return True @@ -118,39 +120,39 @@ def makeProject(make_sig, launch_args, request_file, extra_environ): """Run BOINC make_project script but once only""" #Wait for DateBase initialization... checkFile(make_sig, 3) - print "Cheking if needed to run BOINC make_project..." + print("Cheking if needed to run BOINC make_project...") if os.path.exists(request_file): env = os.environ.copy() env.update(extra_environ) if startProcess(launch_args, env=env): os.unlink(request_file) - print "Finished running BOINC make_projet...Ending" + print("Finished running BOINC make_projet...Ending") else: - print "No new request for make_project. Exiting..." + print("No new request for make_project. Exiting...") def services(args): """This function configure a new installed boinc project instance""" - print "Checking if needed to install or reinstall Boinc-server..." + print("Checking if needed to install or reinstall Boinc-server...") if not args['drop_install']: - print "Not need to install Boinc-server...skipped" + print("Not need to install Boinc-server...skipped") return #Sleep until file 'boinc_project'.readme exist checkFile(args['readme'], 3) topath = os.path.join(args['installroot'], 'html/ops/.htpasswd') - print "Generating .htpasswd file... File=%s" % topath + print("Generating .htpasswd file... File=%s" % topath) passwd = open(args['passwd'], 'r').read() htpwd_args = [args['htpasswd'], '-b', '-c', topath, args['username'], passwd] if not startProcess(htpwd_args): return - print "execute script xadd..." + print("execute script xadd...") env = os.environ.copy() env.update(args['environment']) if not startProcess([os.path.join(args['installroot'], 'bin/xadd')], env): return - print "Update files and directories permissions..." + print("Update files and directories permissions...") upload = os.path.join(args['installroot'], 'upload') inc = os.path.join(args['installroot'], 'html/inc') languages = os.path.join(args['installroot'], 'html/languages') @@ -171,7 +173,7 @@ def services(args): startProcess(sed_args) #Execute php create_forum.php... - print "Boinc Forum: Execute php create_forum.php..." + print("Boinc Forum: Execute php create_forum.php...") cwd = os.path.join(args['installroot'], 'html/ops') if not startProcess(["php", forum_file], env, cwd): return @@ -180,11 +182,11 @@ def services(args): def deployApp(args): """Deploy Boinc App with lock""" - print "Asking to enter in execution with lock mode..." + print("Asking to enter in execution with lock mode...") with LockFile(args['lockfile'], wait=True): - print "acquire the lock file..." + print("acquire the lock file...") deployManagement(args) - print "Exit execution with lock..." + print("Exit execution with lock...") def deployManagement(args): """Fully deploy or redeploy or update a BOINC application using existing BOINC instance""" @@ -195,8 +197,8 @@ def deployManagement(args): if os.path.exists(token): args['previous_wu'] = int(open(token, 'r').read().strip()) if args['previous_wu'] < args['wu_number']: - print args['appname'] + " Work units will be updated from %s to %s" % ( - args['previous_wu'], args['wu_number']) + print(args['appname'] + " Work units will be updated from %s to %s" % ( + args['previous_wu'], args['wu_number'])) else: args['previous_wu'] = 0 newInstall = True @@ -205,7 +207,7 @@ def deployManagement(args): env = os.environ.copy() env.update(args['environment']) - print "setup directories..." + print("setup directories...") numversion = args['version'].replace('.', '') args['inputfile'] = os.path.join(args['installroot'], 'download', args['appname'] + numversion + '_input') @@ -241,13 +243,13 @@ def deployManagement(args): findapp = re.search("<name>(%s)</name>" % args['appname'], open(project_xml, 'r').read()) if not findapp: - print "Adding '" + args['appname'] + "' to project.xml..." - print "Adding deamon for application to config.xml..." + print("Adding '" + args['appname'] + "' to project.xml...") + print("Adding deamon for application to config.xml...") sed_args = [args['bash'], args['appname'], args['installroot']] startProcess(sed_args) if signBin: - print "Sign the application binary..." + print("Sign the application binary...") sign = os.path.join(args['installroot'], 'bin/sign_executable') privateKeyFile = os.path.join(args['installroot'], 'keys/code_sign_private') output = open(binary + '.sig', 'w') @@ -255,15 +257,15 @@ def deployManagement(args): stderr=subprocess.STDOUT, env=env) result = p_sign.communicate()[0] if p_sign.returncode is None or p_sign.returncode != 0: - print "Failed to execute bin/sign_executable.\nThe error was: %s" % result + print("Failed to execute bin/sign_executable.\nThe error was: %s" % result) return output.close() - print "execute script xadd..." + print("execute script xadd...") if not startProcess([os.path.join(args['installroot'], 'bin/xadd')], env): return - print "Running script bin/update_versions..." + print("Running script bin/update_versions...") updt_version = os.path.join(args['installroot'], 'bin/update_versions') p_version = subprocess.Popen([updt_version], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, env=env, @@ -272,17 +274,17 @@ def deployManagement(args): result = p_version.communicate()[0] p_version.stdin.close() if p_version.returncode is None or p_version.returncode != 0: - print "Failed to execute bin/update_versions.\nThe error was: %s" % result + print("Failed to execute bin/update_versions.\nThe error was: %s" % result) return - print "Fill the database... calling bin/create_work..." + print("Fill the database... calling bin/create_work...") create_wu(args, env) - print "Restart Boinc..." + print("Restart Boinc...") subprocess.call((os.path.join(args['installroot'], 'bin', 'stop'),), env=env) subprocess.call((os.path.join(args['installroot'], 'bin', 'start'),), env=env) - print "Boinc Application deployment is done... writing end signal file..." + print("Boinc Application deployment is done... writing end signal file...") writeFile(token, str(args['wu_number'])) @@ -297,7 +299,7 @@ def create_wu(args, env): '--min_quorum', '1', '--target_nresults', '1', args['appname'] + numversion + '_input'] for i in range(args['previous_wu'], args['wu_number']): - print "Creating project wroker %s..." % str(i+1) + print("Creating project wroker %s..." % str(i+1)) launch_args[4] = args['appname'] + str(i+1) + numversion + '_nodelete' startProcess(launch_args, env, args['installroot']) @@ -311,7 +313,7 @@ def runCmd(base_cmd, cc_cmd, installdir, url, key): host = re.search("<ip_addr>([\w\d\.:]+)</ip_addr>", open(client_config, 'r').read()).group(1) base_cmd[2] = host + ':' + base_cmd[2] - print "Run boinccmd with host at %s " % base_cmd[2] + print("Run boinccmd with host at %s " % base_cmd[2]) project_args = base_cmd + ['--project_attach', url, key] startProcess(project_args, cwd=installdir) if cc_cmd: diff --git a/slapos/recipe/bonjourgrid/boinc.py b/slapos/recipe/bonjourgrid/boinc.py index ecf54b44df394761d0ab29b72689e208fe20322a..2af5a233a155849755e1531335fa568e99837fef 100644 --- a/slapos/recipe/bonjourgrid/boinc.py +++ b/slapos/recipe/bonjourgrid/boinc.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import print_function import os import sys import re @@ -36,10 +37,10 @@ def createAccount(config, base_cmd): def runBoinc(config): 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) 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) #XXX Using define values here for Boinc Master URL config['project_url'] = sys.argv[1] @@ -53,7 +54,7 @@ def runBoinc(config): client_config = os.path.join(config['boinc_install_dir'], 'client_state.xml') while not os.path.exists(client_config): time.sleep(5) - print "Search for file '%r'..." % client_config + print("Search for file '%r'..." % client_config) time.sleep(10) try: #Scan client state xml to find client ipv4 adress @@ -64,21 +65,21 @@ def runBoinc(config): '--passwd', config['boinc_passwd']] #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) config['key'] = key - print "Done. The account key is %s" % key + print("Done. The account key is %s" % key) #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: joinProject(config, base_cmd) - except Exception, e: - print e - print "Done! Waiting for Boinc Client now..." - except Exception, e: + except Exception as e: + print(e) + print("Done! Waiting for Boinc Client now...") + except Exception as e: #An error occure!!! os.kill(boinc.pid, signal.SIGTERM) - print e + print(e) #wait for Boinc client execution boinc.wait() diff --git a/slapos/recipe/bonjourgrid/condor.py b/slapos/recipe/bonjourgrid/condor.py index 21fd1cb152cb8be32ce0e925d80d8e882b125d45..99ab5fb7454bfc7015bd4ebe10973efe521320ac 100644 --- a/slapos/recipe/bonjourgrid/condor.py +++ b/slapos/recipe/bonjourgrid/condor.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import print_function import os import sys import re @@ -33,7 +34,7 @@ def updateCondorWrapper(folder, hostname, ipv6): def runCondor(config): 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) hostname = sys.argv[1] diff --git a/slapos/recipe/bonjourgrid/configure.py b/slapos/recipe/bonjourgrid/configure.py index 8719ae8ae101055347036b1abaf211a890e0af79..2c61661bdc1cf942b7159a741c86429f613dd74e 100644 --- a/slapos/recipe/bonjourgrid/configure.py +++ b/slapos/recipe/bonjourgrid/configure.py @@ -25,6 +25,7 @@ # ############################################################################## +from __future__ import print_function import os import subprocess import time @@ -40,7 +41,7 @@ def runProcess(args, file): return process.pid def launchScript(args): - print "Sleep for a few second..." + print("Sleep for a few second...") time.sleep(10) pid_list = [] bg_pid = os.path.join(args['bg_base'], 'pid') @@ -63,6 +64,6 @@ def launchScript(args): pid_list.append(runProcess(args, file)) 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) - print "Done...", result + print("Done...", result) diff --git a/slapos/recipe/certificate_authority/__init__.py b/slapos/recipe/certificate_authority/__init__.py index 3d550d695dff6eba9a1c018a9c39108119be22ba..6b7d0378d7c5bbfebdfcad32dff58d42a6ae5504 100644 --- a/slapos/recipe/certificate_authority/__init__.py +++ b/slapos/recipe/certificate_authority/__init__.py @@ -26,6 +26,7 @@ ############################################################################## import os import hashlib +import six from six.moves import configparser import tempfile @@ -108,6 +109,8 @@ class Request(Recipe): request_needed = True name = self.options['name'] + if six.PY3 and type(name) is str: + name = name.encode("utf-8") hash_ = hashlib.sha512(name).hexdigest() key = os.path.join(self.ca_private, hash_ + self.ca_key_ext) certificate = os.path.join(self.ca_certs, hash_ + self.ca_crt_ext) diff --git a/slapos/recipe/condor/configure.py b/slapos/recipe/condor/configure.py index f0590ebe4b970a3015a2eabf4fc99a3ffc980590..e658cd19275e004fd1f1e70d2f20bfc4cf09e3f0 100644 --- a/slapos/recipe/condor/configure.py +++ b/slapos/recipe/condor/configure.py @@ -25,6 +25,7 @@ # ############################################################################## +from __future__ import print_function import os import subprocess import time @@ -32,9 +33,9 @@ import time def submitJob(submit, submit_file, appdir, appname, sig_install): """Run condor_submit (if needed) for job deployment""" 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): - print "Nothing for install or update...Exited" + print("Nothing for install or update...Exited") return # '-a', "log = out.log", '-a', "error = error.log", launch_args = submit, '-verbose', submit_file @@ -42,7 +43,7 @@ def submitJob(submit, submit_file, appdir, appname, sig_install): stderr=subprocess.STDOUT, cwd=appdir) result = process.communicate()[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: os.unlink(sig_install) diff --git a/slapos/recipe/container.py b/slapos/recipe/container.py index 96dbb2113d646584d018d91cb9bc7202768a2714..1942cfaed518cc939fc5f217eafaad4e314652d4 100644 --- a/slapos/recipe/container.py +++ b/slapos/recipe/container.py @@ -25,7 +25,7 @@ # ############################################################################## -import ConfigParser +from six.moves import configparser import uuid import os import subprocess @@ -47,7 +47,7 @@ class Recipe(GenericSlapRecipe): container_uuid = None if os.path.exists(config_filename): - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(config_filename) if config.has_option('requested', 'name'): container_uuid = uuid.UUID(hex=config.get('requested', 'name')) @@ -68,7 +68,7 @@ class Recipe(GenericSlapRecipe): self.logger.info("Putting slapcontainer configuration file...") - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.add_section('requested') config.set('requested', 'status', self.computer_partition.getState()) diff --git a/slapos/recipe/erp5testnode/__init__.py b/slapos/recipe/erp5testnode/__init__.py index 96c2584d83d3e0181ce1d06eb21ca689979ced8d..0ba3973172a5a17e7cb5919ef265036cc66340d0 100644 --- a/slapos/recipe/erp5testnode/__init__.py +++ b/slapos/recipe/erp5testnode/__init__.py @@ -30,13 +30,14 @@ import json import os from slapos.recipe.librecipe import GenericBaseRecipe +import six class Recipe(GenericBaseRecipe): def install(self): self.path_list = [] options = self.options.copy() 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'] if self.options['instance-dict']: @@ -44,7 +45,7 @@ class Recipe(GenericBaseRecipe): config_instance_dict.add_section('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) value = io.StringIO() config_instance_dict.write(value) diff --git a/slapos/recipe/free_port.py b/slapos/recipe/free_port.py index ef9ce9f397545cd4d38d345b787a998ff3d79e23..736f77b11630f1928ce39d6e23def2954006c056 100644 --- a/slapos/recipe/free_port.py +++ b/slapos/recipe/free_port.py @@ -29,6 +29,7 @@ from six.moves import configparser import os import netaddr import socket +from six.moves import range class Recipe(object): """ @@ -89,7 +90,7 @@ class Recipe(object): This algorithm thus returns always the same value with the same parameters in 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) try: sock.bind((self.ip, port)) diff --git a/slapos/recipe/generic_cloudooo/__init__.py b/slapos/recipe/generic_cloudooo/__init__.py index 4126ce46063f7d783fc24f22541665ca2321c798..10aa44dfc56a27c533b430fa0e9c0776970c6cfb 100644 --- a/slapos/recipe/generic_cloudooo/__init__.py +++ b/slapos/recipe/generic_cloudooo/__init__.py @@ -27,6 +27,7 @@ from functools import cmp_to_key import zc.buildout from slapos.recipe.librecipe import GenericBaseRecipe +from six.moves import range @cmp_to_key def compareMimetypeEntryPair(a, b): diff --git a/slapos/recipe/generic_mysql/mysql.py b/slapos/recipe/generic_mysql/mysql.py index 25d9f9f34fff08b2bfe6fc8529adadba7711a467..b7ee6ce8550598ae6d24125a0aedad5d89c148fa 100644 --- a/slapos/recipe/generic_mysql/mysql.py +++ b/slapos/recipe/generic_mysql/mysql.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import subprocess import time @@ -19,31 +20,31 @@ def updateMysql(mysql_upgrade_binary, mysql_binary, mysql_script_file): stdout=subprocess.PIPE, stderr=subprocess.STDOUT) result = mysql_upgrade.communicate()[0] 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 - 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, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) result = mysql.communicate(mysql_script)[0] if mysql.returncode: - print 'Command %r failed with:\n%s' % (mysql_list, result) + print('Command %r failed with:\n%s' % (mysql_list, result)) break # import timezone database mysql_tzinfo_to_sql = subprocess.Popen(mysql_tzinfo_to_sql_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) timezone_sql = mysql_tzinfo_to_sql.communicate()[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 mysql = subprocess.Popen(mysql_list + ('mysql',), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) result = mysql.communicate(timezone_sql)[0] if mysql.returncode: - print 'Command %r failed with:\n%s' % (mysql_list, result) + print('Command %r failed with:\n%s' % (mysql_list, result)) break - print 'SlapOS initialisation script succesfully applied on database.' + print('SlapOS initialisation script succesfully applied on database.') return - print 'Sleeping for %ss and retrying' % sleep + print('Sleeping for %ss and retrying' % sleep) sys.stdout.flush() sys.stderr.flush() time.sleep(sleep) diff --git a/slapos/recipe/gitinit.py b/slapos/recipe/gitinit.py index 409113c185081158f3775283f7dfa0a9afbd3ca5..7070b03636e491af901371417f2db13ce54e8160 100644 --- a/slapos/recipe/gitinit.py +++ b/slapos/recipe/gitinit.py @@ -30,13 +30,14 @@ import os from subprocess import check_call from slapos.recipe.librecipe import GenericBaseRecipe +import six class Recipe(GenericBaseRecipe): def install(self): 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) if not os.path.exists(absolute_path): check_call([self.options['git-binary'], 'init', diff --git a/slapos/recipe/haproxy/__init__.py b/slapos/recipe/haproxy/__init__.py index 50b6d718cfec53cf65b87f33838f0b0bfeaeda52..36e8383e2b1e40016f0ad2f09c0ed07569fb85f9 100644 --- a/slapos/recipe/haproxy/__init__.py +++ b/slapos/recipe/haproxy/__init__.py @@ -25,6 +25,7 @@ # ############################################################################## from slapos.recipe.librecipe import GenericBaseRecipe +import six class Recipe(GenericBaseRecipe): """ @@ -95,7 +96,7 @@ class Recipe(GenericBaseRecipe): # FIXME: maxconn must be provided per-backend, not globally maxconn = self.options['maxconn'] 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( listen_snippet_filename, { 'name': name, diff --git a/slapos/recipe/haproxy/haproxy.py b/slapos/recipe/haproxy/haproxy.py index a87c5d34451a0b2005526c2e3cb88889b86ea60b..b56bf23c7949d6c3791a2b6b2b99c47c9847804b 100644 --- a/slapos/recipe/haproxy/haproxy.py +++ b/slapos/recipe/haproxy/haproxy.py @@ -1,4 +1,6 @@ +from __future__ import print_function import socket +from six.moves import input try: import readline except ImportError: @@ -7,9 +9,9 @@ except ImportError: def haproxyctl(socket_path): while True: try: - l = raw_input('> ') + l = input('> ') except EOFError: - print + print() break if l == 'quit': break @@ -20,5 +22,5 @@ def haproxyctl(socket_path): r = s.recv(1024) if not r: break - print r + print(r) s.close() diff --git a/slapos/recipe/lamp/__init__.py b/slapos/recipe/lamp/__init__.py index 3e5bb1a98da2214e9efbddd32e2061facf861c02..0306e469ddb489c556448a174a28e1c04116784c 100644 --- a/slapos/recipe/lamp/__init__.py +++ b/slapos/recipe/lamp/__init__.py @@ -130,7 +130,7 @@ class BaseRecipe(BaseSlapRecipe): 'template/apache.in'), apache_config)) self.path_list.append(config_file) 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') self.path_list.append(self.createConfigurationFile('php.ini', self.substituteTemplate(php_ini, dict(tmp_directory=self.tmp_directory)))) @@ -161,8 +161,7 @@ class BaseRecipe(BaseSlapRecipe): """Start process which can launch python scripts, move or remove files or directories when installing software. """ - if not self.options.has_key('delete') and not self.options.has_key('rename') and not\ - self.options.has_key('chmod') and not self.options.has_key('script'): + if 'delete' not in self.options and 'rename' not in self.options and 'chmod' not in self.options and 'script' not in self.options: return "" delete = [] chmod = [] @@ -172,7 +171,7 @@ class BaseRecipe(BaseSlapRecipe): argument = [self.options['lampconfigure_directory'].strip(), "-H", mysql_conf['mysql_host'], "-P", mysql_conf['mysql_port'], "-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'], "--table", self.options['table_name'].strip(), "--cond", self.options['constraint'].strip()] @@ -180,11 +179,11 @@ class BaseRecipe(BaseSlapRecipe): argument = argument + ["-f", self.options['file_token'].strip()] argument += ["-t", document_root] - if self.options.has_key('delete'): + if 'delete' in self.options: delete = ["delete"] for fname in self.options['delete'].split(','): delete.append(fname.strip()) - if self.options.has_key('rename'): + if 'rename' in self.options: for fname in self.options['rename'].split(','): if fname.find("=>") < 0: old_name = fname @@ -194,15 +193,15 @@ class BaseRecipe(BaseSlapRecipe): else: fname = fname.split("=>") cmd = ["rename"] - if self.options.has_key('rename_chmod'): + if 'rename_chmod' in self.options: cmd += ["--chmod", self.options['rename_chmod'].strip()] rename.append(cmd + [fname[0].strip(), fname[1].strip()]) rename_list += fname[0] + " to " + fname[1] + " " - if self.options.has_key('chmod'): + if 'chmod' in self.options: chmod = ["chmod", self.options['mode'].strip()] for fname in self.options['chmod'].split(','): chmod.append(fname.strip()) - if self.options.has_key('script') and \ + if 'script' in self.options and \ self.options['script'].strip().endswith(".py"): data = ["run", self.options['script'].strip(), "-v", mysql_conf['mysql_database'], url, document_root] self.path_list.extend(zc.buildout.easy_install.scripts( @@ -237,7 +236,7 @@ class Simple(BaseRecipe): if not renamed == "": connectionDict['rename'] = renamed 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.options['configuration'], mysql_conf) return self.path_list diff --git a/slapos/recipe/lamp/apache.py b/slapos/recipe/lamp/apache.py index 861f787d09fed9c80b38f561528fbd86b5c7ad44..98ac3d6329e9a3b34164870ca20e47497a2e808c 100644 --- a/slapos/recipe/lamp/apache.py +++ b/slapos/recipe/lamp/apache.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import sys import time @@ -10,7 +11,7 @@ def runApache(args): ready = True for f in conf.get('required_path_list', []): 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 if ready: break diff --git a/slapos/recipe/lamp/mysql.py b/slapos/recipe/lamp/mysql.py index c0f399084738ea3aee5020e33d1cf2b5f3db730d..d6a29392b8d51460fe6d850f358c00cd2b2b9c38 100644 --- a/slapos/recipe/lamp/mysql.py +++ b/slapos/recipe/lamp/mysql.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import subprocess import time @@ -20,15 +21,15 @@ def runMysql(args): stdout=subprocess.PIPE, stderr=subprocess.STDOUT) result = popen.communicate()[0] if popen.returncode is None or popen.returncode != 0: - print "Failed to initialise server.\nThe error was: %s" % result - print "Waiting for %ss and retrying" % sleep + print("Failed to initialise server.\nThe error was: %s" % result) + print("Waiting for %ss and retrying" % sleep) time.sleep(sleep) else: - print "Mysql properly initialised" + print("Mysql properly initialised") break else: - print "MySQL already initialised" - print "Starting %r" % mysqld_wrapper_list[0] + print("MySQL already initialised") + print("Starting %r" % mysqld_wrapper_list[0]) sys.stdout.flush() sys.stderr.flush() os.execl(mysqld_wrapper_list[0], *mysqld_wrapper_list) @@ -46,13 +47,13 @@ def updateMysql(args): if mysql_upgrade.returncode is None: mysql_upgrade.kill() 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 'Sleeping for %ss and retrying' % sleep + print("Command %r failed with result:\n%s" % (mysql_upgrade_list, result)) + print('Sleeping for %ss and retrying' % sleep) else: if mysql_upgrade.returncode == 0: - print "MySQL database upgraded with result:\n%s" % result + print("MySQL database upgraded with result:\n%s" % result) else: - print "No need to upgrade MySQL database" + print("No need to upgrade MySQL database") mysql_script = conf.get('mysql_script') if mysql_script: mysql_list = [conf['mysql_binary'].strip(), '--no-defaults', '-B', '--user=root', '--socket=%s' % conf['socket']] @@ -62,11 +63,11 @@ def updateMysql(args): if mysql.returncode is None: mysql.kill() if mysql.returncode != 0: - print 'Command %r failed with:\n%s' % (mysql_list, result) - print 'Sleeping for %ss and retrying' % sleep + print('Command %r failed with:\n%s' % (mysql_list, result)) + print('Sleeping for %ss and retrying' % sleep) else: is_succeed = True - print 'SlapOS initialisation script succesfully applied on database.' + print('SlapOS initialisation script succesfully applied on database.') sys.stdout.flush() sys.stderr.flush() time.sleep(sleep) diff --git a/slapos/recipe/lamp/runner.py b/slapos/recipe/lamp/runner.py index b4ef29890ffa5ee3934f446a3689368d15e94012..cffa873ae74697a3358f27092a0d176676922419 100644 --- a/slapos/recipe/lamp/runner.py +++ b/slapos/recipe/lamp/runner.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import subprocess @@ -8,20 +9,20 @@ def executeRunner(args): """ arguments, delete, rename, chmod, data = args if delete != []: - print "Calling lampconfigure with 'delete' arguments" + print("Calling lampconfigure with 'delete' arguments") result = subprocess.Popen(arguments + delete) result.wait() if rename != []: for parameters in rename: - print "Calling lampconfigure with 'rename' arguments" + print("Calling lampconfigure with 'rename' arguments") result = subprocess.Popen(arguments + parameters) result.wait() if chmod != []: - print "Calling lampconfigure with 'chmod' arguments" + print("Calling lampconfigure with 'chmod' arguments") result = subprocess.Popen(arguments + chmod) result.wait() if data != []: - print "Calling lampconfigure with 'run' arguments" + print("Calling lampconfigure with 'run' arguments") result = subprocess.Popen(arguments + data) result.wait() return diff --git a/slapos/recipe/librecipe/execute.py b/slapos/recipe/librecipe/execute.py index b93f3c3c65eafccf4a8f167852b48d8bb72fc3c0..92c5156b00b9209382f27dcd54857f23245adff8 100644 --- a/slapos/recipe/librecipe/execute.py +++ b/slapos/recipe/librecipe/execute.py @@ -8,6 +8,7 @@ from collections import defaultdict from inotify_simple import INotify, flags import six +from six.moves import range def _wait_files_creation(file_list): # Establish a list of directory and subfiles. @@ -66,7 +67,7 @@ def generic_exec(args, extra_environ=None, wait_list=None, else: # With chained shebangs, several paths may be inserted at the beginning. 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]: sys.exit("Already running with pid %s." % pid) with open(pidfile, 'w') as f: diff --git a/slapos/recipe/mioga/instantiate.py b/slapos/recipe/mioga/instantiate.py index 13a4ec8ceef46bc5e77f26441d679373947079ac..19d4e4e25aec84bc8f84468ab0cbf0db22c4927a 100644 --- a/slapos/recipe/mioga/instantiate.py +++ b/slapos/recipe/mioga/instantiate.py @@ -25,6 +25,7 @@ # ############################################################################## +from __future__ import print_function import os import pprint import re @@ -215,7 +216,7 @@ Include conf/extra/httpd-autoindex.conf if not stat.S_ISFIFO(os.stat(fifo).st_mode): raise Exception("The file "+fifo+" exists but is not a FIFO.") else: - os.mkfifo(fifo, 0600) + os.mkfifo(fifo, 0o600) site_perl_bin = os.path.join(self.options['site_perl'], 'bin') mioga_conf_path = os.path.join(mioga_base, 'conf', 'Mioga.conf') @@ -253,7 +254,7 @@ Include conf/extra/httpd-autoindex.conf pass os.chdir(former_directory) - print "Mioga instantiate.py::install finished!" + print("Mioga instantiate.py::install finished!") return path_list diff --git a/slapos/recipe/mysql/mysql.py b/slapos/recipe/mysql/mysql.py index 6b0074b361bfe40202b6f8dcb62e40995ae9ee72..9ff28cd22cbefea49e87620ad819492c237d23ef 100644 --- a/slapos/recipe/mysql/mysql.py +++ b/slapos/recipe/mysql/mysql.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import subprocess import time @@ -20,15 +21,15 @@ def runMysql(conf): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=conf['cwd']) result = popen.communicate()[0] if popen.returncode is None or popen.returncode != 0: - print "Failed to initialise server.\nThe error was: %s" % result - print "Waiting for %ss and retrying" % sleep + print("Failed to initialise server.\nThe error was: %s" % result) + print("Waiting for %ss and retrying" % sleep) time.sleep(sleep) else: - print "Mysql properly initialised" + print("Mysql properly initialised") break else: - print "MySQL already initialised" - print "Starting %r" % mysqld_wrapper_list[0] + print("MySQL already initialised") + print("Starting %r" % mysqld_wrapper_list[0]) sys.stdout.flush() sys.stderr.flush() os.execl(mysqld_wrapper_list[0], *mysqld_wrapper_list) @@ -45,13 +46,13 @@ def updateMysql(conf): if mysql_upgrade.returncode is None: mysql_upgrade.kill() 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 'Sleeping for %ss and retrying' % sleep + print("Command %r failed with result:\n%s" % (mysql_upgrade_list, result)) + print('Sleeping for %ss and retrying' % sleep) else: if mysql_upgrade.returncode == 0: - print "MySQL database upgraded with result:\n%s" % result + print("MySQL database upgraded with result:\n%s" % result) 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 = subprocess.Popen(mysql_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) @@ -59,11 +60,11 @@ def updateMysql(conf): if mysql.returncode is None: mysql.kill() if mysql.returncode != 0: - print 'Command %r failed with:\n%s' % (mysql_list, result) - print 'Sleeping for %ss and retrying' % sleep + print('Command %r failed with:\n%s' % (mysql_list, result)) + print('Sleeping for %ss and retrying' % sleep) else: is_succeed = True - print 'SlapOS initialisation script succesfully applied on database.' + print('SlapOS initialisation script succesfully applied on database.') sys.stdout.flush() sys.stderr.flush() time.sleep(sleep) diff --git a/slapos/recipe/neoppod.py b/slapos/recipe/neoppod.py index a626e4408fd9755ff89fd7da196bd550db053059..a59371c62701e3efc6e507dd93330ff17bfdcf70 100644 --- a/slapos/recipe/neoppod.py +++ b/slapos/recipe/neoppod.py @@ -28,6 +28,7 @@ import os import shlex from zc.buildout import UserError from .librecipe import GenericBaseRecipe +import six class Cluster(object): @@ -41,7 +42,7 @@ class Cluster(object): for node in sorted(options['nodes'].split()): node = buildout[node] node_list.append(node) - for k, v in result_dict.iteritems(): + for k, v in six.iteritems(result_dict): x = node[k] if x: v.append(x) diff --git a/slapos/recipe/nosqltestbed/__init__.py b/slapos/recipe/nosqltestbed/__init__.py index 2b1eb49f0d57b1ac787c74cd951e11115d9d0185..b5fd816eefd1e8567fd4c96cdfa11d88fec9eb6a 100644 --- a/slapos/recipe/nosqltestbed/__init__.py +++ b/slapos/recipe/nosqltestbed/__init__.py @@ -37,8 +37,8 @@ class NoSQLTestBed(BaseSlapRecipe): def _install(self): self.parameter_dict = self.computer_partition.getInstanceParameterDict() try: - entry_point = pkg_resources.iter_entry_points(group='slapos.recipe.nosqltestbed.plugin', - name=self.parameter_dict.get('plugin', 'kumo')).next() + entry_point = next(pkg_resources.iter_entry_points(group='slapos.recipe.nosqltestbed.plugin', + name=self.parameter_dict.get('plugin', 'kumo'))) plugin_class = entry_point.load() testbed = plugin_class() diff --git a/slapos/recipe/random.py b/slapos/recipe/random.py index a008ec53f6d94a8f65c2b2f97c7ffa43c9051f97..0b5281a83a15305482d801169675ddf1281aea4d 100644 --- a/slapos/recipe/random.py +++ b/slapos/recipe/random.py @@ -35,9 +35,11 @@ from __future__ import absolute_import import errno import os import random +import six import string from .librecipe import GenericBaseRecipe from .publish_early import volatileOptions +from six.moves import range class Integer(object): """ @@ -174,7 +176,10 @@ class Password(object): fd = os.open(self.storage_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY | os.O_TRUNC, 0o600) 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: os.close(fd) if not self.create_once: diff --git a/slapos/recipe/re6stnet/__init__.py b/slapos/recipe/re6stnet/__init__.py index 22ebd865b2efe3c5cd64eefa49665ce7727a4ea1..6ae7891a955a27a821b9d8d3277eabf18a49439c 100644 --- a/slapos/recipe/re6stnet/__init__.py +++ b/slapos/recipe/re6stnet/__init__.py @@ -34,6 +34,7 @@ import string, random import json import traceback from slapos import slap +from six.moves import range class Recipe(GenericBaseRecipe): @@ -154,7 +155,7 @@ class Recipe(GenericBaseRecipe): hash_path = os.path.join(self.options['conf-dir'], '%s-hash' % length) if not os.path.exists(hash_path): 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) else: hash_string = self.readFile(hash_path) diff --git a/slapos/recipe/re6stnet/re6stnet.py b/slapos/recipe/re6stnet/re6stnet.py index 6b00dbbfa21fdabcb9c6bd91e8eb2ae134dcb2c8..e0964f2d1b4d178273d773e6581094f7428c0341 100644 --- a/slapos/recipe/re6stnet/re6stnet.py +++ b/slapos/recipe/re6stnet/re6stnet.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import httplib +import six.moves.http_client import logging import json import os @@ -8,6 +8,7 @@ import slapos import traceback import logging from re6st import registry +import six log = logging.getLogger('SLAPOS-RE6STNET') logging.basicConfig(level=logging.INFO) @@ -93,7 +94,7 @@ def requestRemoveToken(client, token_base_path): reference = reference_key.split('.')[0] try: result = client.deleteToken(token) - except httplib.NOT_FOUND: + except six.moves.http_client.NOT_FOUND: # Token is alread removed. result = True except Exception: @@ -128,7 +129,7 @@ def checkService(client, token_base_path, token_json, computer_partition): return # 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)) status_file = os.path.join(token_base_path, '%s.status' % slave_reference) if not os.path.exists(status_file): diff --git a/slapos/recipe/readline.py b/slapos/recipe/readline.py index 3958bb589fe5d78510d4abadd43562d6dcfa7962..6bde4f4b87b829d871b52d1b1a2c5985c7a5c34a 100644 --- a/slapos/recipe/readline.py +++ b/slapos/recipe/readline.py @@ -46,7 +46,7 @@ class Recipe(object): try: with open(storage_path) as f: readline = f.readline() - except IOError, e: + except IOError as e: if e.errno != errno.ENOENT: raise readline = None diff --git a/slapos/recipe/redis/MyRedis2410.py b/slapos/recipe/redis/MyRedis2410.py index 0c2b0b4a3f4f2392a1c8dcd217508b5ead7e1d96..52716d544a5735701d8bbf672a16007e3749a2c3 100644 --- a/slapos/recipe/redis/MyRedis2410.py +++ b/slapos/recipe/redis/MyRedis2410.py @@ -1,4 +1,7 @@ from __future__ import with_statement +import six +from six.moves import range +from six.moves import zip "Core exceptions raised by the Redis client" @@ -85,7 +88,7 @@ class PythonParser(object): # no length, read a full line 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" % \ (e.args,)) @@ -110,7 +113,7 @@ class PythonParser(object): return response # int value elif byte == ':': - return long(response) + return int(response) # bulk response elif byte == '$': length = int(response) @@ -123,7 +126,7 @@ class PythonParser(object): length = int(response) if length == -1: return None - return [self.read_response() for i in xrange(length)] + return [self.read_response() for i in range(length)] raise InvalidResponse("Protocol Error") class HiredisParser(object): @@ -151,7 +154,7 @@ class HiredisParser(object): while response is False: try: 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" % \ (e.args,)) if not buffer: @@ -197,7 +200,7 @@ class Connection(object): return try: sock = self._connect() - except socket.error, e: + except socket.error as e: raise ConnectionError(self._error_message(e)) self._sock = sock @@ -253,7 +256,7 @@ class Connection(object): self.connect() try: self._sock.sendall(command) - except socket.error, e: + except socket.error as e: self.disconnect() if len(e.args) == 1: _errno, errmsg = 'UNKNOWN', e.args[0] @@ -470,7 +473,7 @@ def zset_score_pairs(response, **options): return response score_cast_func = options.get('score_cast_func', float) 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): if response is None: @@ -513,7 +516,7 @@ class StrictRedis(object): string_keys_to_dict( # these return OK, or int if redis-server is >=1.3.4 '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( @@ -824,7 +827,7 @@ class StrictRedis(object): def mset(self, mapping): "Sets each key in the ``mapping`` dict to its corresponding value" items = [] - for pair in mapping.iteritems(): + for pair in six.iteritems(mapping): items.extend(pair) return self.execute_command('MSET', *items) @@ -834,7 +837,7 @@ class StrictRedis(object): none of the keys are already set """ items = [] - for pair in mapping.iteritems(): + for pair in six.iteritems(mapping): items.extend(pair) return self.execute_command('MSETNX', *items) @@ -1218,7 +1221,7 @@ class StrictRedis(object): raise RedisError("ZADD requires an equal number of " "values and scores") pieces.extend(args) - for pair in kwargs.iteritems(): + for pair in six.iteritems(kwargs): pieces.append(pair[1]) pieces.append(pair[0]) return self.execute_command('ZADD', name, *pieces) @@ -1383,7 +1386,7 @@ class StrictRedis(object): def _zaggregate(self, command, dest, keys, aggregate=None): pieces = [command, dest, len(keys)] if isinstance(keys, dict): - keys, weights = keys.keys(), keys.values() + keys, weights = list(keys.keys()), list(keys.values()) else: weights = None pieces.extend(keys) @@ -1446,7 +1449,7 @@ class StrictRedis(object): if not mapping: raise DataError("'hmset' with 'mapping' of length 0") items = [] - for pair in mapping.iteritems(): + for pair in six.iteritems(mapping): items.extend(pair) return self.execute_command('HMSET', name, *items) @@ -1540,7 +1543,7 @@ class Redis(StrictRedis): raise RedisError("ZADD requires an equal number of " "values and scores") pieces.extend(reversed(args)) - for pair in kwargs.iteritems(): + for pair in six.iteritems(kwargs): pieces.append(pair[1]) pieces.append(pair[0]) return self.execute_command('ZADD', name, *pieces) diff --git a/slapos/recipe/simplehttpserver/__init__.py b/slapos/recipe/simplehttpserver/__init__.py index 7f8bcaf2a4946d3359278d2b03f0431e7e8bf74e..bbb6f06b39aab5d6b155260fdc2c60e8bc167670 100644 --- a/slapos/recipe/simplehttpserver/__init__.py +++ b/slapos/recipe/simplehttpserver/__init__.py @@ -27,6 +27,7 @@ from slapos.recipe.librecipe import GenericBaseRecipe import string, random import os +from six.moves import range class Recipe(GenericBaseRecipe): @@ -35,7 +36,7 @@ class Recipe(GenericBaseRecipe): base_path = options['base-path'] if options.get('use-hash-url', 'True') in ['true', 'True']: 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) if os.path.exists(base_path): diff --git a/slapos/recipe/simplehttpserver/simplehttpserver.py b/slapos/recipe/simplehttpserver/simplehttpserver.py index 4503f0deb5fd06b4236bc6bfa7cf930e588b2667..649a4836558b25b72f63a1a9d5e03bdde16649a2 100644 --- a/slapos/recipe/simplehttpserver/simplehttpserver.py +++ b/slapos/recipe/simplehttpserver/simplehttpserver.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from SimpleHTTPServer import SimpleHTTPRequestHandler -from BaseHTTPServer import HTTPServer +from six.moves.SimpleHTTPServer import SimpleHTTPRequestHandler +from six.moves.BaseHTTPServer import HTTPServer import ssl import os import logging @@ -46,7 +46,7 @@ class ServerHandler(SimpleHTTPRequestHandler): name = form['path'].value content = form['content'].value method = 'a' - if form.has_key('clear') and form['clear'].value == '1': + if 'clear' in form and form['clear'].value == '1': method = 'w' self.writeFile(name, content, method) self.respond(200, type=self.headers['Content-Type']) @@ -97,7 +97,7 @@ def run(args): httpd = server((host, port), Handler) 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']): scheme = 'https' httpd.socket = ssl.wrap_socket (httpd.socket, diff --git a/slapos/recipe/simplelogger.py b/slapos/recipe/simplelogger.py index 5c1c247800ab6e8ae6ba04c01066c1defa84bdd1..b150007fd647adc447c05848271e0531a41a7202 100644 --- a/slapos/recipe/simplelogger.py +++ b/slapos/recipe/simplelogger.py @@ -24,6 +24,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## +from __future__ import print_function import sys import time @@ -33,8 +34,8 @@ def log(filename): prefix = time.strftime('%Y-%m-%d.%H:%M.%s:') with open(filename, 'a') as logfile: for line in sys.stdin: - print >> logfile, prefix, line, - print >> logfile, prefix, '------------------------' + print(prefix, line, end=' ', file=logfile) + print(prefix, '------------------------', file=logfile) class Recipe(GenericBaseRecipe): diff --git a/slapos/recipe/softwaretype.py b/slapos/recipe/softwaretype.py index 085eb16b9c74b62cd4e8ac80f1a56f9d92626b26..55f82b39633ee6722f8ad0c00df47792c3896f12 100644 --- a/slapos/recipe/softwaretype.py +++ b/slapos/recipe/softwaretype.py @@ -28,7 +28,7 @@ import os import sys import copy -from ConfigParser import ConfigParser +from six.moves.configparser import ConfigParser import json import subprocess import slapos.slap @@ -38,6 +38,7 @@ import errno import re import zc.buildout +import six class SlapConfigParser(ConfigParser, object): """ @@ -138,9 +139,9 @@ class Recipe: for name, ip in self.parameter_dict['ip_list']: if 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. NB: If the directory already exists, it does not change its permission. @@ -193,7 +194,10 @@ class Recipe: raise zc.buildout.UserError("The specified buildout config file %r does " "not exist." % instance_file_path) - buildout = SlapConfigParser() + try: + buildout = SlapConfigParser(strict=False) + except TypeError: + buildout = SlapConfigParser() with open(instance_file_path) as instance_path: buildout.readfp(instance_path) @@ -231,7 +235,7 @@ class Recipe: # Copy/paste 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 buildout.set('slap-connection', key.replace('_', '-'), value) # XXX: Needed for lxc. Use non standard API diff --git a/slapos/recipe/switch_softwaretype.py b/slapos/recipe/switch_softwaretype.py index c42ac31e5348b294a52cb200c109ccf0cb3b4e8e..a78f5a269e5286cbdc2bc8a4807b2879d1fa9b66 100644 --- a/slapos/recipe/switch_softwaretype.py +++ b/slapos/recipe/switch_softwaretype.py @@ -26,6 +26,7 @@ ############################################################################## import os, subprocess, sys +import six class Recipe: @@ -41,7 +42,7 @@ class Recipe: # 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. 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) for x in "directory", "eggs-directory", "develop-eggs-directory": args.append("buildout:%s=%s" % (x, self.buildout["buildout"][x])) diff --git a/slapos/recipe/trac.py b/slapos/recipe/trac.py index 3da82216f4c3803aa49a03d4ab9a0d92a1b3821e..07f4b0ab83dacd9aeefb42096fd38269b080c69e 100644 --- a/slapos/recipe/trac.py +++ b/slapos/recipe/trac.py @@ -32,6 +32,7 @@ import shutil import json from slapos.recipe.librecipe import GenericBaseRecipe +import six class Recipe(GenericBaseRecipe): @@ -141,7 +142,7 @@ class Recipe(GenericBaseRecipe): self.logger.info("Finished initializing %s reposiroty" % svn_repo) 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) if not os.path.exists(absolute_path): self.logger.info("Initializing %s GIT repository..." % repo) diff --git a/slapos/recipe/zabbixagent/svcdaemon.py b/slapos/recipe/zabbixagent/svcdaemon.py index dcdead9ac154604fab43e4064d8ccc9351d8d4d4..f3d3c8c3eb8b9016d992abd7c01af2002cf423e0 100644 --- a/slapos/recipe/zabbixagent/svcdaemon.py +++ b/slapos/recipe/zabbixagent/svcdaemon.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import subprocess import time @@ -16,7 +17,7 @@ def get_pid(filename): pid_file = None def sig_handler(s, frame): - print "Killing on signal %s:" % s, + print("Killing on signal %s:" % s, end=' ') global pid_file if pid_file is not None: pid = get_pid(pid_file) @@ -33,11 +34,11 @@ def sig_handler(s, frame): except Exception: pass else: - print 'with SIGKILL...', + print('with SIGKILL...', end=' ') os.kill(pid, signal.SIGKILL) else: raise ValueError('Pid is none.') - print 'done.' + print('done.') sys.exit(0) signal.signal(signal.SIGINT, sig_handler) @@ -51,7 +52,7 @@ def svcdaemon(args): global pid_file pid_file = args[0]['pid_file'] subprocess.check_call(real_binary) - print 'Started %r' % real_binary + print('Started %r' % real_binary) while True: time.sleep(5) pid = get_pid(pid_file) diff --git a/slapos/recipe/zero_knowledge.py b/slapos/recipe/zero_knowledge.py index abd68c05b623f08931e58ded0b23fccb15dcc788..c3c3c4f9fb95eaca8196fcd2e609f7dcf1068442 100644 --- a/slapos/recipe/zero_knowledge.py +++ b/slapos/recipe/zero_knowledge.py @@ -25,7 +25,7 @@ # ############################################################################## -import ConfigParser +import six.moves.configparser import os import zc.buildout @@ -53,7 +53,7 @@ class WriteRecipe(GenericBaseRecipe): def install(self): # Set up the parser, and write config file if needed - self.parser = ConfigParser.ConfigParser() + self.parser = six.moves.configparser.ConfigParser() try: self.parser.read(self.path) #clean_options(options) @@ -63,7 +63,7 @@ class WriteRecipe(GenericBaseRecipe): with open(self.path, 'w') as file: self.parser.write(file) # 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() def full_install(self): @@ -94,7 +94,7 @@ class ReadRecipe(GenericBaseRecipe): self.path = options['file-path'].strip() # 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): self.parser.read(self.path) for section in self.parser.sections():