Changeset View
Changeset View
Standalone View
Standalone View
tools/create_dmg/create.py
- This file was added.
1 | #!/usr/bin/env Python | ||||
---|---|---|---|---|---|
nienhueser: Should by python, not Python | |||||
2 | | ||||
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. nienhueser: Please add the typical license header, see e.g. https://cgit.kde.org/marble. | |||||
3 | import sys, os, tempfile, subprocess, time, 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_BACKGROUND = os.path.join(SCRIPT_ROOT, "background.jpg") | ||||
21 | DMG_OUT = os.path.join(BUILD_DIR, "marble-{}.dmg".format(VERSION)) | ||||
22 | | ||||
23 | HDIUTIL = os.getenv("HDIUTIL", "hdiutil") | ||||
24 | OSASCRIPT = os.getenv("OSASCRIPT", "osascript") | ||||
25 | | ||||
26 | def package_dmg(root=DMG_ROOT, app=DMG_APP, background=DMG_BACKGROUND, | ||||
27 | out=DMG_OUT): | ||||
28 | marble = os.path.join(root, "Marble") | ||||
29 | os.mkdir(marble) | ||||
30 | | ||||
31 | if not os.path.exists(app): | ||||
32 | print("{} doesn't exist!".format(app)) | ||||
33 | sys.exit(1) | ||||
34 | | ||||
35 | # Copy every file to be placed in the disk into `Marble'. | ||||
36 | shutil.copytree(app, marble) | ||||
37 | | ||||
38 | # Create a template image. | ||||
39 | template = os.path.join(root, "template.dmg") | ||||
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 | print("\n-- Create template: " + template) | ||||
41 | subprocess.call([HDIUTIL, "create", template, "-srcfolder", marble, | ||||
42 | "-volname", "Marble", "-format", "UDRW", "-size", | ||||
43 | "100m"]) | ||||
44 | subprocess.call([HDIUTIL, "attach", template]) | ||||
45 | | ||||
46 | # Add the `hidden' folder | ||||
47 | hidden = os.path.join(marble, "hidden") | ||||
48 | os.mkdir(hidden) | ||||
49 | shutil.copyfile(os.path.join(SCRIPT_ROOT, "background.jpg"), | ||||
50 | os.path.join(hidden, "background.jpg")) | ||||
51 | | ||||
52 | # Run the prepare script. | ||||
nienhueser: Please use shutil.copyfile | |||||
53 | prepare = os.path.join(SCRIPT_ROOT, "prepare.scpt") | ||||
54 | print("\n-- Execute osascript: " + prepare) | ||||
55 | subprocess.call([OSASCRIPT, prepare]) | ||||
56 | | ||||
57 | # Let the disk eject. | ||||
58 | subprocess.call([HDIUTIL, "detach", template]) | ||||
59 | | ||||
60 | # Convert it to read-write, compressed, and save it to `out'. | ||||
61 | subprocess.call([HDIUTIL, "convert", "-format", "UDBZ", "-o", | ||||
62 | out, template]) | ||||
63 | | ||||
64 | print("DMG: " + out + "\n") | ||||
65 | shutil.rmtree(marble) | ||||
66 | | ||||
67 | if __name__ == "__main__": | ||||
68 | d = dict() | ||||
nienhueser: Please use shutil.rmtree | |||||
69 | | ||||
70 | parser = argparse.ArgumentParser() | ||||
71 | parser.add_argument("-i", "--app", | ||||
72 | help="The app to insert in to the new DMG.") | ||||
73 | parser.add_argument("-o", "--out", | ||||
74 | help="The path to the new DMG.") | ||||
nienhueser: Please add a help entry also, same below. | |||||
75 | args = parser.parse_args() | ||||
76 | | ||||
77 | if args.app: | ||||
78 | d["app"] = args.app | ||||
79 | | ||||
80 | if args.out: | ||||
81 | d["out"] = args.out | ||||
82 | | ||||
83 | package_dmg(**d) |
Should by python, not Python