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
Xavier Thompson
slapos.recipe.build
Commits
d5f5d399
Commit
d5f5d399
authored
May 29, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make 'download-unpacked' compatible with Python 2.6
parent
3ffdd641
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
61 deletions
+49
-61
slapos/recipe/__init__.py
slapos/recipe/__init__.py
+2
-2
slapos/recipe/downloadunpacked.py
slapos/recipe/downloadunpacked.py
+47
-59
No files found.
slapos/recipe/__init__.py
View file @
d5f5d399
...
@@ -44,8 +44,8 @@ class EnvironMixin:
...
@@ -44,8 +44,8 @@ class EnvironMixin:
raise
zc
.
buildout
.
UserError
(
'Key %r is repeated'
%
k
)
raise
zc
.
buildout
.
UserError
(
'Key %r is repeated'
%
k
)
env
[
k
]
=
v
.
strip
()
%
environ
env
[
k
]
=
v
.
strip
()
%
environ
else
:
else
:
self
.
_environ
=
{
k
:
v
.
strip
()
%
environ
self
.
_environ
=
dict
((
k
,
v
.
strip
()
%
environ
)
for
k
,
v
in
self
.
buildout
[
environment
].
iteritems
()
}
for
k
,
v
in
self
.
buildout
[
environment
].
iteritems
()
)
else
:
else
:
self
.
_environ
=
None
if
allow_none
else
{}
self
.
_environ
=
None
if
allow_none
else
{}
...
...
slapos/recipe/downloadunpacked.py
View file @
d5f5d399
...
@@ -33,24 +33,10 @@ import zc.buildout
...
@@ -33,24 +33,10 @@ import zc.buildout
import
tempfile
import
tempfile
import
setuptools
import
setuptools
TRUE_VALUES
=
(
'yes'
,
'true'
,
'1'
,
'on'
)
is_true
=
(
'false'
,
'true'
).
index
class
Recipe
:
class
Recipe
:
def
calculate_base
(
self
,
extract_dir
):
log
=
logging
.
getLogger
(
self
.
name
)
# Move the contents of the package in to the correct destination
top_level_contents
=
os
.
listdir
(
extract_dir
)
if
self
.
options
[
'strip-top-level-dir'
].
strip
().
lower
()
in
TRUE_VALUES
:
if
len
(
top_level_contents
)
!=
1
:
log
.
error
(
'Unable to strip top level directory because there are more '
'than one element in the root of the package.'
)
raise
zc
.
buildout
.
UserError
(
'Invalid package contents'
)
base
=
os
.
path
.
join
(
extract_dir
,
top_level_contents
[
0
])
else
:
base
=
extract_dir
return
base
def
__init__
(
self
,
buildout
,
name
,
options
):
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
buildout
=
buildout
self
.
buildout
=
buildout
self
.
name
=
name
self
.
name
=
name
...
@@ -93,57 +79,59 @@ class Recipe:
...
@@ -93,57 +79,59 @@ class Recipe:
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
)
download
=
zc
.
buildout
.
download
.
Download
(
self
.
buildout
[
'buildout'
],
download
=
zc
.
buildout
.
download
.
Download
(
self
.
buildout
[
'buildout'
],
hash_name
=
True
,
cache
=
self
.
buildout
[
'buildout'
].
get
(
'download-cache'
))
hash_name
=
True
,
cache
=
self
.
buildout
[
'buildout'
].
get
(
'download-cache'
))
path
,
is_temp
=
download
(
self
.
options
[
'url'
],
md5sum
=
self
.
options
.
get
(
'md5sum'
))
extract_dir
=
tempfile
.
mkdtemp
(
self
.
name
)
extract_dir
=
tempfile
.
mkdtemp
(
self
.
name
)
self
.
logger
.
debug
(
'Created working directory %r'
%
extract_dir
)
try
:
try
:
patch_archive_util
()
self
.
logger
.
debug
(
'Created working directory %r'
,
extract_dir
)
# ad-hoc support for .xz and .lz archive
path
,
is_temp
=
download
(
self
.
options
[
'url'
],
hdr
=
file
(
path
).
read
(
6
)
md5sum
=
self
.
options
.
get
(
'md5sum'
))
if
hdr
==
'
\
xfd
7zXZ
\
x00
'
:
try
:
new_path
=
os
.
path
.
join
(
extract_dir
,
os
.
path
.
basename
(
path
))
patch_archive_util
()
file
(
new_path
,
'w'
).
write
(
subprocess
.
check_output
([
'xzcat'
,
path
],
env
=
self
.
environ
))
# ad-hoc support for .xz and .lz archive
setuptools
.
archive_util
.
unpack_archive
(
new_path
,
extract_dir
)
hdr
=
open
(
path
,
'rb'
).
read
(
6
)
os
.
unlink
(
new_path
)
for
magic
,
cmd
in
((
'
\
xfd
7zXZ
\
x00
'
,
(
'xzcat'
,)),
elif
hdr
.
startswith
(
'LZIP'
):
(
'LZIP'
,
(
'lunzip'
,
'-c'
))):
new_path
=
os
.
path
.
join
(
extract_dir
,
os
.
path
.
basename
(
path
))
if
hdr
.
startswith
(
magic
):
file
(
new_path
,
'w'
).
write
(
subprocess
.
check_output
([
'lunzip'
,
'-c'
,
path
],
env
=
self
.
environ
))
new_path
=
os
.
path
.
join
(
extract_dir
,
os
.
path
.
basename
(
path
))
setuptools
.
archive_util
.
unpack_archive
(
new_path
,
extract_dir
)
with
open
(
new_path
,
'wb'
)
as
stdout
:
os
.
unlink
(
new_path
)
subprocess
.
check_call
(
cmd
+
(
path
,),
else
:
stdout
=
stdout
,
env
=
self
.
environ
)
setuptools
.
archive_util
.
unpack_archive
(
path
,
extract_dir
)
setuptools
.
archive_util
.
unpack_archive
(
new_path
,
extract_dir
)
finally
:
os
.
unlink
(
new_path
)
unpatch_archive_util
()
break
if
is_temp
:
else
:
os
.
unlink
(
path
)
setuptools
.
archive_util
.
unpack_archive
(
path
,
extract_dir
)
finally
:
unpatch_archive_util
()
if
is_temp
:
os
.
unlink
(
path
)
# Delete destination directory if exist
if
os
.
path
.
exists
(
self
.
destination
):
if
os
.
path
.
exists
(
self
.
destination
):
shutil
.
rmtree
(
self
.
destination
)
shutil
.
rmtree
(
self
.
destination
)
# Create destination directory
if
not
os
.
path
.
isdir
(
self
.
destination
):
os
.
makedirs
(
self
.
destination
)
os
.
makedirs
(
self
.
destination
)
base_dir
=
extract_dir
strip
=
self
.
options
.
get
(
'strip-top-level-dir'
)
if
not
self
.
options
.
has_key
(
'strip-top-level-dir'
):
if
strip
:
directories
=
os
.
listdir
(
extract_dir
)
if
is_true
(
strip
.
lower
()):
if
len
(
directories
)
==
1
and
os
.
path
.
isdir
(
os
.
path
.
join
(
extract_dir
,
directories
[
0
])):
base_dir
,
=
os
.
listdir
(
extract_dir
)
base_dir
=
os
.
path
.
join
(
extract_dir
,
directories
[
0
])
base_dir
=
os
.
path
.
join
(
extract_dir
,
base_dir
)
else
:
else
:
base_dir
=
self
.
calculate_base
(
extract_dir
)
base_dir
=
extract_dir
extract_dir
=
os
.
path
.
join
(
base_dir
,
self
.
options
[
'extract-directory'
])
else
:
for
filename
in
os
.
listdir
(
extract_dir
):
directories
=
os
.
listdir
(
extract_dir
)
dest
=
os
.
path
.
join
(
self
.
destination
,
filename
)
if
len
(
directories
)
==
1
:
shutil
.
move
(
os
.
path
.
join
(
extract_dir
,
filename
),
dest
)
base_dir
=
os
.
path
.
join
(
extract_dir
,
directories
[
0
])
if
not
os
.
path
.
isdir
(
base_dir
):
shutil
.
rmtree
(
extract_dir
)
base_dir
=
extract_dir
self
.
logger
.
debug
(
'Downloaded %r and saved to %r.'
%
(
self
.
options
[
'url'
],
base_dir
=
os
.
path
.
join
(
base_dir
,
self
.
options
[
'extract-directory'
])
self
.
destination
))
for
filename
in
os
.
listdir
(
base_dir
):
shutil
.
move
(
os
.
path
.
join
(
base_dir
,
filename
),
self
.
destination
)
finally
:
shutil
.
rmtree
(
extract_dir
)
self
.
logger
.
debug
(
'Downloaded %r and saved to %r.'
,
self
.
options
[
'url'
],
self
.
destination
)
if
self
.
parts
is
not
None
:
if
self
.
parts
is
not
None
:
return
[
self
.
parts
]
return
[
self
.
parts
]
else
:
else
:
...
...
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