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
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
Hide 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 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
errno
import
logging
import
os
from
platform
import
uname
...
...
@@ -121,6 +122,14 @@ def guessOperatingSystem():
assert
target
,
'Unknown architecture'
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'
)
class
Script
:
...
...
@@ -189,14 +198,14 @@ class Script:
hash_name
=
True
,
cache
=
self
.
buildout
[
'buildout'
].
get
(
'download-cache'
))
path
,
is_temp
=
download
(
url
,
md5sum
=
md5sum
)
if
is_temp
:
self
.
cleanup_
file_
list
.
append
(
path
)
self
.
cleanup_list
.
append
(
path
)
return
path
def
extract
(
self
,
path
):
extract_dir
=
tempfile
.
mkdtemp
(
self
.
name
)
self
.
logger
.
debug
(
'Created working directory %r'
%
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
def
pipeCommand
(
self
,
command_list_list
,
*
args
,
**
kwargs
):
...
...
@@ -252,11 +261,12 @@ class Script:
raise
error
return
True
cleanup_dir_list
=
cleanup_file_list
=
property
(
lambda
self
:
self
.
cleanup_list
)
script
=
'raise NotImplementedError'
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
cleanup_dir_list
=
[]
self
.
cleanup_file_list
=
[]
self
.
cleanup_list
=
[]
self
.
options
=
options
self
.
buildout
=
buildout
self
.
name
=
name
...
...
@@ -308,36 +318,26 @@ class Script:
return
env
def
install
(
self
):
location
=
self
.
options
[
'location'
]
if
os
.
path
.
lexists
(
location
):
self
.
logger
.
warning
(
'Removing already existing path %r'
,
location
)
rmtree
(
location
)
env
=
self
.
getEnvironment
()
# env is used in script exec'ed below
try
:
if
os
.
path
.
exists
(
self
.
options
[
'location'
]):
self
.
cleanup_dir_list
.
append
(
self
.
options
[
'location'
])
raise
shutil
.
Error
(
'Directory %s already exists'
%
self
.
options
[
'location'
])
env
=
self
.
getEnvironment
()
# env is used in script exec'ed below
exec
self
.
options
[
'script'
]
try
:
self
.
_checkPromise
(
'slapos_promise'
,
self
.
options
[
'location'
])
except
Exception
:
if
os
.
path
.
exists
(
self
.
options
[
'location'
]):
self
.
cleanup_dir_list
.
append
(
self
.
options
[
'location'
])
raise
self
.
_checkPromise
(
'slapos_promise'
,
location
)
except
:
self
.
cleanup_list
.
append
(
location
)
raise
finally
:
for
d
in
self
.
cleanup_dir_list
:
if
os
.
path
.
exists
(
d
):
if
not
self
.
keep_on_error
:
self
.
logger
.
debug
(
'Cleanup directory %r'
%
d
)
shutil
.
rmtree
(
d
)
for
path
in
self
.
cleanup_list
:
if
os
.
path
.
lexists
(
path
):
if
self
.
keep_on_error
:
self
.
logger
.
info
(
'Left %r as requested'
,
path
)
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
:
self
.
logger
.
info
(
'Left file %r as requested'
%
f
)
return
[
self
.
options
[
'location'
]]
self
.
logger
.
debug
(
'Removing %r'
,
path
)
rmtree
(
path
)
return
[
location
]
def
update
(
self
):
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