~ubuntu-branches/ubuntu/lucid/jhbuild/lucid

« back to all changes in this revision

Viewing changes to jhbuild/utils/unpack.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort, Loic Minier, Emilio Pozuelo Monfort
  • Date: 2009-11-09 20:28:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091109202848-m9ec7dmzptqtchtj
Tags: 2.28.0-1
[ Loic Minier ]
* Cleanups.
* Ship scripts.
* Don't set GNOME_MODULE as it equals the name of the source package.

[ Emilio Pozuelo Monfort ]
* New upstream release. Closes: #524504.
  - Use 'git rev-parse' rather than 'git-rev-parse'. Closes: #544642.
* Ship install-check. Closes: #441008.
* Uploaders list regenerated. Closes: #523542, #554071.
* debian/control.in,
  debian/rules:
  - Stop shipping a copy of subprocess.py. Require python >= 2.4.
  - Switch to python-support.
* debian/control.in:
  - Bump Standards-Version to 3.8.3, no changes needed.
  - Build depend on intltool >= 0.35.0.
  - Build depend on pkg-config, gnome-doc-utils and rarian-compat to build
    the documentation.
  - Make jhbuild arch any since install-check is a binary. Depend on
    ${shlibs:Depends}.
  - Recommend, and not suggest, git-core. Also recommend mercurial.
* debian/watch:
  - Added.
* debian/patches/01_import_from_pkgdatadir.patch:
  - Added, import jhbuild from pkgdatadir if everything else fails.
    This way we can ship the jhbuild private modules in /usr/sharejhbuild.
* debian/jhbuild.docs:
  - Removed, the necessary docs are now installed by the upstream Makefile.
* debian/rules:
  - Include autotools.mk and gnome.mk.
  - Remove all the manual build process, autotools.mk does everything now.
  - Install the jhbuild modules in /usr/share/jhbuild.
* debian/install:
  - Install the modulesets and patches from here since the upstream build
    system doesn't install them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# jhbuild - a build script for GNOME 1.x and 2.x
 
2
# Copyright (C) 2007  Alberto Ruiz <aruiz@gnome.org>
 
3
#
 
4
#   unpack.py: helper functions for unpacking compressed packages
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
import tarfile
 
21
import zipfile
 
22
import os.path
 
23
 
 
24
from jhbuild.utils.cmds import has_command
 
25
from jhbuild.errors import CommandError
 
26
 
 
27
 
 
28
def unpack_tar_file(localfile, target_directory):
 
29
    pkg = tarfile.open(localfile, 'r|*')
 
30
    pkg.extractall(target_directory)
 
31
    pkg.close()
 
32
 
 
33
 
 
34
def unpack_zip_file(localfile, target_directory):
 
35
    # Attributes are stored in ZIP files in a host-dependent way.
 
36
    # The zipinfo.create_system value describes the host OS.
 
37
    # Known values:
 
38
    #   * 3 (UNIX)
 
39
    #   * 11 (undefined, seems to be UNIX)
 
40
    #   * 0 (MSDOS)
 
41
    # Reference: http://www.opennet.ru/docs/formats/zip.txt
 
42
 
 
43
    def attr_check_symlink(host, attr):
 
44
        if host == 0:
 
45
            return False
 
46
        return attr == 0xA1ED0000
 
47
 
 
48
    def attr_to_file_perm(host, attr):
 
49
        if host == 0:
 
50
            if attr & 1:
 
51
                perm = 0444
 
52
            else:
 
53
                perm = 0666
 
54
        else:
 
55
            perm = attr
 
56
            perm &= 0x08FF0000
 
57
            perm >>= 16
 
58
            perm |= 0x00000100
 
59
        return perm
 
60
 
 
61
    def attr_to_dir_perm(host, attr):
 
62
        if host==0:
 
63
            # attr & 16 should be true (this is directory bit)
 
64
            if attr & 1:
 
65
                perm = 0444
 
66
            else:
 
67
                perm = 0666
 
68
        else:
 
69
            perm = attr
 
70
            perm &= 0xFFFF0000
 
71
            perm >>= 16
 
72
            perm |= 0x00000100
 
73
        return perm
 
74
 
 
75
    def makedirs(dir):
 
76
        if not os.path.isdir(dir):
 
77
            os.makedirs(dir)
 
78
 
 
79
    pkg = zipfile.ZipFile(localfile, 'r')
 
80
    for pkg_fileinfo in pkg.filelist:
 
81
        pkg_file = pkg_fileinfo.filename
 
82
        attr = pkg_fileinfo.external_attr
 
83
        chost = pkg_fileinfo.create_system
 
84
 
 
85
        # symbolic link
 
86
        if attr_check_symlink(chost, attr):
 
87
            # TODO: support symlinks in zipfiles
 
88
            continue
 
89
 
 
90
        # directory
 
91
        if pkg_file.endswith('/'):
 
92
            dir = os.path.join(target_directory, pkg_file)
 
93
            makedirs(dir)
 
94
            os.chmod(dir, attr_to_dir_perm(chost, attr))
 
95
            continue
 
96
 
 
97
        # file
 
98
        if '/' in pkg_file:
 
99
            dir = os.path.dirname(pkg_file)
 
100
            dir = os.path.join(target_directory, dir)
 
101
            makedirs(dir)
 
102
 
 
103
        data = pkg.read(pkg_file)
 
104
        file = open(os.path.join(target_directory, pkg_file), 'wb')
 
105
        file.write(data)
 
106
        file.close()
 
107
 
 
108
        os.chmod(os.path.join(target_directory, pkg_file), attr_to_file_perm(chost, attr))
 
109
 
 
110
 
 
111
def unpack_archive(buildscript, localfile, target_directory):
 
112
    ext = os.path.splitext(localfile)[-1]
 
113
    if ext == '.lzma' and has_command('lzcat') and has_command('tar'):
 
114
        buildscript.execute('lzcat -d "%s" | tar xf -' % localfile,
 
115
                cwd = target_directory)
 
116
    if ext == '.bz2' and has_command('bunzip2') and has_command('tar'):
 
117
        buildscript.execute('bunzip2 -dc "%s" | tar xf -' % localfile,
 
118
                cwd = target_directory)
 
119
    elif ext in ('.gz', '.tgz') and has_command('gunzip') and has_command('tar'):
 
120
        buildscript.execute('gunzip -dc "%s" | tar xf -' % localfile,
 
121
                cwd = target_directory)
 
122
    elif ext == '.zip' and has_command('unzip'):
 
123
        buildscript.execute('unzip "%s"' % localfile,
 
124
                cwd = target_directory)
 
125
    else:
 
126
        try:
 
127
            if tarfile.is_tarfile(localfile):
 
128
                unpack_tar_file(localfile, target_directory)
 
129
            elif zipfile.is_zipfile(localfile):
 
130
                unpack_zip_file(localfile, target_directory)    
 
131
            else:
 
132
                raise CommandError(_('Failed to unpack %s (unknown archive type)') % localfile)
 
133
        except:
 
134
            raise CommandError(_('Failed to unpack %s') % localfile)