refactor: remove unused spack.stage._get_mirrors() function

This commit is contained in:
Tamara Dahlgren 2019-06-05 17:26:42 -07:00 committed by Todd Gamblin
parent 8e3fd3f7c2
commit eb584d895b

View File

@ -28,6 +28,7 @@
from spack.util.path import canonicalize_path from spack.util.path import canonicalize_path
from spack.util.crypto import prefix_bits, bit_length from spack.util.crypto import prefix_bits, bit_length
_source_path_subdir = 'src'
_stage_prefix = 'spack-stage-' _stage_prefix = 'spack-stage-'
@ -46,8 +47,9 @@ def _first_accessible_path(paths):
# return it if successful. # return it if successful.
return path return path
except OSError: except OSError as e:
tty.debug('OSError while checking temporary path: %s' % path) tty.debug('OSError while checking temporary path %s: %s' % (
path, str(e)))
continue continue
return None return None
@ -78,7 +80,7 @@ def get_tmp_root():
_use_tmp_stage = False _use_tmp_stage = False
return None return None
# ensure that any temp path is unique per user, so users don't # Ensure that any temp path is unique per user, so users don't
# fight over shared temporary space. # fight over shared temporary space.
user = getpass.getuser() user = getpass.getuser()
if user not in path: if user not in path:
@ -292,13 +294,18 @@ def _need_to_create_path(self):
def expected_archive_files(self): def expected_archive_files(self):
"""Possible archive file paths.""" """Possible archive file paths."""
paths = [] paths = []
if isinstance(self.default_fetcher, fs.URLFetchStrategy): roots = [self.path]
paths.append(os.path.join( if self.expanded:
self.path, os.path.basename(self.default_fetcher.url))) roots.insert(0, self.source_path)
if self.mirror_path: for path in roots:
paths.append(os.path.join( if isinstance(self.default_fetcher, fs.URLFetchStrategy):
self.path, os.path.basename(self.mirror_path))) paths.append(os.path.join(
path, os.path.basename(self.default_fetcher.url)))
if self.mirror_path:
paths.append(os.path.join(
path, os.path.basename(self.mirror_path)))
return paths return paths
@ -320,28 +327,15 @@ def archive_file(self):
else: else:
return None return None
@property
def expanded(self):
"""Returns True if source path expanded; else False."""
return os.path.exists(self.source_path)
@property @property
def source_path(self): def source_path(self):
"""Returns the path to the expanded/checked out source code. """Returns the well-known source directory path."""
return os.path.join(self.path, _source_path_subdir)
To find the source code, this method searches for the first
subdirectory of the stage that it can find, and returns it.
This assumes nothing besides the archive file will be in the
stage path, but it has the advantage that we don't need to
know the name of the archive or its contents.
If the fetch strategy is not supposed to expand the downloaded
file, it will just return the stage path. If the archive needs
to be expanded, it will return None when no archive is found.
"""
if isinstance(self.fetcher, fs.URLFetchStrategy):
if not self.fetcher.expand_archive:
return self.path
for p in [os.path.join(self.path, f) for f in os.listdir(self.path)]:
if os.path.isdir(p):
return p
return None
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."""
@ -441,8 +435,7 @@ 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
downloaded.""" downloaded."""
archive_dir = self.source_path if not self.expanded:
if not archive_dir:
self.fetcher.expand() self.fetcher.expand()
tty.msg("Created stage in %s" % self.path) tty.msg("Created stage in %s" % self.path)
else: else:
@ -635,12 +628,6 @@ def cache_local(self):
tty.msg("Sources for DIY stages are not cached") tty.msg("Sources for DIY stages are not cached")
def _get_mirrors():
"""Get mirrors from spack configuration."""
config = spack.config.get('mirrors')
return [val for name, val in iteritems(config)]
def ensure_access(file=spack.paths.stage_path): def ensure_access(file=spack.paths.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):