Changeset View
Changeset View
Standalone View
Standalone View
tools/create_dmg/create.py
- This file was added.
1 | #!/usr/bin/env python | ||||
---|---|---|---|---|---|
2 | | ||||
nienhueser: Please add the typical license header, see e.g. https://cgit.kde.org/marble. | |||||
nienhueser: Should by python, not Python | |||||
3 | import sys, os, tempfile, subprocess, argparse, shutil | ||||
4 | | ||||
5 | # | ||||
6 | # This file is part of the Marble Virtual Globe. | ||||
7 | # | ||||
8 | # This program is free software licensed under the GNU LGPL. You can | ||||
9 | # find a copy of this license in LICENSE.txt in the top directory of | ||||
whitegeorge: I need to get this from CMake. | |||||
10 | # the source code. | ||||
11 | # | ||||
12 | # Copyright 2016 George White <george@gwhite.me> | ||||
13 | # | ||||
14 | | ||||
15 | VERSION = "1.14.0" | ||||
16 | SCRIPT_ROOT = os.path.dirname(os.path.abspath(__file__)) | ||||
17 | TREE_ROOT = os.path.abspath(os.path.join(SCRIPT_ROOT, "..", "..")) | ||||
18 | | ||||
19 | DMG_ROOT = tempfile.mkdtemp() | ||||
20 | DMG_APP = os.path.abspath("Marble.app") | ||||
21 | DMG_BACKGROUND = os.path.join(SCRIPT_ROOT, "background.jpg") | ||||
22 | DMG_OUT = os.path.join(BUILD_DIR, "marble-{}.dmg".format(VERSION)) | ||||
23 | | ||||
24 | HDIUTIL = os.getenv("HDIUTIL", "hdiutil") | ||||
25 | OSASCRIPT = os.getenv("OSASCRIPT", "osascript") | ||||
26 | | ||||
27 | def package_dmg(root=DMG_ROOT, app=DMG_APP, background=DMG_BACKGROUND, | ||||
28 | out=DMG_OUT): | ||||
29 | marble = os.path.join(root, "Marble") | ||||
30 | os.mkdir(marble) | ||||
31 | | ||||
32 | if not os.path.exists(app): | ||||
33 | print("{} doesn't exist!".format(app)) | ||||
34 | sys.exit(1) | ||||
35 | | ||||
36 | # Copy the app to be placed in the disk into `Marble' as `Marble.app'. | ||||
37 | shutil.copytree(app, os.path.join(marble, "Marble.app")) | ||||
38 | | ||||
39 | # Create a template image. | ||||
shutil.copytree seems better, see https://docs.python.org/3.5/library/shutil.html nienhueser: shutil.copytree seems better, see https://docs.python.org/3.5/library/shutil.html | |||||
40 | template = os.path.join(root, "template.dmg") | ||||
41 | print("\n-- Create template: " + template) | ||||
42 | subprocess.call([HDIUTIL, "create", template, "-srcfolder", marble, | ||||
43 | "-volname", "Marble", "-format", "UDRW", "-size", | ||||
44 | "100m"]) | ||||
45 | subprocess.call([HDIUTIL, "attach", template]) | ||||
46 | | ||||
47 | # Add the `hidden' folder | ||||
48 | hidden = os.path.join(marble, "hidden") | ||||
49 | os.mkdir(hidden) | ||||
50 | shutil.copyfile(os.path.join(SCRIPT_ROOT, "background.jpg"), | ||||
51 | os.path.join(hidden, "background.jpg")) | ||||
52 | | ||||
nienhueser: Please use shutil.copyfile | |||||
53 | # Run the prepare script. | ||||
54 | prepare = os.path.join(SCRIPT_ROOT, "prepare.scpt") | ||||
55 | print("\n-- Execute osascript: " + prepare) | ||||
56 | subprocess.call([OSASCRIPT, prepare]) | ||||
57 | | ||||
58 | # Let the disk eject. | ||||
59 | subprocess.call([HDIUTIL, "detach", template]) | ||||
60 | | ||||
61 | # Convert it to read-write, compressed, and save it to `out'. | ||||
62 | subprocess.call([HDIUTIL, "convert", "-format", "UDBZ", "-o", | ||||
63 | out, template]) | ||||
64 | | ||||
65 | print("DMG: " + out + "\n") | ||||
66 | shutil.rmtree(marble) | ||||
67 | | ||||
68 | if __name__ == "__main__": | ||||
nienhueser: Please use shutil.rmtree | |||||
69 | d = dict() | ||||
70 | | ||||
71 | parser = argparse.ArgumentParser() | ||||
72 | parser.add_argument("-i", "--app", | ||||
73 | help="The app to insert in to the new DMG.") | ||||
74 | parser.add_argument("-o", "--out", | ||||
nienhueser: Please add a help entry also, same below. | |||||
75 | help="The path to the new DMG.") | ||||
76 | args = parser.parse_args() | ||||
77 | | ||||
78 | if args.app: | ||||
79 | d["app"] = args.app | ||||
80 | | ||||
81 | if args.out: | ||||
82 | d["out"] = args.out | ||||
83 | | ||||
84 | package_dmg(**d) |
Please add the typical license header, see e.g. https://cgit.kde.org/marble.git/tree/tools/vectortilecreator/vectortilecreator.py and your name and mail address as author.