1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/env python
#
# Copyright (C) 2011-2012 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# This is a program to convert the json dump of the overlaps between artifacts
# in a format more suited to shell programs, or human reading
import json
import tarfile
import os
import cliapp
class AssembleStratum(cliapp.Application):
def add_settings(self):
self.settings.string(['cachedir'],
'Where the cache basedir is')
self.settings.string(['tarformat'],
'What format to write tar to',
default='')
def process_args(self, args):
chunklist = json.load(open(args[0]))
tarformat = 'w'
if self.settings['tarformat'] != "":
tarformat += self.settings['tarformat']
outfile = tarfile.open(args[1], tarformat)
# concatenate chunk tarballs
for chunk in chunklist:
path = os.path.join(self.settings['cachedir'], 'artifacts', chunk)
chunktar = tarfile.open(path, mode='r:*')
for tarinfo in chunktar:
if tarinfo.isfile():
outfile.addfile(tarinfo, chunktar.extractfile(tarinfo))
else:
outfile.addfile(tarinfo)
chunktar.close()
# add the stratum's metadata
if os.path.exists(args[0] + '.meta'):
outfile.add(args[0] + '.meta',
os.path.join('baserock', '%s.meta' % args[2]))
outfile.close()
AssembleStratum().run()
|