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