contrib/fixpax.py
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 11 Jan 2016 18:16:38 -0800
changeset 27721 e4b512bb6386
parent 27495 58eb1c5bba58
child 28354 00f317788d33
permissions -rwxr-xr-x
debugshell: disable demand importer when importing debugger For reasons I can't explain (but likely have something to do with a combination of __import__ inferring default values for arguments and the demand importer mechanism further assuming defaults), the demand importer isn't playing well with IPython. Without this patch, we get a failure "ValueError: Attempted relative import in non-package" when attempting to import "IPython." The stack has numerous demandimport calls on it and adding "IPython" to the exclude list in demandimport isn't enough to make the problem go away, which means the issue is likely somewhere in the bowells of IPython. It's easier to just disable the demand importer when importing the debugger.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27495
58eb1c5bba58 contrib: add execute bit for fixpax.py
timeless <timeless@mozdev.org>
parents: 23940
diff changeset
     1
#!/usr/bin/env python
23940
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     2
# fixpax - fix ownership in bdist_mpkg output
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     3
#
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     4
# Copyright 2015 Matt Mackall <mpm@selenic.com>
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     5
#
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     7
# MIT license (http://opensource.org/licenses/MIT)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     8
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     9
"""Set file ownership to 0 in an Archive.pax.gz.
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    10
Suitable for fixing files bdist_mpkg output:
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    11
*.mpkg/Contents/Packages/*.pkg/Contents/Archive.pax.gz
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    12
"""
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    13
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    14
import sys, os, gzip
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    15
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    16
def fixpax(iname, oname):
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    17
    i = gzip.GzipFile(iname)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    18
    o = gzip.GzipFile(oname, "w")
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    19
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    20
    while True:
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    21
        magic = i.read(6)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    22
        dev = i.read(6)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    23
        ino = i.read(6)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    24
        mode = i.read(6)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    25
        i.read(6) # uid
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    26
        i.read(6) # gid
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    27
        nlink = i.read(6)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    28
        rdev = i.read(6)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    29
        mtime = i.read(11)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    30
        namesize = i.read(6)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    31
        filesize = i.read(11)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    32
        name = i.read(int(namesize, 8))
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    33
        data = i.read(int(filesize, 8))
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    34
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    35
        o.write(magic)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    36
        o.write(dev)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    37
        o.write(ino)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    38
        o.write(mode)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    39
        o.write("000000")
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    40
        o.write("000000")
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    41
        o.write(nlink)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    42
        o.write(rdev)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    43
        o.write(mtime)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    44
        o.write(namesize)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    45
        o.write(filesize)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    46
        o.write(name)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    47
        o.write(data)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    48
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    49
        if name.startswith("TRAILER!!!"):
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    50
            o.write(i.read())
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    51
            break
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    52
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    53
    o.close()
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    54
    i.close()
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    55
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    56
if __name__ == '__main__':
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    57
    for iname in sys.argv[1:]:
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    58
        print 'fixing file ownership in %s' % iname
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    59
        oname = sys.argv[1] + '.tmp'
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    60
        fixpax(iname, oname)
d0ef40776999 osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    61
        os.rename(oname, iname)