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
Jérome Perrin
slapos.recipe.build
Commits
49e5b835
Commit
49e5b835
authored
Oct 10, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build: review of file/dir removal
parent
053815eb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
30 deletions
+30
-30
slapos/recipe/build/__init__.py
slapos/recipe/build/__init__.py
+30
-30
No files found.
slapos/recipe/build/__init__.py
View file @
49e5b835
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
##############################################################################
##############################################################################
import
errno
import
logging
import
logging
import
os
import
os
from
platform
import
uname
from
platform
import
uname
...
@@ -121,6 +122,14 @@ def guessOperatingSystem():
...
@@ -121,6 +122,14 @@ def guessOperatingSystem():
assert
target
,
'Unknown architecture'
assert
target
,
'Unknown architecture'
return
target
return
target
def
rmtree
(
path
):
try
:
os
.
remove
(
path
)
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
EISDIR
:
raise
shutil
.
rmtree
(
path
)
TRUE_LIST
=
(
'y'
,
'on'
,
'yes'
,
'true'
,
'1'
)
TRUE_LIST
=
(
'y'
,
'on'
,
'yes'
,
'true'
,
'1'
)
class
Script
:
class
Script
:
...
@@ -189,14 +198,14 @@ class Script:
...
@@ -189,14 +198,14 @@ class Script:
hash_name
=
True
,
cache
=
self
.
buildout
[
'buildout'
].
get
(
'download-cache'
))
hash_name
=
True
,
cache
=
self
.
buildout
[
'buildout'
].
get
(
'download-cache'
))
path
,
is_temp
=
download
(
url
,
md5sum
=
md5sum
)
path
,
is_temp
=
download
(
url
,
md5sum
=
md5sum
)
if
is_temp
:
if
is_temp
:
self
.
cleanup_
file_
list
.
append
(
path
)
self
.
cleanup_list
.
append
(
path
)
return
path
return
path
def
extract
(
self
,
path
):
def
extract
(
self
,
path
):
extract_dir
=
tempfile
.
mkdtemp
(
self
.
name
)
extract_dir
=
tempfile
.
mkdtemp
(
self
.
name
)
self
.
logger
.
debug
(
'Created working directory %r'
%
extract_dir
)
self
.
logger
.
debug
(
'Created working directory %r'
%
extract_dir
)
setuptools
.
archive_util
.
unpack_archive
(
path
,
extract_dir
)
setuptools
.
archive_util
.
unpack_archive
(
path
,
extract_dir
)
self
.
cleanup_
dir_
list
.
append
(
extract_dir
)
self
.
cleanup_list
.
append
(
extract_dir
)
return
extract_dir
return
extract_dir
def
pipeCommand
(
self
,
command_list_list
,
*
args
,
**
kwargs
):
def
pipeCommand
(
self
,
command_list_list
,
*
args
,
**
kwargs
):
...
@@ -252,11 +261,12 @@ class Script:
...
@@ -252,11 +261,12 @@ class Script:
raise
error
raise
error
return
True
return
True
cleanup_dir_list
=
cleanup_file_list
=
property
(
lambda
self
:
self
.
cleanup_list
)
script
=
'raise NotImplementedError'
script
=
'raise NotImplementedError'
def
__init__
(
self
,
buildout
,
name
,
options
):
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
cleanup_dir_list
=
[]
self
.
cleanup_list
=
[]
self
.
cleanup_file_list
=
[]
self
.
options
=
options
self
.
options
=
options
self
.
buildout
=
buildout
self
.
buildout
=
buildout
self
.
name
=
name
self
.
name
=
name
...
@@ -308,36 +318,26 @@ class Script:
...
@@ -308,36 +318,26 @@ class Script:
return
env
return
env
def
install
(
self
):
def
install
(
self
):
try
:
location
=
self
.
options
[
'location'
]
if
os
.
path
.
exists
(
self
.
options
[
'location'
]):
if
os
.
path
.
lexists
(
location
):
self
.
cleanup_dir_list
.
append
(
self
.
options
[
'location'
])
self
.
logger
.
warning
(
'Removing already existing path %r'
,
location
)
raise
shutil
.
Error
(
'Directory %s already exists'
%
rmtree
(
location
)
self
.
options
[
'location'
])
env
=
self
.
getEnvironment
()
# env is used in script exec'ed below
env
=
self
.
getEnvironment
()
# env is used in script exec'ed below
exec
self
.
options
[
'script'
]
try
:
try
:
self
.
_checkPromise
(
'slapos_promise'
,
self
.
options
[
'location'
])
exec
self
.
options
[
'script'
]
except
Exception
:
self
.
_checkPromise
(
'slapos_promise'
,
location
)
if
os
.
path
.
exists
(
self
.
options
[
'location'
])
:
except
:
self
.
cleanup_dir_list
.
append
(
self
.
options
[
'location'
]
)
self
.
cleanup_list
.
append
(
location
)
raise
raise
finally
:
finally
:
for
d
in
self
.
cleanup_dir_list
:
for
path
in
self
.
cleanup_list
:
if
os
.
path
.
exists
(
d
):
if
os
.
path
.
lexists
(
path
):
if
not
self
.
keep_on_error
:
if
self
.
keep_on_error
:
self
.
logger
.
debug
(
'Cleanup directory %r'
%
d
)
self
.
logger
.
info
(
'Left %r as requested'
,
path
)
shutil
.
rmtree
(
d
)
else
:
self
.
logger
.
info
(
'Left directory %r as requested'
%
d
)
for
f
in
self
.
cleanup_file_list
:
if
os
.
path
.
exists
(
f
):
if
not
self
.
keep_on_error
:
self
.
logger
.
debug
(
'Cleanup file %r'
%
f
)
os
.
unlink
(
f
)
else
:
else
:
self
.
logger
.
info
(
'Left file %r as requested'
%
f
)
self
.
logger
.
debug
(
'Removing %r'
,
path
)
rmtree
(
path
)
return
[
self
.
options
[
'location'
]
]
return
[
location
]
def
update
(
self
):
def
update
(
self
):
pass
pass
...
...
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