package : minor syntax fixes

mirror : extracted add_single_spec from create
This commit is contained in:
alalazo 2016-03-02 15:56:09 +01:00
parent d649b715ed
commit 9001b9ed3c
2 changed files with 54 additions and 48 deletions

View file

@ -110,7 +110,6 @@ def suggest_archive_basename(resource):
return basename return basename
def create(path, specs, **kwargs): def create(path, specs, **kwargs):
"""Create a directory to be used as a spack mirror, and fill it with """Create a directory to be used as a spack mirror, and fill it with
package archives. package archives.
@ -158,18 +157,29 @@ def create(path, specs, **kwargs):
"Cannot create directory '%s':" % mirror_root, str(e)) "Cannot create directory '%s':" % mirror_root, str(e))
# Things to keep track of while parsing specs. # Things to keep track of while parsing specs.
present = [] categories = {
mirrored = [] 'present': [],
error = [] 'mirrored': [],
'error': []
}
# Iterate through packages and download all the safe tarballs for each of them # Iterate through packages and download all the safe tarballs for each of them
everything_already_exists = True
for spec in version_specs: for spec in version_specs:
pkg = spec.package add_single_spec(spec, mirror_root, categories, **kwargs)
return categories['present'], categories['mirrored'], categories['error']
def add_single_spec(spec, mirror_root, categories, **kwargs):
tty.msg("Adding package {pkg} to mirror".format(pkg=spec.format("$_$@"))) tty.msg("Adding package {pkg} to mirror".format(pkg=spec.format("$_$@")))
spec_exists_in_mirror = True
try: try:
with pkg.stage: with spec.package.stage:
for ii, stage in enumerate(pkg.stage): # fetcher = stage.fetcher
# fetcher.fetch()
# ...
# fetcher.archive(archive_path)
for ii, stage in enumerate(spec.package.stage):
fetcher = stage.fetcher fetcher = stage.fetcher
if ii == 0: if ii == 0:
# create a subdirectory for the current package@version # create a subdirectory for the current package@version
@ -185,7 +195,7 @@ def create(path, specs, **kwargs):
if os.path.exists(archive_path): if os.path.exists(archive_path):
tty.msg("{name} : already added".format(name=name)) tty.msg("{name} : already added".format(name=name))
else: else:
everything_already_exists = False spec_exists_in_mirror = False
fetcher.fetch() fetcher.fetch()
if not kwargs.get('no_checksum', False): if not kwargs.get('no_checksum', False):
fetcher.check() fetcher.check()
@ -196,20 +206,16 @@ def create(path, specs, **kwargs):
fetcher.archive(archive_path) fetcher.archive(archive_path)
tty.msg("{name} : added".format(name=name)) tty.msg("{name} : added".format(name=name))
if everything_already_exists: if spec_exists_in_mirror:
present.append(spec) categories['present'].append(spec)
else: else:
mirrored.append(spec) categories['mirrored'].append(spec)
except Exception, e: except Exception as e:
if spack.debug: if spack.debug:
sys.excepthook(*sys.exc_info()) sys.excepthook(*sys.exc_info())
else: else:
tty.warn("Error while fetching %s." % spec.format('$_$@'), e.message) tty.warn("Error while fetching %s." % spec.format('$_$@'), e.message)
error.append(spec) categories['error'].append(spec)
finally:
pkg.stage.destroy()
return (present, mirrored, error)
class MirrorError(spack.error.SpackError): class MirrorError(spack.error.SpackError):

View file

@ -912,7 +912,7 @@ def real_work():
% (_hms(self._fetch_time), _hms(build_time), _hms(self._total_time))) % (_hms(self._fetch_time), _hms(build_time), _hms(self._total_time)))
print_pkg(self.prefix) print_pkg(self.prefix)
except ProcessError, e: except ProcessError as e:
# Annotate with location of build log. # Annotate with location of build log.
e.build_log = log_path e.build_log = log_path
cleanup() cleanup()