~ubuntu-branches/ubuntu/utopic/curtin/utopic

« back to all changes in this revision

Viewing changes to curtin/commands/extract.py

  • Committer: Package Import Robot
  • Author(s): Scott Moser
  • Date: 2014-07-22 18:53:38 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20140722185338-2nm6ekaottq6ldge
Tags: 0.1.0~bzr142-0ubuntu1
* New upstream snapshot.
  * add utility for parsing /etc/network/interfaces
  * aarm64 support [Newell Jensen]
    * run update-initramfs in aarm64
    * create boot partition when necessary (LP: #1338851 LP: #1340942)
  * know kernel mapping for utopic (3.16)
  * properly write fstype into /etc/fstab per provided fstype
  * add support for disk images as type 'dd-tgz'
  * correctly call finalize in target (LP: #1328521)
  * support invoking tar with --xattrs if available (LP: #1307636)
  * increase size of uefi partition to 512M (LP: #1306164)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
)
36
36
 
37
37
 
 
38
def tar_xattr_opts(cmd=None):
 
39
    # if tar cmd supports xattrs, return the required flags to extract them.
 
40
    if cmd is None:
 
41
        cmd = ['tar']
 
42
 
 
43
    if isinstance(cmd, str):
 
44
        cmd = [cmd]
 
45
 
 
46
    (out, _err) = curtin.util.subp(cmd + ['--help'], capture=True)
 
47
 
 
48
    if "xattr" in out:
 
49
        return ['--xattrs', '--xattrs-include=*', '--acls']
 
50
    return []
 
51
 
 
52
 
38
53
def extract_root_tgz_url(source, target):
39
 
    curtin.util.subp(args=['sh', '-c',
 
54
    curtin.util.subp(args=['sh', '-cf',
40
55
                           ('wget "$1" --progress=dot:mega -O - |'
41
 
                            'tar -C "$2" -Sxpzf - --numeric-owner'),
 
56
                            'tar -C "$2" ' + ' '.join(tar_xattr_opts()) +
 
57
                            ' ' + '-Sxpzf - --numeric-owner'),
42
58
                           '--', source, target])
43
59
 
44
60
 
45
61
def extract_root_tgz_file(source, target):
46
 
    curtin.util.subp(args=['tar', '-C', target, '-Sxpzf', source,
47
 
                           '--numeric-owner'])
 
62
    curtin.util.subp(args=['tar', '-C', target] +
 
63
                     tar_xattr_opts() + ['-Sxpzf', source, '--numeric-owner'])
48
64
 
49
65
 
50
66
def copy_to_target(source, target):
80
96
    LOG.debug("Installing sources: %s to target at %s" % (sources, target))
81
97
 
82
98
    for source in sources:
83
 
        if source.startswith("cp://"):
84
 
            copy_to_target(source, target)
85
 
        elif os.path.isfile(source):
86
 
            extract_root_tgz_file(source, target)
87
 
        elif source.startswith("file://"):
88
 
            extract_root_tgz_file(source[len("file://"):], target)
89
 
        elif source.startswith("http://") or source.startswith("https://"):
90
 
            extract_root_tgz_url(source, target)
 
99
        if source['type'].startswith('dd-'):
 
100
            continue
 
101
        if source['uri'].startswith("cp://"):
 
102
            copy_to_target(source['uri'], target)
 
103
        elif os.path.isfile(source['uri']):
 
104
            extract_root_tgz_file(source['uri'], target)
 
105
        elif source['uri'].startswith("file://"):
 
106
            extract_root_tgz_file(
 
107
                source['uri'][len("file://"):],
 
108
                target)
 
109
        elif (source['uri'].startswith("http://") or
 
110
              source['uri'].startswith("https://")):
 
111
            extract_root_tgz_url(source['uri'], target)
91
112
        else:
92
 
            raise TypeError("do not know how to extract '%s'", source)
 
113
            raise TypeError(
 
114
                "do not know how to extract '%s'" %
 
115
                source['uri'])
93
116
 
94
117
 
95
118
def POPULATE_SUBCMD(parser):