Commit f84536b8 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪 Committed by Julien Muchembled

More Py3 fixes

parent 9c49c425
...@@ -69,7 +69,7 @@ For example:: ...@@ -69,7 +69,7 @@ For example::
recipe = slapos.recipe.build recipe = slapos.recipe.build
example = foobar's one example = foobar's one
script = script =
print '%%s' %% self.options['example'] print('%%s' %% self.options['example'])
# will print “foobar's one” # will print “foobar's one”
[no-escaping] [no-escaping]
...@@ -78,9 +78,9 @@ For example:: ...@@ -78,9 +78,9 @@ For example::
foo = bar foo = bar
format = no format = no
script = script =
print '%s' % self.options['example'] print('%s' % self.options['example'])
# will print “foobar's one” # will print “foobar's one”
print '%(foo)s' print('%(foo)s')
# will print “%(foo)s” # will print “%(foo)s”
Pure download Pure download
...@@ -150,7 +150,7 @@ the recipe will pick up the latest commit on the remote master branch:: ...@@ -150,7 +150,7 @@ the recipe will pick up the latest commit on the remote master branch::
This will clone the git repository in `parts/git-clone` directory. This will clone the git repository in `parts/git-clone` directory.
Then let's run the buildout:: Then let's run the buildout::
>>> print system(buildout) >>> print(system(buildout))
Installing git-clone. Installing git-clone.
Cloning into '/sample-buildout/parts/git-clone'... Cloning into '/sample-buildout/parts/git-clone'...
...@@ -161,7 +161,7 @@ Let's take a look at the buildout parts directory now:: ...@@ -161,7 +161,7 @@ Let's take a look at the buildout parts directory now::
When updating, it will do a "git fetch; git reset @{upstream}":: When updating, it will do a "git fetch; git reset @{upstream}"::
>>> print system(buildout) >>> print(system(buildout))
Updating git-clone. Updating git-clone.
Fetching origin Fetching origin
HEAD is now at ... HEAD is now at ...
...@@ -185,7 +185,7 @@ run it will take the latest commit on this remote branch:: ...@@ -185,7 +185,7 @@ run it will take the latest commit on this remote branch::
Then let's run the buildout:: Then let's run the buildout::
>>> print system(buildout) >>> print(system(buildout))
Uninstalling git-clone. Uninstalling git-clone.
Running uninstall recipe. Running uninstall recipe.
Installing git-clone. Installing git-clone.
...@@ -200,13 +200,13 @@ And let's see that current branch is "build":: ...@@ -200,13 +200,13 @@ And let's see that current branch is "build"::
>>> import subprocess >>> import subprocess
>>> cd('parts', 'git-clone') >>> cd('parts', 'git-clone')
>>> print subprocess.check_output(['git', 'branch']) >>> print(subprocess.check_output(['git', 'branch'], universal_newlines=True))
* build * build
When updating, it will do a "git fetch; git reset build":: When updating, it will do a "git fetch; git reset build"::
>>> cd(sample_buildout) >>> cd(sample_buildout)
>>> print system(buildout) >>> print(system(buildout))
Updating git-clone. Updating git-clone.
Fetching origin Fetching origin
HEAD is now at ... HEAD is now at ...
...@@ -231,7 +231,7 @@ This option has priority over the "branch" option:: ...@@ -231,7 +231,7 @@ This option has priority over the "branch" option::
Then let's run the buildout:: Then let's run the buildout::
>>> print system(buildout) >>> print(system(buildout))
Uninstalling git-clone. Uninstalling git-clone.
Running uninstall recipe. Running uninstall recipe.
Installing git-clone. Installing git-clone.
...@@ -246,13 +246,13 @@ And let's see that current revision is "2566127":: ...@@ -246,13 +246,13 @@ And let's see that current revision is "2566127"::
>>> import subprocess >>> import subprocess
>>> cd(sample_buildout, 'parts', 'git-clone') >>> cd(sample_buildout, 'parts', 'git-clone')
>>> print subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']) >>> print(subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], universal_newlines=True))
2566127 2566127
When updating, it will do a "git fetch; git reset revision":: When updating, it will do a "git fetch; git reset revision"::
>>> cd(sample_buildout) >>> cd(sample_buildout)
>>> print system(buildout) >>> print(system(buildout))
Updating git-clone. Updating git-clone.
... ...
HEAD is now at 2566127 ... HEAD is now at 2566127 ...
...@@ -283,14 +283,14 @@ extend an existing section specifying a branch):: ...@@ -283,14 +283,14 @@ extend an existing section specifying a branch)::
... branch = master ... branch = master
... """) ... """)
>>> print system(buildout) >>> print(system(buildout))
Uninstalling git-clone. Uninstalling git-clone.
Running uninstall recipe. Running uninstall recipe.
Installing git-clone. Installing git-clone.
Cloning into '/sample-buildout/parts/git-clone'... Cloning into '/sample-buildout/parts/git-clone'...
>>> cd(sample_buildout, 'parts', 'git-clone') >>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('git branch') >>> print(system('git branch'))
* master * master
Revision/branch priority Revision/branch priority
...@@ -312,7 +312,7 @@ and branch parameter is ignored:: ...@@ -312,7 +312,7 @@ and branch parameter is ignored::
... revision = 2566127 ... revision = 2566127
... """) ... """)
>>> print system(buildout) >>> print(system(buildout))
Uninstalling git-clone. Uninstalling git-clone.
Running uninstall recipe. Running uninstall recipe.
Installing git-clone. Installing git-clone.
...@@ -321,7 +321,7 @@ and branch parameter is ignored:: ...@@ -321,7 +321,7 @@ and branch parameter is ignored::
HEAD is now at 2566127 ... HEAD is now at 2566127 ...
>>> cd(sample_buildout, 'parts', 'git-clone') >>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('git branch') >>> print(system('git branch'))
* master * master
Setup a "develop" repository Setup a "develop" repository
...@@ -351,7 +351,7 @@ erase your local modifications by specifying the "develop" flag:: ...@@ -351,7 +351,7 @@ erase your local modifications by specifying the "develop" flag::
... develop = true ... develop = true
... """) ... """)
>>> print system(buildout) >>> print(system(buildout))
Uninstalling git-clone. Uninstalling git-clone.
Running uninstall recipe. Running uninstall recipe.
Installing git-clone. Installing git-clone.
...@@ -361,10 +361,10 @@ Buildout will then keep local modifications, instead of resetting the ...@@ -361,10 +361,10 @@ Buildout will then keep local modifications, instead of resetting the
repository:: repository::
>>> cd(sample_buildout, 'parts', 'git-clone') >>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('echo foo > setup.py') >>> print(system('echo foo > setup.py'))
>>> cd(sample_buildout) >>> cd(sample_buildout)
>>> print system(buildout) >>> print(system(buildout))
Updating git-clone. Updating git-clone.
Fetching origin Fetching origin
... ...
...@@ -372,26 +372,26 @@ repository:: ...@@ -372,26 +372,26 @@ repository::
>>> cd(sample_buildout, 'parts', 'git-clone') >>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('cat setup.py') >>> print(system('cat setup.py'))
foo foo
Then, when update occurs, nothing is done:: Then, when update occurs, nothing is done::
>>> cd(sample_buildout, 'parts', 'git-clone') >>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('echo kept > local_change') >>> print(system('echo kept > local_change'))
>>> print system('git remote add broken http://git.erp5.org/repos/nowhere') >>> print(system('git remote add broken http://git.erp5.org/repos/nowhere'))
... ...
>>> cd(sample_buildout) >>> cd(sample_buildout)
>>> print system(buildout) >>> print(system(buildout))
Updating git-clone. Updating git-clone.
Fetching origin Fetching origin
Fetching broken Fetching broken
Unable to update: Unable to update:
Traceback (most recent call last): Traceback (most recent call last):
... ...
CalledProcessError: Command '['git', 'fetch', '--all']' returned non-zero exit status 1 ...CalledProcessError: Command '['git', 'fetch', '--all']' returned non-zero exit status 1
<BLANKLINE> <BLANKLINE>
... ...
fatal: unable to access 'http://git.erp5.org/repos/nowhere/': The requested URL returned error: 500 fatal: unable to access 'http://git.erp5.org/repos/nowhere/': The requested URL returned error: 500
...@@ -399,7 +399,7 @@ Then, when update occurs, nothing is done:: ...@@ -399,7 +399,7 @@ Then, when update occurs, nothing is done::
<BLANKLINE> <BLANKLINE>
>>> cd(sample_buildout, 'parts', 'git-clone') >>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('cat local_change') >>> print(system('cat local_change'))
kept kept
In case of uninstall, buildout will keep the repository directory:: In case of uninstall, buildout will keep the repository directory::
...@@ -418,7 +418,7 @@ In case of uninstall, buildout will keep the repository directory:: ...@@ -418,7 +418,7 @@ In case of uninstall, buildout will keep the repository directory::
... foo = bar ... foo = bar
... """) ... """)
>>> print system(buildout) >>> print(system(buildout))
Uninstalling git-clone. Uninstalling git-clone.
Running uninstall recipe. Running uninstall recipe.
You have uncommited changes in /sample-buildout/parts/git-clone. This folder will be left as is. You have uncommited changes in /sample-buildout/parts/git-clone. This folder will be left as is.
......
...@@ -64,22 +64,16 @@ class GitCloneNonInformativeTests(unittest.TestCase): ...@@ -64,22 +64,16 @@ class GitCloneNonInformativeTests(unittest.TestCase):
recipe = self.makeGitCloneRecipe({"use-cache": "true", recipe = self.makeGitCloneRecipe({"use-cache": "true",
"repository": BAD_GIT_REPOSITORY}) "repository": BAD_GIT_REPOSITORY})
os.chdir(self.dir) os.chdir(self.dir)
try: with self.assertRaises(zc.buildout.UserError) as cm:
recipe.install() recipe.install()
# Should have raised before. self.assertEqual(str(cm.exception), GIT_CLONE_CACHE_ERROR_MESSAGE)
self.assertTrue(False)
except zc.buildout.UserError as e:
self.assertEqual(e.message, GIT_CLONE_CACHE_ERROR_MESSAGE)
def test_not_using_download_cache_if_forbidden(self): def test_not_using_download_cache_if_forbidden(self):
recipe = self.makeGitCloneRecipe({"repository": BAD_GIT_REPOSITORY}) recipe = self.makeGitCloneRecipe({"repository": BAD_GIT_REPOSITORY})
os.chdir(self.dir) os.chdir(self.dir)
try: with self.assertRaises(zc.buildout.UserError) as cm:
recipe.install() recipe.install()
# Should have raised before. self.assertEqual(str(cm.exception), GIT_CLONE_ERROR_MESSAGE)
self.assertTrue(False)
except zc.buildout.UserError as e:
self.assertEqual(e.message, GIT_CLONE_ERROR_MESSAGE)
def test_cleanup_of_pyc_files(self): def test_cleanup_of_pyc_files(self):
recipe = self.makeGitCloneRecipe({}) recipe = self.makeGitCloneRecipe({})
...@@ -101,9 +95,9 @@ class GitCloneNonInformativeTests(unittest.TestCase): ...@@ -101,9 +95,9 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# Monkey patch check_call # Monkey patch check_call
original_check_call = slapos.recipe.gitclone.check_call original_check_call = slapos.recipe.gitclone.check_call
check_call_paramater_list = [] check_call_parameter_list = []
def patch_check_call(*args, **kw): def patch_check_call(*args, **kw):
check_call_paramater_list.extend([args, kw]) check_call_parameter_list.extend((args, kw))
original_check_call(args[0]) original_check_call(args[0])
slapos.recipe.gitclone.check_call = patch_check_call slapos.recipe.gitclone.check_call = patch_check_call
...@@ -116,19 +110,15 @@ class GitCloneNonInformativeTests(unittest.TestCase): ...@@ -116,19 +110,15 @@ class GitCloneNonInformativeTests(unittest.TestCase):
options = { options = {
'repository': GIT_REPOSITORY, 'repository': GIT_REPOSITORY,
"ignore-ssl-certificate": str(ignore_ssl_certificate).lower(), "ignore-ssl-certificate": str(ignore_ssl_certificate).lower(),
"repository": GIT_REPOSITORY
} }
recipe = slapos.recipe.gitclone.Recipe(bo, 'test', options) recipe = slapos.recipe.gitclone.Recipe(bo, 'test', options)
recipe.install() recipe.install()
# Check git clone parameters # Check git clone parameters
if ignore_ssl_certificate: _ = self.assertIn if ignore_ssl_certificate else self.assertNotIn
self.assertTrue("--config" in check_call_paramater_list[0][0]) _("--config", check_call_parameter_list[0][0])
self.assertTrue("http.sslVerify=false" in check_call_paramater_list[0][0]) _("http.sslVerify=false", check_call_parameter_list[0][0])
else:
self.assertTrue(not "--config" in check_call_paramater_list[0][0])
self.assertTrue(not "http.sslVerify=false" in check_call_paramater_list[0][0])
# Restore original check_call method # Restore original check_call method
slapos.recipe.gitclone.check_call = original_check_call slapos.recipe.gitclone.check_call = original_check_call
......
...@@ -250,16 +250,16 @@ class Signature: ...@@ -250,16 +250,16 @@ class Signature:
return m.hexdigest() return m.hexdigest()
def dumps(self): def dumps(self):
return '\n'.join(self.item_list) return b'\n'.join(self.item_list)
def test(self, folder_path): def test(self, folder_path):
digest = self.hexdigest() digest = self.hexdigest()
if os.path.basename(folder_path) == digest: if os.path.basename(folder_path).encode('utf-8') == digest:
target_path = os.path.join(folder_path, self.filename) target_path = os.path.join(folder_path, self.filename)
if os.path.exists(target_path) and open(target_path).read() == self.dumps(): if os.path.exists(target_path) and open(target_path, 'rb').read() == self.dumps():
return True return True
return False return False
def save(self, folder_path): def save(self, folder_path):
with open(os.path.join(folder_path, self.filename), 'w') as f: with open(os.path.join(folder_path, self.filename), 'wb') as f:
f.write(self.dumps()) f.write(self.dumps())
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