Commit 92dfe439 authored by Xiaowu Zhang's avatar Xiaowu Zhang

downliadunpacked: add shared feature

parent b0a8d3fd
...@@ -32,6 +32,7 @@ import tarfile ...@@ -32,6 +32,7 @@ import tarfile
import zc.buildout import zc.buildout
import tempfile import tempfile
import setuptools.archive_util import setuptools.archive_util
from hashlib import md5
is_true = ('false', 'true').index is_true = ('false', 'true').index
...@@ -47,13 +48,34 @@ class Recipe: ...@@ -47,13 +48,34 @@ class Recipe:
'exclusive.') 'exclusive.')
self.parts = None self.parts = None
self.destination = self.options.get('destination', None) self.destination = self.options.get('destination', None)
self.shared = shared = options.get('shared', '')
if self.destination is None: if self.destination is None:
self.parts = os.path.join(self.buildout['buildout']['parts-directory'], if shared:
self.name) shared_part = buildout['buildout'].get('shared-part', None)
if not shared_part:
raise ValueError(
" Set ${buildout:shared-part} for shared feature")
shared = os.path.join(shared_part.strip().rstrip('/'), name)
if not os.path.exists(shared):
os.makedirs(shared)
self._debug_signature_text = []
m = md5()
profile_base_location = options.get('_profile_base_location_', '')
for k, v in sorted(options.items()):
if profile_base_location:
v = v.replace(profile_base_location, '${:_profile_base_location_}')
option_signature = ('%r: %r' % (k, v)).encode()
self._debug_signature_text.append(option_signature)
m.update(option_signature)
shared = os.path.join(shared, m.hexdigest())
self.parts = shared
self.logger.info('shared directory %s set for %s' % (shared, name))
else:
self.parts = os.path.join(self.buildout['buildout']['parts-directory'],
self.name)
self.destination = self.parts self.destination = self.parts
# backward compatibility with other recipes -- expose location # backward compatibility with other recipes -- expose location
options['location'] = os.path.join(self.buildout['buildout'][ options['location'] = self.parts
'parts-directory'], self.name)
options['target'] = self.destination options['target'] = self.destination
options.setdefault('extract-directory', '') options.setdefault('extract-directory', '')
...@@ -76,6 +98,11 @@ class Recipe: ...@@ -76,6 +98,11 @@ class Recipe:
self.environ[key] = self.environ[key] % os.environ self.environ[key] = self.environ[key] % os.environ
def install(self): def install(self):
if self.shared:
self.logger.info('Checking whether package is installed at shared path : %s' % self.destination)
if os.path.exists(self.destination):
self.logger.info('This shared package has been installed by other package')
return []
if self.parts is not None: if self.parts is not None:
if not os.path.isdir(self.parts): if not os.path.isdir(self.parts):
os.mkdir(self.parts) os.mkdir(self.parts)
...@@ -132,6 +159,10 @@ class Recipe: ...@@ -132,6 +159,10 @@ class Recipe:
shutil.rmtree(extract_dir) shutil.rmtree(extract_dir)
self.logger.debug('Downloaded %r and saved to %r.', self.logger.debug('Downloaded %r and saved to %r.',
self.options['url'], self.destination) self.options['url'], self.destination)
if self.shared:
with open(os.path.join(self.parts, ".slapos.recipe.build.signature"), 'w') as f:
f.write('\n'.join(self._debug_signature_text))
if self.parts is not None: if self.parts is not None:
return [self.parts] return [self.parts]
else: else:
......
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