summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-03-02 15:56:09 +0100
committeralalazo <massimiliano.culpo@googlemail.com>2016-03-02 15:56:09 +0100
commit9001b9ed3c01f8ccaceaca60d6a34c3551f77240 (patch)
treea23eb5b1735c4472b6c8b4cdca7fa9f30d7b1733 /lib
parentd649b715edae0871254695e2deacf078554a1475 (diff)
downloadspack-9001b9ed3c01f8ccaceaca60d6a34c3551f77240.tar.gz
spack-9001b9ed3c01f8ccaceaca60d6a34c3551f77240.tar.bz2
spack-9001b9ed3c01f8ccaceaca60d6a34c3551f77240.tar.xz
spack-9001b9ed3c01f8ccaceaca60d6a34c3551f77240.zip
package : minor syntax fixes
mirror : extracted add_single_spec from create
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/mirror.py106
-rw-r--r--lib/spack/spack/package.py4
2 files changed, 58 insertions, 52 deletions
diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py
index bc8870926f..5ed7aff176 100644
--- a/lib/spack/spack/mirror.py
+++ b/lib/spack/spack/mirror.py
@@ -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,58 +157,65 @@ 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
- tty.msg("Adding package {pkg} to mirror".format(pkg=spec.format("$_$@")))
- try:
- with pkg.stage:
- for ii, stage in enumerate(pkg.stage):
- fetcher = stage.fetcher
- if ii == 0:
- # create a subdirectory for the current package@version
- archive_path = os.path.abspath(join_path(mirror_root, mirror_archive_path(spec, fetcher)))
- name = spec.format("$_$@")
- else:
- resource = stage.resource
- archive_path = join_path(subdir, suggest_archive_basename(resource))
- name = "{resource} ({pkg}).".format(resource=resource.name, pkg=spec.format("$_$@"))
- subdir = os.path.dirname(archive_path)
- mkdirp(subdir)
-
- if os.path.exists(archive_path):
- tty.msg("{name} : already added".format(name=name))
- else:
- everything_already_exists = False
- fetcher.fetch()
- if not kwargs.get('no_checksum', False):
- fetcher.check()
- tty.msg("{name} : checksum passed".format(name=name))
-
- # Fetchers have to know how to archive their files. Use
- # that to move/copy/create an archive in the mirror.
- fetcher.archive(archive_path)
- tty.msg("{name} : added".format(name=name))
-
- if everything_already_exists:
- present.append(spec)
- else:
- mirrored.append(spec)
- except Exception, 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)
+ 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 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
+ archive_path = os.path.abspath(join_path(mirror_root, mirror_archive_path(spec, fetcher)))
+ name = spec.format("$_$@")
+ else:
+ resource = stage.resource
+ archive_path = join_path(subdir, suggest_archive_basename(resource))
+ name = "{resource} ({pkg}).".format(resource=resource.name, pkg=spec.format("$_$@"))
+ subdir = os.path.dirname(archive_path)
+ mkdirp(subdir)
+
+ if os.path.exists(archive_path):
+ tty.msg("{name} : already added".format(name=name))
+ else:
+ spec_exists_in_mirror = False
+ fetcher.fetch()
+ if not kwargs.get('no_checksum', False):
+ fetcher.check()
+ tty.msg("{name} : checksum passed".format(name=name))
+
+ # Fetchers have to know how to archive their files. Use
+ # that to move/copy/create an archive in the mirror.
+ fetcher.archive(archive_path)
+ tty.msg("{name} : added".format(name=name))
+
+ if spec_exists_in_mirror:
+ categories['present'].append(spec)
+ else:
+ 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)
+ categories['error'].append(spec)
class MirrorError(spack.error.SpackError):
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index 4fdc582479..29b781a749 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -732,7 +732,7 @@ class Package(object):
# If we encounter an archive that failed to patch, restage it
# so that we can apply all the patches again.
if os.path.isfile(bad_file):
- tty.msg("Patching failed last time. Restaging.")
+ tty.msg("Patching failed last time. Restaging.")
self.stage.restage()
self.stage.chdir_to_source()
@@ -912,7 +912,7 @@ class Package(object):
% (_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()