Fixes issues introduced after merge with conflicts

This commit is contained in:
alalazo 2016-01-26 12:08:28 +01:00
parent 6f11a64af5
commit 093b831799
2 changed files with 25 additions and 21 deletions

View file

@ -804,6 +804,9 @@ def _get_resources(self):
for when_spec, resource_list in self.resources.items(): for when_spec, resource_list in self.resources.items():
if when_spec in self.spec: if when_spec in self.spec:
resources.extend(resource_list) resources.extend(resource_list)
# Sorts the resources by the length of the string representing their destination. Since any nested resource
# must contain another resource's name in its path, it seems that should work
resources = sorted(resources, key=lambda res: len(res.destination))
return resources return resources
def _resource_stage(self, resource): def _resource_stage(self, resource):

View file

@ -1,4 +1,4 @@
############################################################################## 1 ##############################################################################
# Copyright (c) 2013, Lawrence Livermore National Security, LLC. # Copyright (c) 2013, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory. # Produced at the Lawrence Livermore National Laboratory.
# #
@ -23,7 +23,7 @@
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import os import os
import re import errno
import shutil import shutil
import tempfile import tempfile
from urlparse import urljoin from urlparse import urljoin
@ -38,7 +38,6 @@
import spack.fetch_strategy as fs import spack.fetch_strategy as fs
import spack.error import spack.error
STAGE_PREFIX = 'spack-stage-' STAGE_PREFIX = 'spack-stage-'
@ -95,7 +94,7 @@ def __init__(self, url_or_fetch_strategy, **kwargs):
raise ValueError("Can't construct Stage without url or fetch strategy") raise ValueError("Can't construct Stage without url or fetch strategy")
self.fetcher.set_stage(self) self.fetcher.set_stage(self)
self.default_fetcher = self.fetcher # self.fetcher can change with mirrors. self.default_fetcher = self.fetcher # self.fetcher can change with mirrors.
self.skip_checksum_for_mirror = True # used for mirrored archives of repositories. self.skip_checksum_for_mirror = True # used for mirrored archives of repositories.
self.name = kwargs.get('name') self.name = kwargs.get('name')
self.mirror_path = kwargs.get('mirror_path') self.mirror_path = kwargs.get('mirror_path')
@ -104,7 +103,6 @@ def __init__(self, url_or_fetch_strategy, **kwargs):
self.path = None self.path = None
self._setup() self._setup()
def _cleanup_dead_links(self): def _cleanup_dead_links(self):
"""Remove any dead links in the stage directory.""" """Remove any dead links in the stage directory."""
for file in os.listdir(spack.stage_path): for file in os.listdir(spack.stage_path):
@ -114,7 +112,6 @@ def _cleanup_dead_links(self):
if not os.path.exists(path): if not os.path.exists(path):
os.unlink(path) os.unlink(path)
def _need_to_create_path(self): def _need_to_create_path(self):
"""Makes sure nothing weird has happened since the last time we """Makes sure nothing weird has happened since the last time we
looked at path. Returns True if path already exists and is ok. looked at path. Returns True if path already exists and is ok.
@ -132,7 +129,7 @@ def _need_to_create_path(self):
# Path looks ok, but need to check the target of the link. # Path looks ok, but need to check the target of the link.
if os.path.islink(self.path): if os.path.islink(self.path):
real_path = os.path.realpath(self.path) real_path = os.path.realpath(self.path)
real_tmp = os.path.realpath(self.tmp_root) real_tmp = os.path.realpath(self.tmp_root)
if spack.use_tmp_stage: if spack.use_tmp_stage:
# If we're using a tmp dir, it's a link, and it points at the right spot, # If we're using a tmp dir, it's a link, and it points at the right spot,
@ -151,7 +148,6 @@ def _need_to_create_path(self):
return False return False
def _setup(self): def _setup(self):
"""Creates the stage directory. """Creates the stage directory.
If spack.use_tmp_stage is False, the stage directory is created If spack.use_tmp_stage is False, the stage directory is created
@ -200,7 +196,6 @@ def _setup(self):
# Make sure we can actually do something with the stage we made. # Make sure we can actually do something with the stage we made.
ensure_access(self.path) ensure_access(self.path)
@property @property
def archive_file(self): def archive_file(self):
"""Path to the source archive within this stage directory.""" """Path to the source archive within this stage directory."""
@ -217,7 +212,6 @@ def archive_file(self):
else: else:
return None return None
@property @property
def source_path(self): def source_path(self):
"""Returns the path to the expanded/checked out source code """Returns the path to the expanded/checked out source code
@ -232,7 +226,6 @@ def source_path(self):
return p return p
return None return None
def chdir(self): def chdir(self):
"""Changes directory to the stage path. Or dies if it is not set up.""" """Changes directory to the stage path. Or dies if it is not set up."""
if os.path.isdir(self.path): if os.path.isdir(self.path):
@ -240,7 +233,6 @@ def chdir(self):
else: else:
tty.die("Setup failed: no such directory: " + self.path) tty.die("Setup failed: no such directory: " + self.path)
def fetch(self, mirror_only=False): def fetch(self, mirror_only=False):
"""Downloads an archive or checks out code from a repository.""" """Downloads an archive or checks out code from a repository."""
self.chdir() self.chdir()
@ -293,7 +285,6 @@ def fetch(self, mirror_only=False):
self.fetcher = self.default_fetcher self.fetcher = self.default_fetcher
raise fs.FetchError(errMessage, None) raise fs.FetchError(errMessage, None)
def check(self): def check(self):
"""Check the downloaded archive against a checksum digest. """Check the downloaded archive against a checksum digest.
No-op if this stage checks code out of a repository.""" No-op if this stage checks code out of a repository."""
@ -307,7 +298,6 @@ def check(self):
else: else:
self.fetcher.check() self.fetcher.check()
def expand_archive(self): def expand_archive(self):
"""Changes to the stage directory and attempt to expand the downloaded """Changes to the stage directory and attempt to expand the downloaded
archive. Fail if the stage is not set up or if the archive is not yet archive. Fail if the stage is not set up or if the archive is not yet
@ -320,7 +310,6 @@ def expand_archive(self):
else: else:
tty.msg("Already staged %s in %s." % (self.name, self.path)) tty.msg("Already staged %s in %s." % (self.name, self.path))
def chdir_to_source(self): def chdir_to_source(self):
"""Changes directory to the expanded archive directory. """Changes directory to the expanded archive directory.
Dies with an error if there was no expanded archive. Dies with an error if there was no expanded archive.
@ -333,14 +322,12 @@ def chdir_to_source(self):
if not os.listdir(path): if not os.listdir(path):
tty.die("Archive was empty for %s" % self.name) tty.die("Archive was empty for %s" % self.name)
def restage(self): def restage(self):
"""Removes the expanded archive path if it exists, then re-expands """Removes the expanded archive path if it exists, then re-expands
the archive. the archive.
""" """
self.fetcher.reset() self.fetcher.reset()
def destroy(self): def destroy(self):
"""Remove this stage directory.""" """Remove this stage directory."""
remove_linked_tree(self.path) remove_linked_tree(self.path)
@ -367,11 +354,24 @@ def expand_archive(self):
placement = {'': placement} placement = {'': placement}
# Make the paths in the dictionary absolute and link # Make the paths in the dictionary absolute and link
for key, value in placement.iteritems(): for key, value in placement.iteritems():
link_path = join_path(root_stage.source_path, resource.destination, value) target_path = join_path(root_stage.source_path, resource.destination)
destination_path = join_path(target_path, value)
source_path = join_path(self.source_path, key) source_path = join_path(self.source_path, key)
if not os.path.exists(link_path):
try:
os.makedirs(target_path)
except OSError as err:
if err.errno == errno.EEXIST and os.path.isdir(target_path):
pass
else:
raise
if not os.path.exists(destination_path):
# Create a symlink # Create a symlink
os.symlink(source_path, link_path) tty.info('Moving resource stage\n\tsource : {stage}\n\tdestination : {destination}'.format(
stage=source_path, destination=destination_path
))
shutil.move(source_path, destination_path)
@pattern.composite(method_list=['fetch', 'check', 'expand_archive', 'restage', 'destroy']) @pattern.composite(method_list=['fetch', 'check', 'expand_archive', 'restage', 'destroy'])
@ -380,6 +380,7 @@ class StageComposite:
Composite for Stage type objects. The first item in this composite is considered to be the root package, and Composite for Stage type objects. The first item in this composite is considered to be the root package, and
operations that return a value are forwarded to it. operations that return a value are forwarded to it.
""" """
@property @property
def source_path(self): def source_path(self):
return self[0].source_path return self[0].source_path
@ -394,6 +395,7 @@ def chdir_to_source(self):
class DIYStage(object): class DIYStage(object):
"""Simple class that allows any directory to be a spack stage.""" """Simple class that allows any directory to be a spack stage."""
def __init__(self, path): def __init__(self, path):
self.archive_file = None self.archive_file = None
self.path = path self.path = path
@ -431,7 +433,6 @@ def _get_mirrors():
return [val for name, val in config.iteritems()] return [val for name, val in config.iteritems()]
def ensure_access(file=spack.stage_path): def ensure_access(file=spack.stage_path):
"""Ensure we can access a directory and die with an error if we can't.""" """Ensure we can access a directory and die with an error if we can't."""
if not can_access(file): if not can_access(file):