dmg-builder 26.4.1 → 26.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +0,0 @@
1
- from .core import build_dmg
2
-
3
- __version__ = "1.6.5"
4
-
5
- __all__ = ["__version__", "build_dmg"]
@@ -1,67 +0,0 @@
1
- #! /usr/bin/env python3
2
- import argparse
3
-
4
- from .core import build_dmg
5
-
6
-
7
- def main():
8
- parser = argparse.ArgumentParser(description="Construct a disk image file.")
9
- parser.add_argument(
10
- "volume_name",
11
- metavar="volume-name",
12
- help="The name to give to the volume (this will appear in the title bar when the user mounts the disk image).",
13
- )
14
- parser.add_argument(
15
- "filename",
16
- metavar="output.dmg",
17
- help="The filename of the disk image to create.",
18
- )
19
- parser.add_argument("-s", "--settings", help="The path of the settings file.")
20
- parser.add_argument(
21
- "-D",
22
- dest="defines",
23
- action="append",
24
- default=[],
25
- help="Define a value for the settings file (e.g. -Dfoo=bar).",
26
- )
27
- parser.add_argument(
28
- "--no-hidpi",
29
- dest="lookForHiDPI",
30
- action="store_false",
31
- default=True,
32
- help="Do not search for HiDPI versions of the background image (if specified)",
33
- )
34
- parser.add_argument(
35
- "--detach-retries",
36
- dest="detachRetries",
37
- type=int,
38
- default=5,
39
- choices=range(1, 31),
40
- help="Number of attempts to detach disk volume (1 sec. interval)",
41
- )
42
-
43
- args = parser.parse_args()
44
-
45
- defines = {}
46
- for d in args.defines:
47
- k, v = d.split("=", 1)
48
- k = k.strip()
49
- v = v.strip()
50
- if (v.startswith("'") and v.endswith("'")) or (
51
- v.startswith('"') and v.endswith('"')
52
- ):
53
- v = v[1:-1]
54
- defines[k] = v
55
-
56
- build_dmg(
57
- args.filename,
58
- args.volume_name,
59
- args.settings,
60
- defines=defines,
61
- lookForHiDPI=args.lookForHiDPI,
62
- detach_retries=args.detachRetries,
63
- )
64
-
65
-
66
- if __name__ == "__main__":
67
- main()
@@ -1,169 +0,0 @@
1
- import math
2
-
3
- from Quartz import (
4
- CFURLCreateWithFileSystemPath,
5
- CGBitmapContextCreate,
6
- CGBitmapContextCreateImage,
7
- CGColorSpaceCreateWithName,
8
- CGImageDestinationAddImage,
9
- CGImageDestinationCreateWithURL,
10
- CGImageDestinationFinalize,
11
- CGImageSourceCopyPropertiesAtIndex,
12
- CGImageSourceCreateImageAtIndex,
13
- CGImageSourceCreateWithURL,
14
- CGImageSourceGetCount,
15
- CIContext,
16
- CIFilter,
17
- CIImage,
18
- CIVector,
19
- NSAffineTransform,
20
- kCFURLPOSIXPathStyle,
21
- kCGColorSpaceGenericRGB,
22
- kCGImageAlphaPremultipliedLast,
23
- kCIInputAspectRatioKey,
24
- kCIInputBackgroundImageKey,
25
- kCIInputImageKey,
26
- kCIInputScaleKey,
27
- kCIOutputImageKey,
28
- )
29
-
30
- _REMOVABLE_DISK_PATH = (
31
- "/System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns"
32
- )
33
-
34
-
35
- def badge_disk_icon(badge_file, output_file):
36
- # Load the Removable disk icon
37
- url = CFURLCreateWithFileSystemPath(
38
- None, _REMOVABLE_DISK_PATH, kCFURLPOSIXPathStyle, False
39
- )
40
- backdrop = CGImageSourceCreateWithURL(url, None)
41
- backdropCount = CGImageSourceGetCount(backdrop)
42
-
43
- # Load the badge
44
- url = CFURLCreateWithFileSystemPath(None, badge_file, kCFURLPOSIXPathStyle, False)
45
- badge = CGImageSourceCreateWithURL(url, None)
46
- assert badge is not None, "Unable to process image file: %s" % badge_file
47
- badgeCount = CGImageSourceGetCount(badge)
48
-
49
- # Set up a destination for our target
50
- url = CFURLCreateWithFileSystemPath(None, output_file, kCFURLPOSIXPathStyle, False)
51
- target = CGImageDestinationCreateWithURL(url, "com.apple.icns", backdropCount, None)
52
-
53
- # Get the RGB colorspace
54
- rgbColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)
55
-
56
- # Scale
57
- scale = 1.0
58
-
59
- # Perspective transform
60
- corners = ((0.2, 0.95), (0.8, 0.95), (0.85, 0.35), (0.15, 0.35))
61
-
62
- # Translation
63
- position = (0.5, 0.5)
64
-
65
- for n in range(backdropCount):
66
- props = CGImageSourceCopyPropertiesAtIndex(backdrop, n, None)
67
- width = props["PixelWidth"]
68
- height = props["PixelHeight"]
69
- dpi = props["DPIWidth"]
70
- depth = props["Depth"]
71
-
72
- # Choose the best sized badge image
73
- bestWidth = None
74
- # ?? bestHeight = None
75
- bestBadge = None
76
- bestDepth = None
77
- # ?? bestDPI = None
78
- for m in range(badgeCount):
79
- badgeProps = CGImageSourceCopyPropertiesAtIndex(badge, m, None)
80
- badgeWidth = badgeProps["PixelWidth"]
81
- # ?? badgeHeight = badgeProps['PixelHeight']
82
- badgeDPI = badgeProps["DPIWidth"]
83
- badgeDepth = badgeProps["Depth"]
84
-
85
- if bestBadge is None or (
86
- badgeWidth <= width
87
- and (
88
- bestWidth > width
89
- or badgeWidth > bestWidth
90
- or (
91
- badgeWidth == bestWidth
92
- and badgeDPI == dpi
93
- and badgeDepth <= depth
94
- and (bestDepth is None or badgeDepth > bestDepth)
95
- )
96
- )
97
- ):
98
- bestBadge = m
99
- bestWidth = badgeWidth
100
- # ?? bestHeight = badgeHeight
101
- # ?? bestDPI = badgeDPI
102
- bestDepth = badgeDepth
103
-
104
- badgeImage = CGImageSourceCreateImageAtIndex(badge, bestBadge, None)
105
- badgeCI = CIImage.imageWithCGImage_(badgeImage)
106
-
107
- backgroundImage = CGImageSourceCreateImageAtIndex(backdrop, n, None)
108
- backgroundCI = CIImage.imageWithCGImage_(backgroundImage)
109
-
110
- compositor = CIFilter.filterWithName_("CISourceOverCompositing")
111
- lanczos = CIFilter.filterWithName_("CILanczosScaleTransform")
112
- perspective = CIFilter.filterWithName_("CIPerspectiveTransform")
113
- transform = CIFilter.filterWithName_("CIAffineTransform")
114
-
115
- lanczos.setValue_forKey_(badgeCI, kCIInputImageKey)
116
- lanczos.setValue_forKey_(scale * float(width) / bestWidth, kCIInputScaleKey)
117
- lanczos.setValue_forKey_(1.0, kCIInputAspectRatioKey)
118
-
119
- topLeft = (width * scale * corners[0][0], width * scale * corners[0][1])
120
- topRight = (width * scale * corners[1][0], width * scale * corners[1][1])
121
- bottomRight = (width * scale * corners[2][0], width * scale * corners[2][1])
122
- bottomLeft = (width * scale * corners[3][0], width * scale * corners[3][1])
123
-
124
- out = lanczos.valueForKey_(kCIOutputImageKey)
125
- if width >= 16:
126
- perspective.setValue_forKey_(out, kCIInputImageKey)
127
- perspective.setValue_forKey_(
128
- CIVector.vectorWithX_Y_(*topLeft), "inputTopLeft"
129
- )
130
- perspective.setValue_forKey_(
131
- CIVector.vectorWithX_Y_(*topRight), "inputTopRight"
132
- )
133
- perspective.setValue_forKey_(
134
- CIVector.vectorWithX_Y_(*bottomRight), "inputBottomRight"
135
- )
136
- perspective.setValue_forKey_(
137
- CIVector.vectorWithX_Y_(*bottomLeft), "inputBottomLeft"
138
- )
139
- out = perspective.valueForKey_(kCIOutputImageKey)
140
-
141
- tfm = NSAffineTransform.transform()
142
- tfm.translateXBy_yBy_(
143
- math.floor((position[0] - 0.5 * scale) * width),
144
- math.floor((position[1] - 0.5 * scale) * height),
145
- )
146
-
147
- transform.setValue_forKey_(out, kCIInputImageKey)
148
- transform.setValue_forKey_(tfm, "inputTransform")
149
- out = transform.valueForKey_(kCIOutputImageKey)
150
-
151
- compositor.setValue_forKey_(out, kCIInputImageKey)
152
- compositor.setValue_forKey_(backgroundCI, kCIInputBackgroundImageKey)
153
-
154
- result = compositor.valueForKey_(kCIOutputImageKey)
155
-
156
- cgContext = CGBitmapContextCreate(
157
- None, width, height, 8, 0, rgbColorSpace, kCGImageAlphaPremultipliedLast
158
- )
159
- context = CIContext.contextWithCGContext_options_(cgContext, None)
160
-
161
- context.drawImage_inRect_fromRect_(
162
- result, ((0, 0), (width, height)), ((0, 0), (width, height))
163
- )
164
-
165
- image = CGBitmapContextCreateImage(cgContext)
166
-
167
- CGImageDestinationAddImage(target, image, props)
168
-
169
- CGImageDestinationFinalize(target)