Commit 8c99c1ac authored by Jondy Zhao's avatar Jondy Zhao Committed by Cédric de Saint Martin

Add option 'share'.

parent 55575006
...@@ -26,6 +26,21 @@ Supported options ...@@ -26,6 +26,21 @@ Supported options
``--prefix`` injection takes place. You can also set the ``--prefix`` ``--prefix`` injection takes place. You can also set the ``--prefix``
parameter explicitly in ``configure-options``. parameter explicitly in ``configure-options``.
``share``
Specify the path in which this package is shared by many other
packages. When it's unset or blank, it means the package isn't
shared. Otherwise, it shared by many packages. Recipe will return
an empty list so that buildout will not uninstall the package when
uninstalling part.
In share mode, ``promises`` should be set so that recipe can tell
whether the package is installed. Otherwise nohting to do.
This option is experiment now. Recipe doesn't try to set prefix
with the valule of this opton in the configure or make command,
you should specify them accordingly by yourself.
``md5sum`` ``md5sum``
MD5 checksum for the package file. If available the MD5 MD5 checksum for the package file. If available the MD5
...@@ -1062,6 +1077,53 @@ Look, "package" is reinstalled either: ...@@ -1062,6 +1077,53 @@ Look, "package" is reinstalled either:
building package building package
installing package installing package
Install share package
=====================
Use option ``share`` to install a share pacakge.
>>> write('buildout.cfg',
... """
... [buildout]
... newest = false
... parts = package
...
... [package]
... recipe = slapos.recipe.cmmi
... url = file://%s/package-0.0.0.tar.gz
... share = /usr/local/bin
... promises = ${:share}/mypackage.exe
... """ % (src,))
>>> print system(buildout)
Uninstalling package.
Uninstalling package-2.
Installing package.
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: Extracting package to /sample_buildout/parts/package__compile__
configure --prefix=/sample_buildout/parts/package
building package
installing package
package: could not find promise "/usr/local/bin/mypackage.exe"
Do nothing if one package has been installed.
>>> write('buildout.cfg',
... """
... [buildout]
... newest = false
... parts = package
...
... [package]
... recipe = slapos.recipe.cmmi
... url = file://%s/package-0.0.0.tar.gz
... share = /usr/local/bin
... promises =
... """ % (src,))
>>> print system(buildout)
Uninstalling package.
Installing package.
package: This shared package has been installed by other package
For even more specific needs you can write your own recipe that uses For even more specific needs you can write your own recipe that uses
``slapos.recipe.cmmi`` and set the ``keep-compile-dir`` option to ``true``. ``slapos.recipe.cmmi`` and set the ``keep-compile-dir`` option to ``true``.
You can then continue from where this recipe finished by reading the location You can then continue from where this recipe finished by reading the location
......
...@@ -44,7 +44,8 @@ class Recipe(object): ...@@ -44,7 +44,8 @@ class Recipe(object):
options['url'] = options.get('url', '').strip() options['url'] = options.get('url', '').strip()
options['path'] = options.get('path', '').strip() options['path'] = options.get('path', '').strip()
options['promises'] = options.get('promises', '') options['promises'] = options.get('promises', '')
options['share'] = options.get('share', '').strip()
# Check dependencies, all the dependent parts will be installed first. It # Check dependencies, all the dependent parts will be installed first. It
# seems once part is referenced, for example, self.buildout[part], it will # seems once part is referenced, for example, self.buildout[part], it will
# be appended as an install part. # be appended as an install part.
...@@ -181,13 +182,13 @@ class Recipe(object): ...@@ -181,13 +182,13 @@ class Recipe(object):
raise zc.buildout.UserError('System error') raise zc.buildout.UserError('System error')
return files.split() return files.split()
def check_promises(self): def check_promises(self, log=None):
result = True result = True
log = logging.getLogger(self.name)
for path in self.options['promises'].splitlines(): for path in self.options['promises'].splitlines():
if not os.path.exists(path): if not os.path.exists(path):
result = False result = False
log.warning('could not find promise "%s"' % path) if log is not None:
log.warning('could not find promise "%s"' % path)
return result return result
def call_script(self, script): def call_script(self, script):
...@@ -232,6 +233,11 @@ class Recipe(object): ...@@ -232,6 +233,11 @@ class Recipe(object):
log = logging.getLogger(self.name) log = logging.getLogger(self.name)
parts = [] parts = []
# In share mode, do nothing if package has been installed.
if (not self.options['share'] == '') and self.check_promises():
log.info('This shared package has been installed by other package')
return parts
make_cmd = self.options.get('make-binary', 'make').strip() make_cmd = self.options.get('make-binary', 'make').strip()
make_options = ' '.join(self.options.get('make-options', '').split()) make_options = ' '.join(self.options.get('make-options', '').split())
make_targets = ' '.join(self.options.get('make-targets', 'install').split()) make_targets = ' '.join(self.options.get('make-targets', 'install').split())
...@@ -341,7 +347,9 @@ class Recipe(object): ...@@ -341,7 +347,9 @@ class Recipe(object):
if post_install_cmd != '': if post_install_cmd != '':
log.info('Executing post-install') log.info('Executing post-install')
self.run(post_install_cmd) self.run(post_install_cmd)
if self.buildout_prefix != '' and os.path.exists(self.buildout_prefix): if (self.buildout_prefix != ''
and self.options['share'] == ''
and os.path.exists(self.buildout_prefix)):
log.info('Getting installed file lists') log.info('Getting installed file lists')
parts.extend(self.get_installed_files(tmp_path)) parts.extend(self.get_installed_files(tmp_path))
except: except:
...@@ -353,7 +361,7 @@ class Recipe(object): ...@@ -353,7 +361,7 @@ class Recipe(object):
shutil.rmtree(tmp_path) shutil.rmtree(tmp_path)
# Check promises # Check promises
self.check_promises() self.check_promises(log)
if self.options['url']: if self.options['url']:
if self.options.get('keep-compile-dir', if self.options.get('keep-compile-dir',
...@@ -366,5 +374,6 @@ class Recipe(object): ...@@ -366,5 +374,6 @@ class Recipe(object):
shutil.rmtree(compile_dir) shutil.rmtree(compile_dir)
del self.options['compile-directory'] del self.options['compile-directory']
parts.append(self.options['location']) if self.options['share'] == '':
parts.append(self.options['location'])
return parts return parts
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