Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.build
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Leymonerie
slapos.recipe.build
Commits
e01e634a
Commit
e01e634a
authored
Jan 12, 2022
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
download*: new 'offline' option to override ${buildout:offline}
parent
c4362bb8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
14 deletions
+68
-14
README.rst
README.rst
+6
-0
slapos/recipe/build/__init__.py
slapos/recipe/build/__init__.py
+3
-1
slapos/recipe/build/tests.py
slapos/recipe/build/tests.py
+46
-6
slapos/recipe/download.py
slapos/recipe/download.py
+8
-4
slapos/recipe/downloadunpacked.py
slapos/recipe/downloadunpacked.py
+5
-3
No files found.
README.rst
View file @
e01e634a
...
...
@@ -342,6 +342,12 @@ In case of checksum mismatch::
Error: MD5 checksum mismatch downloading '...'
>>> ls('parts')
option: offline
---------------
Boolean option that can be specified to override `${buildout:offline}`.
option: alternate-url
---------------------
...
...
slapos/recipe/build/__init__.py
View file @
e01e634a
...
...
@@ -145,8 +145,10 @@ class Script(EnvironMixin):
def
download
(
self
,
*
args
,
**
kw
):
if
not
(
args
or
'url'
in
kw
):
args
=
self
.
options
[
'url'
],
self
.
options
.
get
(
'md5sum'
)
or
None
offline
=
kw
.
pop
(
'offline'
,
None
)
path
,
is_temp
=
zc
.
buildout
.
download
.
Download
(
self
.
buildout
[
'buildout'
],
hash_name
=
True
)(
*
args
,
**
kw
)
hash_name
=
True
,
**
({}
if
offline
is
None
else
{
'offline'
:
offline
})
)(
*
args
,
**
kw
)
if
is_temp
:
self
.
cleanup_list
.
append
(
path
)
return
path
...
...
slapos/recipe/build/tests.py
View file @
e01e634a
import
doctest
from
zope.testing
import
renormalizing
import
os
import
re
import
shutil
import
tarfile
import
tempfile
import
unittest
import
zc.buildout.testing
from
zc.buildout.download
import
check_md5sum
,
ChecksumError
from
zc.buildout.testing
import
buildoutTearDown
from
contextlib
import
contextmanager
from
copy
import
deepcopy
from
functools
import
wraps
from
subprocess
import
check_call
,
check_output
,
CalledProcessError
,
STDOUT
from
..
import
download
,
gitclone
,
make_read_only_recursively
import
zc.buildout.testing
from
zc.buildout.download
import
check_md5sum
,
ChecksumError
from
zc.buildout.testing
import
buildoutTearDown
from
zope.testing
import
renormalizing
from
..
import
download
,
downloadunpacked
,
gitclone
,
make_read_only_recursively
optionflags
=
(
doctest
.
ELLIPSIS
|
doctest
.
NORMALIZE_WHITESPACE
)
...
...
@@ -99,6 +102,43 @@ class DownloadTests(TestCase):
self
.
assertRaises
(
ChecksumError
,
download
.
Recipe
(
self
.
buildout
,
'fail'
,
options
).
install
)
@
with_buildout
def
test_offline
(
self
,
write
,
start_server
,
**
kw
):
data
=
'bar'
foo
=
os
.
path
.
join
(
self
.
dir
,
'foo'
)
write
(
foo
,
data
)
url
=
start_server
(
self
.
dir
)
+
'foo'
def
check
(
Recipe
,
target
):
def
check
(
offline_error
,
buildout_offline
=
None
,
options_offline
=
None
):
buildout
=
deepcopy
(
self
.
buildout
)
if
buildout_offline
:
buildout
[
'buildout'
][
'offline'
]
=
buildout_offline
options
=
{
'url'
:
url
}
if
options_offline
:
options
[
'offline'
]
=
options_offline
try
:
Recipe
(
buildout
,
'offline'
,
options
).
install
()
except
zc
.
buildout
.
UserError
:
if
not
offline_error
:
raise
else
:
self
.
assertFalse
(
offline_error
)
with
open
(
target
(
options
))
as
f
:
self
.
assertEqual
(
f
.
read
(),
data
)
check
(
False
)
check
(
False
,
'false'
)
check
(
True
,
'true'
)
check
(
False
,
None
,
'false'
)
check
(
True
,
None
,
'true'
)
check
(
False
,
'true'
,
'false'
)
check
(
True
,
'false'
,
'true'
)
check
(
download
.
Recipe
,
lambda
options
:
options
[
'target'
])
with
tarfile
.
open
(
os
.
path
.
join
(
foo
+
'.tar'
),
'w'
)
as
tar
:
tar
.
add
(
foo
,
'foo'
)
url
+=
'.tar'
check
(
downloadunpacked
.
Recipe
,
lambda
options
:
os
.
path
.
join
(
options
[
'target'
],
'foo'
))
class
GitCloneNonInformativeTests
(
TestCase
):
...
...
slapos/recipe/download.py
View file @
e01e634a
...
...
@@ -27,7 +27,7 @@
import
errno
import
os
from
zc.buildout
import
download
,
UserError
from
.
import
Shared
from
.
import
is_true
,
Shared
class
Recipe
(
object
):
...
...
@@ -38,6 +38,8 @@ class Recipe(object):
self
.
_url
=
options
[
'url'
]
self
.
_alternate
=
options
.
get
(
'alternate-url'
)
self
.
_md5sum
=
options
.
get
(
'md5sum'
)
or
None
offline
=
options
.
get
(
'offline'
)
self
.
_offline
=
is_true
(
offline
)
if
offline
else
None
# 'mode' option was dropped; don't reimplement it
# an 'executable' boolean option may be acceptable
if
'mode'
in
options
:
...
...
@@ -75,10 +77,12 @@ class Recipe(object):
return
[
destination
]
def
_download
(
self
):
offline
=
self
.
_offline
kw
=
{}
if
offline
is
None
else
{
'offline'
:
offline
}
dl
=
download
.
Download
(
self
.
_buildout
,
hash_name
=
True
,
**
kw
)
alternate
=
self
.
_alternate
path
,
is_temp
=
download
.
Download
(
self
.
_buildout
,
hash_name
=
True
)(
self
.
_url
,
self
.
_md5sum
,
self
.
_destination
,
**
({
'alternate_url'
:
alternate
}
if
alternate
else
{}))
kw
=
{
'alternate_url'
:
alternate
}
if
alternate
else
{}
path
,
is_temp
=
dl
(
self
.
_url
,
self
.
_md5sum
,
self
.
_destination
,
**
kw
)
assert
path
==
self
.
_destination
and
not
is_temp
,
(
"SlapOS buildout >= 2.7.1+slapos014 needed"
)
...
...
slapos/recipe/downloadunpacked.py
View file @
e01e634a
...
...
@@ -61,10 +61,12 @@ class Recipe(EnvironMixin):
# inside slapos.buildout (see networkcache support)
from
zc.buildout
import
download
location
=
self
.
_shared
.
location
offline
=
self
.
options
.
get
(
'offline'
)
kw
=
{
'offline'
:
is_true
(
offline
)}
if
offline
else
{}
dl
=
download
.
Download
(
self
.
buildout
[
'buildout'
],
hash_name
=
True
,
**
kw
)
alternate
=
self
.
options
.
get
(
'alternate-url'
)
path
,
is_temp
=
download
.
Download
(
self
.
buildout
[
'buildout'
],
hash_name
=
True
)(
self
.
_url
,
self
.
options
.
get
(
'md5sum'
)
or
None
,
**
({
'alternate_url'
:
alternate
}
if
alternate
else
{}))
kw
=
{
'alternate_url'
:
alternate
}
if
alternate
else
{}
path
,
is_temp
=
dl
(
self
.
_url
,
self
.
options
.
get
(
'md5sum'
)
or
None
,
**
kw
)
try
:
unpack_archive
(
self
,
path
,
location
)
finally
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment