Skip to content

Commit d8e2d17

Browse files
committed
Expand on Ben Boeckel's use of python tarfile
1 parent 78e0eb5 commit d8e2d17

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

lib/spack/spack/binary_distribution.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77

88
import llnl.util.tty as tty
9-
from llnl.util.filesystem import mkdirp
9+
from llnl.util.filesystem import mkdirp,join_path
1010

1111
from spack.util.executable import which
1212
import spack.cmd
@@ -113,7 +113,7 @@ def tarball_directory_name(spec):
113113
def tarball_name(spec, ext):
114114
"""
115115
Return the name of the tarfile according to the convention
116-
<os>-<architecture>-<package>-<dag_hash>.tar.gz
116+
<os>-<architecture>-<package>-<dag_hash><ext>
117117
"""
118118
return "%s-%s-%s-%s%s" % (get_full_system_from_platform(),
119119
spec.name,
@@ -136,43 +136,45 @@ def build_tarball(spec, outdir, force=False, key=None):
136136
Build a tarball from given spec and put it into the directory structure
137137
used at the mirror (following <tarball_directory_name>).
138138
"""
139-
tarfile_dir = os.path.join(outdir, tarball_directory_name(spec))
140-
tarfile_path = os.path.join(outdir, tarball_path_name(spec, '.tar.gz'))
141-
if force:
142-
os.remove(tarfile)
143-
else:
144-
tty.warn("file exists, use -f to force overwrite: %s" % tarfile)
145-
return
146-
if not os.path.exists(tarfile_dir):
147-
mkdirp(tarfile_dir)
148-
149-
dirname = os.path.dirname(spec.prefix)
150-
basename = os.path.basename(spec.prefix)
151-
spec_file = os.path.join(spec.prefix, ".spack", "spec.yaml")
139+
tarfile_name = tarball_name(spec, '.tar.gz')
140+
tarfile_dir = join_path(outdir, tarball_directory_name(spec))
141+
tarfile_path = join_path(tarfile_dir,tarfile_name)
142+
mkdirp(tarfile_dir)
143+
if os.path.exists(tarfile_path):
144+
if force:
145+
os.remove(tarfile_path)
146+
else:
147+
tty.warn("file exists, use -f to force overwrite: %s" % tarfile)
148+
return
149+
150+
spec_file = join_path(spec.prefix, ".spack", "spec.yaml")
152151

153152
# create info for later relocation and create tar
153+
write_buildinfo_file(spec)
154154
with tarfile.open(tarfile_path, 'w:gz') as tar:
155-
write_buildinfo_file(spec)
156-
157-
tar.add(basename)
158-
159-
spec_info = tar.gettarinfo(spec_file, arcname='.spack/spec.yaml')
160-
tar.addfile(spec_info)
155+
tar.add(name = '%s' % spec.prefix
156+
, arcname = '%s' % os.path.basename(spec.prefix))
161157

162158
# Sign the packages.
163159
#spack gpg sign [--key key] tarfile_path
164-
#spack gpg sign [--key key] spec_file
160+
#spack gpg sign [--key key] tarfile_path + '/spec.yaml'
161+
path1='%s.asc' % tarfile_path
162+
with open(path1,'a'):
163+
os.utime(path1, None)
164+
path2='%s.asc' % spec_file
165+
with open(path2,'a'):
166+
os.utime(path2, None)
167+
165168

166169
spackfile_path = os.path.join(outdir, tarball_path_name(spec, '.spack'))
167170
with tarfile.open(spackfile_path, 'w') as tar:
168-
tar.add(tarfile_path)
169-
#tar.add(tarfile_path + '.asc')
170-
171-
spec_info = tar.gettarinfo(spec_file, arcname='spec.yaml')
172-
tar.addfile(spec_info)
173-
174-
#tar.add(spec_file + '.asc')
175-
171+
tar.add(name = '%s' % tarfile_path, arcname = '%s' % tarfile_name)
172+
tar.add(name = '%s' % spec_file, arcname = 'spec.yaml')
173+
tar.add(name = '%s.asc' % tarfile_path , arcname = '%s.asc' % tarfile_name )
174+
tar.add(name = '%s.asc' % spec_file, arcname = 'spec.yaml.asc' )
175+
os.remove(tarfile_path)
176+
os.remove(path1)
177+
os.remove(path2)
176178
tty.msg(tarfile_path)
177179

178180

lib/spack/spack/cmd/create_tarball.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
##############################################################################
2525
import argparse
2626

27+
import os
28+
2729
import llnl.util.tty as tty
2830

2931
import spack
@@ -37,8 +39,6 @@
3739

3840

3941
def setup_parser(subparser):
40-
subparser.add_argument('-r', '--recurse', action='store_true',
41-
help="also make tarballs for dependencies.")
4242
subparser.add_argument('-f', '--force', action='store_true',
4343
help="overwrite tarball if it exists.")
4444
subparser.add_argument('-d', '--directory', default=".",
@@ -55,14 +55,16 @@ def create_tarball(parser, args):
5555

5656
pkgs = set(args.packages)
5757
specs = set()
58+
outdir = os.getcwd()
59+
if args.directory :
60+
outdir = args.directory
5861
for pkg in pkgs:
5962
for spec in spack.cmd.parse_specs(pkg, concretize=True):
6063
specs.add(spec)
61-
if args.recurse:
62-
tty.msg('recursing dependencies')
63-
for d, node in spec.traverse(order='pre', depth=True):
64-
tty.msg('adding dependency %s' % node)
65-
specs.add(node)
64+
tty.msg('recursing dependencies')
65+
for d, node in spec.traverse(order='pre', depth=True):
66+
tty.msg('adding dependency %s' % node)
67+
specs.add(node)
6668
for spec in specs:
6769
tty.msg('creating binary cache tarball for package %s ' % spec)
68-
build_tarball(spec, args.directory, args.force)
70+
build_tarball(spec, outdir, args.force)

0 commit comments

Comments
 (0)