Commit d27df419 authored by Julien Muchembled's avatar Julien Muchembled

Do not upload to cache by default, nor cache working copy

parent 62416e88
Changes Changes
======= =======
0.12 (Unreleased)
-----------------
* Do not upload to cache by default. 'use-cache' option replaces
'forbid-download-cache' and must be explicitely set in order to use cache.
* Do not cache working copy, which just duplicate `.git` folder.
0.11.6 (2013-02-25) 0.11.6 (2013-02-25)
------------------- -------------------
......
...@@ -57,7 +57,8 @@ slapos.recipe.build:gitclone ...@@ -57,7 +57,8 @@ slapos.recipe.build:gitclone
**************************** ****************************
Checkout a git repository. Checkout a git repository.
Supports slapos.libnetworkcache if present. Supports slapos.libnetworkcache if present, and if boolean 'use-cache' option
is true.
Examples Examples
******** ********
...@@ -78,6 +79,7 @@ the recipe will pick up the latest commit on the remote master branch:: ...@@ -78,6 +79,7 @@ the recipe will pick up the latest commit on the remote master branch::
... [git-clone] ... [git-clone]
... recipe = slapos.recipe.build:gitclone ... recipe = slapos.recipe.build:gitclone
... repository = http://git.erp5.org/repos/slapos.recipe.build.git ... repository = http://git.erp5.org/repos/slapos.recipe.build.git
... use-cache = true
... """) ... """)
This will clone the git repository in `parts/git-clone` directory. This will clone the git repository in `parts/git-clone` directory.
......
from setuptools import setup, find_packages from setuptools import setup, find_packages
version = '0.11.6' version = '0.12-dev'
name = 'slapos.recipe.build' name = 'slapos.recipe.build'
long_description = open("README.rst").read() + "\n" + \ long_description = open("README.rst").read() + "\n" + \
open("CHANGES.txt").read() + "\n" open("CHANGES.txt").read() + "\n"
......
...@@ -51,7 +51,7 @@ except: ...@@ -51,7 +51,7 @@ except:
GIT_DEFAULT_REMOTE_NAME = 'origin' GIT_DEFAULT_REMOTE_NAME = 'origin'
GIT_DEFAULT_BRANCH_NAME = 'master' GIT_DEFAULT_BRANCH_NAME = 'master'
TRUE_VALUES = ['y', 'yes', '1', 'true'] TRUE_VALUES = ('y', 'yes', '1', 'true')
GIT_CLONE_ERROR_MESSAGE = 'Impossible to clone repository.' GIT_CLONE_ERROR_MESSAGE = 'Impossible to clone repository.'
GIT_CLONE_CACHE_ERROR_MESSAGE = 'Impossible to clone repository and ' \ GIT_CLONE_CACHE_ERROR_MESSAGE = 'Impossible to clone repository and ' \
...@@ -62,7 +62,7 @@ def upload_network_cached(path, name, revision, networkcache_options): ...@@ -62,7 +62,7 @@ def upload_network_cached(path, name, revision, networkcache_options):
Creates uploads repository to cache. Creates uploads repository to cache.
""" """
if not (LIBNETWORKCACHE_ENABLED and networkcache_options.get( if not (LIBNETWORKCACHE_ENABLED and networkcache_options.get(
'shacache-cert-file')): 'upload-dir-url')):
return False return False
try: try:
print 'Uploading git repository to cache...' print 'Uploading git repository to cache...'
...@@ -132,12 +132,8 @@ class Recipe(object): ...@@ -132,12 +132,8 @@ class Recipe(object):
self.name = name self.name = name
self.location = options.get('location') self.location = options.get('location')
# Set boolean values # Set boolean values
for key in ['develop', 'forbid-download-cache']: for key in ('develop', 'use-cache'):
attribute = key.replace('-', '_') setattr(self, key.replace('-', '_'), options.get(key) in TRUE_VALUES)
if options.get(key) in TRUE_VALUES:
setattr(self, attribute, True)
else:
setattr(self, attribute, False)
self.networkcache = buildout.get('networkcache', {}) self.networkcache = buildout.get('networkcache', {})
...@@ -182,18 +178,21 @@ class Recipe(object): ...@@ -182,18 +178,21 @@ class Recipe(object):
raise UserError("Unknown error while cloning repository.") raise UserError("Unknown error while cloning repository.")
if self.revision: if self.revision:
self.gitReset(self.revision) self.gitReset(self.revision)
upload_network_cached(self.location, self.name, self.revision, if self.use_cache:
self.networkcache) upload_network_cached(os.path.join(self.location, '.git'),
self.repository, self.revision, self.networkcache)
except CalledProcessError: except CalledProcessError:
print ("Unable to download from git repository. Trying from network " print ("Unable to download from git repository. Trying from network "
"cache...") "cache...")
if os.path.exists(self.location): if os.path.exists(self.location):
shutil.rmtree(self.location) shutil.rmtree(self.location)
if self.forbid_download_cache: if not self.use_cache:
raise UserError(GIT_CLONE_ERROR_MESSAGE) raise UserError(GIT_CLONE_ERROR_MESSAGE)
if not download_network_cached(self.location, self.name, self.revision, os.mkdir(self.location)
self.networkcache): if not download_network_cached(os.path.join(self.location, '.git'),
self.repository, self.revision, self.networkcache):
raise UserError(GIT_CLONE_CACHE_ERROR_MESSAGE) raise UserError(GIT_CLONE_CACHE_ERROR_MESSAGE)
self.gitReset()
return [self.location] return [self.location]
......
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