Commit 6ed49af2 authored by Łukasz Nowak's avatar Łukasz Nowak

Move slapos.recipe.download functionality.

slapos.cookbook provided it before, but it is simple functionality, which does
not need so many dependencies.
parent a7f95f7e
...@@ -109,3 +109,36 @@ can be used as:: ...@@ -109,3 +109,36 @@ can be used as::
Which will link ${file:location}/bin/file to ${buildout:bin-directory}/bin/file Which will link ${file:location}/bin/file to ${buildout:bin-directory}/bin/file
and ${file:location}/bin/file to ${buildout:bin-directory}/bin/anotherfile and ${file:location}/bin/file to ${buildout:bin-directory}/bin/anotherfile
Pure download
-------------
::
[buildout]
parts =
download
[download]
recipe = slapos.recipe.build:download
url = https://some.url/file
Such profile will download https://some.url/file and put it in
buildout:parts-directory/download/download
filename parameter can be used to change destination named filename.
destination parameter allows to put explicit destination.
md5sum parameter allows pass md5sum.
mode (octal, so for rw-r--r-- use 0644) allows to set mode
Exposes target attribute which is path to downloaded file.
Notes
-----
This recipe suffers from buildout download utility issue, which will do not
try to redownload resource with wrong md5sum.
...@@ -29,6 +29,7 @@ setup(name=name, ...@@ -29,6 +29,7 @@ setup(name=name,
entry_points={ entry_points={
'zc.buildout': [ 'zc.buildout': [
'default = slapos.recipe.build:Script', 'default = slapos.recipe.build:Script',
'cmmi = slapos.recipe.build:Cmmi' 'cmmi = slapos.recipe.build:Cmmi',
'download = slapos.recipe.download:Recipe'
]}, ]},
) )
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import os
import logging
import shutil
import zc.buildout
class Recipe:
def __init__(self, buildout, name, options):
self.buildout = buildout
self.name = name
self.options = options
self.logger = logging.getLogger(self.name)
if 'filename' in self.options and 'destination' in self.options:
raise zc.buildout.UserError('Parameters filename and destination are '
'exclusive.')
self.parts = None
self.destination = self.options.get('destination', None)
if self.destination is None:
self.parts = os.path.join(self.buildout['buildout']['parts-directory'],
self.name)
self.destination = os.path.join(self.parts, self.options.get('filename',
self.name))
options['target'] = self.destination
def install(self):
if self.parts is not None:
if not os.path.isdir(self.parts):
os.mkdir(self.parts)
download = zc.buildout.download.Download(self.buildout['buildout'],
hash_name=True, cache=self.buildout['buildout'].get('download-cache'))
path, is_temp = download(self.options['url'],
md5sum=self.options.get('md5sum'))
if os.path.exists(self.destination):
os.unlink(self.destination)
shutil.copy(path, self.destination)
mode = self.options.get('mode')
if mode is not None:
mode = int(mode, 8)
os.chmod(self.destination, mode)
self.logger.debug('Mode of %r set to 0%o.' % (self.destination, mode))
self.logger.debug('Downloaded %r and saved to %r.' % (self.options['url'],
self.destination))
if self.parts is not None:
return [self.parts]
else:
return []
update = install
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