summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-03-03 09:18:47 +0100
committeralalazo <massimiliano.culpo@googlemail.com>2016-03-03 09:18:47 +0100
commit353d12d2e6e24c0f62795dd9e649a801b566c4d8 (patch)
tree752fd22287b48eb8353be72f8baad7e5b01c6b83 /lib
parent717bcb862428a1b1a3b9c70f925c3fe6c325f622 (diff)
downloadspack-353d12d2e6e24c0f62795dd9e649a801b566c4d8.tar.gz
spack-353d12d2e6e24c0f62795dd9e649a801b566c4d8.tar.bz2
spack-353d12d2e6e24c0f62795dd9e649a801b566c4d8.tar.xz
spack-353d12d2e6e24c0f62795dd9e649a801b566c4d8.zip
stage : added create function as decided in #477 comments
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/stage.py50
1 files changed, 30 insertions, 20 deletions
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index e87b822a8f..5d8b09fa9e 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -105,26 +105,10 @@ class Stage(object):
"""
Entering a stage context will create the stage directory
- If self.tmp_root evaluates to False, the stage directory is created directly under spack.stage_path, otherwise
- this will attempt to create a stage in a temporary directory and link it into spack.stage_path.
-
- Spack will use the first writable location in spack.tmp_dirs to create a stage. If there is no valid location
- in tmp_dirs, fall back to making the stage inside spack.stage_path.
+ Returns:
+ self
"""
- # Create the top-level stage directory
- mkdirp(spack.stage_path)
- remove_dead_links(spack.stage_path)
- # If a tmp_root exists then create a directory there and then link it in the stage area,
- # otherwise create the stage directory in self.path
- if self._need_to_create_path():
- if self.tmp_root:
- tmp_dir = tempfile.mkdtemp('', STAGE_PREFIX, self.tmp_root)
- os.symlink(tmp_dir, self.path)
- else:
- mkdirp(self.path)
- # Make sure we can actually do something with the stage we made.
- ensure_access(self.path)
-
+ self.create()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
@@ -314,8 +298,34 @@ class Stage(object):
"""
self.fetcher.reset()
+ def create(self):
+ """
+ Creates the stage directory
+
+ If self.tmp_root evaluates to False, the stage directory is created directly under spack.stage_path, otherwise
+ this will attempt to create a stage in a temporary directory and link it into spack.stage_path.
+
+ Spack will use the first writable location in spack.tmp_dirs to create a stage. If there is no valid location
+ in tmp_dirs, fall back to making the stage inside spack.stage_path.
+ """
+ # Create the top-level stage directory
+ mkdirp(spack.stage_path)
+ remove_dead_links(spack.stage_path)
+ # If a tmp_root exists then create a directory there and then link it in the stage area,
+ # otherwise create the stage directory in self.path
+ if self._need_to_create_path():
+ if self.tmp_root:
+ tmp_dir = tempfile.mkdtemp('', STAGE_PREFIX, self.tmp_root)
+ os.symlink(tmp_dir, self.path)
+ else:
+ mkdirp(self.path)
+ # Make sure we can actually do something with the stage we made.
+ ensure_access(self.path)
+
def destroy(self):
- """Remove this stage directory."""
+ """
+ Removes this stage directory
+ """
remove_linked_tree(self.path)
# Make sure we don't end up in a removed directory