summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/action/unpack_dmg.py
blob: 74e4091549a61f05605d1385f7ef8d48258e5d63 (plain)
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse
import sys
from pathlib import Path

from mozpack import dmg

from mozbuild.bootstrap import bootstrap_toolchain


def _path_or_none(input: str):
    if not input:
        return None
    return Path(input)


def main(args):
    parser = argparse.ArgumentParser(
        description="Explode a DMG into its relevant files"
    )

    parser.add_argument("--dsstore", help="DSStore file from")
    parser.add_argument("--background", help="Background file from")
    parser.add_argument("--icon", help="Icon file from")

    parser.add_argument("dmgfile", metavar="DMG_IN", help="DMG File to Unpack")
    parser.add_argument(
        "outpath", metavar="PATH_OUT", help="Location to put unpacked files"
    )

    options = parser.parse_args(args)

    dmg_tool = bootstrap_toolchain("dmg/dmg")
    hfs_tool = bootstrap_toolchain("dmg/hfsplus")

    dmg.extract_dmg(
        dmgfile=Path(options.dmgfile),
        output=Path(options.outpath),
        dmg_tool=Path(dmg_tool),
        hfs_tool=Path(hfs_tool),
        dsstore=_path_or_none(options.dsstore),
        background=_path_or_none(options.background),
        icon=_path_or_none(options.icon),
    )
    return 0


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))