wsba-hockey 1.0.2__py3-none-any.whl → 1.0.4__py3-none-any.whl

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.
Files changed (130) hide show
  1. wsba_hockey/data_pipelines.py +183 -0
  2. wsba_hockey/evidence/weakside-breakout/node_modules/duckdb/vendor.py +146 -0
  3. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/flatted.py +149 -0
  4. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/test.py +63 -0
  5. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  6. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  7. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  8. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  9. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  10. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  11. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  12. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  13. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  14. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +690 -0
  15. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common.py +661 -0
  16. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  17. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  18. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  19. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  20. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  21. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  22. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  23. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  24. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  25. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  26. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  27. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  28. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  29. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2714 -0
  30. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3981 -0
  31. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  32. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  33. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  34. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  35. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  36. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input.py +3130 -0
  37. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  38. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  39. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  40. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  41. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  42. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  43. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  44. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  45. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  46. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  47. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  48. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  49. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  50. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  51. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  52. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  53. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/update-gyp.py +64 -0
  54. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  55. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  56. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  57. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  58. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  59. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  60. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  61. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  62. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  63. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +666 -0
  64. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common.py +654 -0
  65. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  66. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  67. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  68. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  69. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  70. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  71. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  72. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  73. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  74. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  75. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  76. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  77. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  78. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2518 -0
  79. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3978 -0
  80. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  81. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  82. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  83. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  84. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  85. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input.py +3137 -0
  86. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  87. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  88. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  89. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  90. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  91. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  92. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  93. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  94. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  95. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  96. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/setup.py +42 -0
  97. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  98. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  99. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  100. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  101. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  102. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  103. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/update-gyp.py +46 -0
  104. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/app.py +401 -0
  105. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/name_fix.py +47 -0
  106. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/app.py +108 -0
  107. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/plot.py +93 -0
  108. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/rink_plot.py +245 -0
  109. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/app.py +145 -0
  110. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/plot.py +77 -0
  111. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/rink_plot.py +245 -0
  112. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/app.py +389 -0
  113. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/plot.py +70 -0
  114. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/rink_plot.py +245 -0
  115. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/app.py +110 -0
  116. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/plot.py +58 -0
  117. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/rink_plot.py +245 -0
  118. wsba_hockey/tools/agg.py +242 -53
  119. wsba_hockey/tools/plotting.py +15 -20
  120. wsba_hockey/tools/scraping.py +149 -258
  121. wsba_hockey/tools/xg_model.py +370 -298
  122. wsba_hockey/workspace.py +22 -101
  123. wsba_hockey/wsba_main.py +494 -147
  124. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/METADATA +2 -2
  125. wsba_hockey-1.0.4.dist-info/RECORD +135 -0
  126. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/WHEEL +1 -1
  127. wsba_hockey/stats/calculate_viz/shot_impact.py +0 -2
  128. wsba_hockey-1.0.2.dist-info/RECORD +0 -19
  129. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/licenses/LICENSE +0 -0
  130. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,771 @@
1
+ #!/usr/bin/env python3
2
+ # Copyright (c) 2012 Google Inc. All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be
4
+ # found in the LICENSE file.
5
+
6
+ """Utility functions to perform Xcode-style build steps.
7
+
8
+ These functions are executed via gyp-mac-tool when using the Makefile generator.
9
+ """
10
+
11
+
12
+ import fcntl
13
+ import fnmatch
14
+ import glob
15
+ import json
16
+ import os
17
+ import plistlib
18
+ import re
19
+ import shutil
20
+ import struct
21
+ import subprocess
22
+ import sys
23
+ import tempfile
24
+
25
+
26
+ def main(args):
27
+ executor = MacTool()
28
+ exit_code = executor.Dispatch(args)
29
+ if exit_code is not None:
30
+ sys.exit(exit_code)
31
+
32
+
33
+ class MacTool:
34
+ """This class performs all the Mac tooling steps. The methods can either be
35
+ executed directly, or dispatched from an argument list."""
36
+
37
+ def Dispatch(self, args):
38
+ """Dispatches a string command to a method."""
39
+ if len(args) < 1:
40
+ raise Exception("Not enough arguments")
41
+
42
+ method = "Exec%s" % self._CommandifyName(args[0])
43
+ return getattr(self, method)(*args[1:])
44
+
45
+ def _CommandifyName(self, name_string):
46
+ """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
47
+ return name_string.title().replace("-", "")
48
+
49
+ def ExecCopyBundleResource(self, source, dest, convert_to_binary):
50
+ """Copies a resource file to the bundle/Resources directory, performing any
51
+ necessary compilation on each resource."""
52
+ convert_to_binary = convert_to_binary == "True"
53
+ extension = os.path.splitext(source)[1].lower()
54
+ if os.path.isdir(source):
55
+ # Copy tree.
56
+ # TODO(thakis): This copies file attributes like mtime, while the
57
+ # single-file branch below doesn't. This should probably be changed to
58
+ # be consistent with the single-file branch.
59
+ if os.path.exists(dest):
60
+ shutil.rmtree(dest)
61
+ shutil.copytree(source, dest)
62
+ elif extension == ".xib":
63
+ return self._CopyXIBFile(source, dest)
64
+ elif extension == ".storyboard":
65
+ return self._CopyXIBFile(source, dest)
66
+ elif extension == ".strings" and not convert_to_binary:
67
+ self._CopyStringsFile(source, dest)
68
+ else:
69
+ if os.path.exists(dest):
70
+ os.unlink(dest)
71
+ shutil.copy(source, dest)
72
+
73
+ if convert_to_binary and extension in (".plist", ".strings"):
74
+ self._ConvertToBinary(dest)
75
+
76
+ def _CopyXIBFile(self, source, dest):
77
+ """Compiles a XIB file with ibtool into a binary plist in the bundle."""
78
+
79
+ # ibtool sometimes crashes with relative paths. See crbug.com/314728.
80
+ base = os.path.dirname(os.path.realpath(__file__))
81
+ if os.path.relpath(source):
82
+ source = os.path.join(base, source)
83
+ if os.path.relpath(dest):
84
+ dest = os.path.join(base, dest)
85
+
86
+ args = ["xcrun", "ibtool", "--errors", "--warnings", "--notices"]
87
+
88
+ if os.environ["XCODE_VERSION_ACTUAL"] > "0700":
89
+ args.extend(["--auto-activate-custom-fonts"])
90
+ if "IPHONEOS_DEPLOYMENT_TARGET" in os.environ:
91
+ args.extend(
92
+ [
93
+ "--target-device",
94
+ "iphone",
95
+ "--target-device",
96
+ "ipad",
97
+ "--minimum-deployment-target",
98
+ os.environ["IPHONEOS_DEPLOYMENT_TARGET"],
99
+ ]
100
+ )
101
+ else:
102
+ args.extend(
103
+ [
104
+ "--target-device",
105
+ "mac",
106
+ "--minimum-deployment-target",
107
+ os.environ["MACOSX_DEPLOYMENT_TARGET"],
108
+ ]
109
+ )
110
+
111
+ args.extend(
112
+ ["--output-format", "human-readable-text", "--compile", dest, source]
113
+ )
114
+
115
+ ibtool_section_re = re.compile(r"/\*.*\*/")
116
+ ibtool_re = re.compile(r".*note:.*is clipping its content")
117
+ try:
118
+ stdout = subprocess.check_output(args)
119
+ except subprocess.CalledProcessError as e:
120
+ print(e.output)
121
+ raise
122
+ current_section_header = None
123
+ for line in stdout.splitlines():
124
+ if ibtool_section_re.match(line):
125
+ current_section_header = line
126
+ elif not ibtool_re.match(line):
127
+ if current_section_header:
128
+ print(current_section_header)
129
+ current_section_header = None
130
+ print(line)
131
+ return 0
132
+
133
+ def _ConvertToBinary(self, dest):
134
+ subprocess.check_call(
135
+ ["xcrun", "plutil", "-convert", "binary1", "-o", dest, dest]
136
+ )
137
+
138
+ def _CopyStringsFile(self, source, dest):
139
+ """Copies a .strings file using iconv to reconvert the input into UTF-16."""
140
+ input_code = self._DetectInputEncoding(source) or "UTF-8"
141
+
142
+ # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call
143
+ # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints
144
+ # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing
145
+ # semicolon in dictionary.
146
+ # on invalid files. Do the same kind of validation.
147
+ import CoreFoundation
148
+
149
+ with open(source, "rb") as in_file:
150
+ s = in_file.read()
151
+ d = CoreFoundation.CFDataCreate(None, s, len(s))
152
+ _, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None)
153
+ if error:
154
+ return
155
+
156
+ with open(dest, "wb") as fp:
157
+ fp.write(s.decode(input_code).encode("UTF-16"))
158
+
159
+ def _DetectInputEncoding(self, file_name):
160
+ """Reads the first few bytes from file_name and tries to guess the text
161
+ encoding. Returns None as a guess if it can't detect it."""
162
+ with open(file_name, "rb") as fp:
163
+ try:
164
+ header = fp.read(3)
165
+ except Exception:
166
+ return None
167
+ if header.startswith(b"\xFE\xFF"):
168
+ return "UTF-16"
169
+ elif header.startswith(b"\xFF\xFE"):
170
+ return "UTF-16"
171
+ elif header.startswith(b"\xEF\xBB\xBF"):
172
+ return "UTF-8"
173
+ else:
174
+ return None
175
+
176
+ def ExecCopyInfoPlist(self, source, dest, convert_to_binary, *keys):
177
+ """Copies the |source| Info.plist to the destination directory |dest|."""
178
+ # Read the source Info.plist into memory.
179
+ with open(source) as fd:
180
+ lines = fd.read()
181
+
182
+ # Insert synthesized key/value pairs (e.g. BuildMachineOSBuild).
183
+ plist = plistlib.readPlistFromString(lines)
184
+ if keys:
185
+ plist.update(json.loads(keys[0]))
186
+ lines = plistlib.writePlistToString(plist)
187
+
188
+ # Go through all the environment variables and replace them as variables in
189
+ # the file.
190
+ IDENT_RE = re.compile(r"[_/\s]")
191
+ for key in os.environ:
192
+ if key.startswith("_"):
193
+ continue
194
+ evar = "${%s}" % key
195
+ evalue = os.environ[key]
196
+ lines = lines.replace(lines, evar, evalue)
197
+
198
+ # Xcode supports various suffices on environment variables, which are
199
+ # all undocumented. :rfc1034identifier is used in the standard project
200
+ # template these days, and :identifier was used earlier. They are used to
201
+ # convert non-url characters into things that look like valid urls --
202
+ # except that the replacement character for :identifier, '_' isn't valid
203
+ # in a URL either -- oops, hence :rfc1034identifier was born.
204
+ evar = "${%s:identifier}" % key
205
+ evalue = IDENT_RE.sub("_", os.environ[key])
206
+ lines = lines.replace(lines, evar, evalue)
207
+
208
+ evar = "${%s:rfc1034identifier}" % key
209
+ evalue = IDENT_RE.sub("-", os.environ[key])
210
+ lines = lines.replace(lines, evar, evalue)
211
+
212
+ # Remove any keys with values that haven't been replaced.
213
+ lines = lines.splitlines()
214
+ for i in range(len(lines)):
215
+ if lines[i].strip().startswith("<string>${"):
216
+ lines[i] = None
217
+ lines[i - 1] = None
218
+ lines = "\n".join(line for line in lines if line is not None)
219
+
220
+ # Write out the file with variables replaced.
221
+ with open(dest, "w") as fd:
222
+ fd.write(lines)
223
+
224
+ # Now write out PkgInfo file now that the Info.plist file has been
225
+ # "compiled".
226
+ self._WritePkgInfo(dest)
227
+
228
+ if convert_to_binary == "True":
229
+ self._ConvertToBinary(dest)
230
+
231
+ def _WritePkgInfo(self, info_plist):
232
+ """This writes the PkgInfo file from the data stored in Info.plist."""
233
+ plist = plistlib.readPlist(info_plist)
234
+ if not plist:
235
+ return
236
+
237
+ # Only create PkgInfo for executable types.
238
+ package_type = plist["CFBundlePackageType"]
239
+ if package_type != "APPL":
240
+ return
241
+
242
+ # The format of PkgInfo is eight characters, representing the bundle type
243
+ # and bundle signature, each four characters. If that is missing, four
244
+ # '?' characters are used instead.
245
+ signature_code = plist.get("CFBundleSignature", "????")
246
+ if len(signature_code) != 4: # Wrong length resets everything, too.
247
+ signature_code = "?" * 4
248
+
249
+ dest = os.path.join(os.path.dirname(info_plist), "PkgInfo")
250
+ with open(dest, "w") as fp:
251
+ fp.write(f"{package_type}{signature_code}")
252
+
253
+ def ExecFlock(self, lockfile, *cmd_list):
254
+ """Emulates the most basic behavior of Linux's flock(1)."""
255
+ # Rely on exception handling to report errors.
256
+ fd = os.open(lockfile, os.O_RDONLY | os.O_NOCTTY | os.O_CREAT, 0o666)
257
+ fcntl.flock(fd, fcntl.LOCK_EX)
258
+ return subprocess.call(cmd_list)
259
+
260
+ def ExecFilterLibtool(self, *cmd_list):
261
+ """Calls libtool and filters out '/path/to/libtool: file: foo.o has no
262
+ symbols'."""
263
+ libtool_re = re.compile(
264
+ r"^.*libtool: (?:for architecture: \S* )?" r"file: .* has no symbols$"
265
+ )
266
+ libtool_re5 = re.compile(
267
+ r"^.*libtool: warning for library: "
268
+ + r".* the table of contents is empty "
269
+ + r"\(no object file members in the library define global symbols\)$"
270
+ )
271
+ env = os.environ.copy()
272
+ # Ref:
273
+ # http://www.opensource.apple.com/source/cctools/cctools-809/misc/libtool.c
274
+ # The problem with this flag is that it resets the file mtime on the file to
275
+ # epoch=0, e.g. 1970-1-1 or 1969-12-31 depending on timezone.
276
+ env["ZERO_AR_DATE"] = "1"
277
+ libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
278
+ err = libtoolout.communicate()[1].decode("utf-8")
279
+ for line in err.splitlines():
280
+ if not libtool_re.match(line) and not libtool_re5.match(line):
281
+ print(line, file=sys.stderr)
282
+ # Unconditionally touch the output .a file on the command line if present
283
+ # and the command succeeded. A bit hacky.
284
+ if not libtoolout.returncode:
285
+ for i in range(len(cmd_list) - 1):
286
+ if cmd_list[i] == "-o" and cmd_list[i + 1].endswith(".a"):
287
+ os.utime(cmd_list[i + 1], None)
288
+ break
289
+ return libtoolout.returncode
290
+
291
+ def ExecPackageIosFramework(self, framework):
292
+ # Find the name of the binary based on the part before the ".framework".
293
+ binary = os.path.basename(framework).split(".")[0]
294
+ module_path = os.path.join(framework, "Modules")
295
+ if not os.path.exists(module_path):
296
+ os.mkdir(module_path)
297
+ module_template = (
298
+ "framework module %s {\n"
299
+ ' umbrella header "%s.h"\n'
300
+ "\n"
301
+ " export *\n"
302
+ " module * { export * }\n"
303
+ "}\n" % (binary, binary)
304
+ )
305
+
306
+ with open(os.path.join(module_path, "module.modulemap"), "w") as module_file:
307
+ module_file.write(module_template)
308
+
309
+ def ExecPackageFramework(self, framework, version):
310
+ """Takes a path to Something.framework and the Current version of that and
311
+ sets up all the symlinks."""
312
+ # Find the name of the binary based on the part before the ".framework".
313
+ binary = os.path.basename(framework).split(".")[0]
314
+
315
+ CURRENT = "Current"
316
+ RESOURCES = "Resources"
317
+ VERSIONS = "Versions"
318
+
319
+ if not os.path.exists(os.path.join(framework, VERSIONS, version, binary)):
320
+ # Binary-less frameworks don't seem to contain symlinks (see e.g.
321
+ # chromium's out/Debug/org.chromium.Chromium.manifest/ bundle).
322
+ return
323
+
324
+ # Move into the framework directory to set the symlinks correctly.
325
+ pwd = os.getcwd()
326
+ os.chdir(framework)
327
+
328
+ # Set up the Current version.
329
+ self._Relink(version, os.path.join(VERSIONS, CURRENT))
330
+
331
+ # Set up the root symlinks.
332
+ self._Relink(os.path.join(VERSIONS, CURRENT, binary), binary)
333
+ self._Relink(os.path.join(VERSIONS, CURRENT, RESOURCES), RESOURCES)
334
+
335
+ # Back to where we were before!
336
+ os.chdir(pwd)
337
+
338
+ def _Relink(self, dest, link):
339
+ """Creates a symlink to |dest| named |link|. If |link| already exists,
340
+ it is overwritten."""
341
+ if os.path.lexists(link):
342
+ os.remove(link)
343
+ os.symlink(dest, link)
344
+
345
+ def ExecCompileIosFrameworkHeaderMap(self, out, framework, *all_headers):
346
+ framework_name = os.path.basename(framework).split(".")[0]
347
+ all_headers = [os.path.abspath(header) for header in all_headers]
348
+ filelist = {}
349
+ for header in all_headers:
350
+ filename = os.path.basename(header)
351
+ filelist[filename] = header
352
+ filelist[os.path.join(framework_name, filename)] = header
353
+ WriteHmap(out, filelist)
354
+
355
+ def ExecCopyIosFrameworkHeaders(self, framework, *copy_headers):
356
+ header_path = os.path.join(framework, "Headers")
357
+ if not os.path.exists(header_path):
358
+ os.makedirs(header_path)
359
+ for header in copy_headers:
360
+ shutil.copy(header, os.path.join(header_path, os.path.basename(header)))
361
+
362
+ def ExecCompileXcassets(self, keys, *inputs):
363
+ """Compiles multiple .xcassets files into a single .car file.
364
+
365
+ This invokes 'actool' to compile all the inputs .xcassets files. The
366
+ |keys| arguments is a json-encoded dictionary of extra arguments to
367
+ pass to 'actool' when the asset catalogs contains an application icon
368
+ or a launch image.
369
+
370
+ Note that 'actool' does not create the Assets.car file if the asset
371
+ catalogs does not contains imageset.
372
+ """
373
+ command_line = [
374
+ "xcrun",
375
+ "actool",
376
+ "--output-format",
377
+ "human-readable-text",
378
+ "--compress-pngs",
379
+ "--notices",
380
+ "--warnings",
381
+ "--errors",
382
+ ]
383
+ is_iphone_target = "IPHONEOS_DEPLOYMENT_TARGET" in os.environ
384
+ if is_iphone_target:
385
+ platform = os.environ["CONFIGURATION"].split("-")[-1]
386
+ if platform not in ("iphoneos", "iphonesimulator"):
387
+ platform = "iphonesimulator"
388
+ command_line.extend(
389
+ [
390
+ "--platform",
391
+ platform,
392
+ "--target-device",
393
+ "iphone",
394
+ "--target-device",
395
+ "ipad",
396
+ "--minimum-deployment-target",
397
+ os.environ["IPHONEOS_DEPLOYMENT_TARGET"],
398
+ "--compile",
399
+ os.path.abspath(os.environ["CONTENTS_FOLDER_PATH"]),
400
+ ]
401
+ )
402
+ else:
403
+ command_line.extend(
404
+ [
405
+ "--platform",
406
+ "macosx",
407
+ "--target-device",
408
+ "mac",
409
+ "--minimum-deployment-target",
410
+ os.environ["MACOSX_DEPLOYMENT_TARGET"],
411
+ "--compile",
412
+ os.path.abspath(os.environ["UNLOCALIZED_RESOURCES_FOLDER_PATH"]),
413
+ ]
414
+ )
415
+ if keys:
416
+ keys = json.loads(keys)
417
+ for key, value in keys.items():
418
+ arg_name = "--" + key
419
+ if isinstance(value, bool):
420
+ if value:
421
+ command_line.append(arg_name)
422
+ elif isinstance(value, list):
423
+ for v in value:
424
+ command_line.append(arg_name)
425
+ command_line.append(str(v))
426
+ else:
427
+ command_line.append(arg_name)
428
+ command_line.append(str(value))
429
+ # Note: actool crashes if inputs path are relative, so use os.path.abspath
430
+ # to get absolute path name for inputs.
431
+ command_line.extend(map(os.path.abspath, inputs))
432
+ subprocess.check_call(command_line)
433
+
434
+ def ExecMergeInfoPlist(self, output, *inputs):
435
+ """Merge multiple .plist files into a single .plist file."""
436
+ merged_plist = {}
437
+ for path in inputs:
438
+ plist = self._LoadPlistMaybeBinary(path)
439
+ self._MergePlist(merged_plist, plist)
440
+ plistlib.writePlist(merged_plist, output)
441
+
442
+ def ExecCodeSignBundle(self, key, entitlements, provisioning, path, preserve):
443
+ """Code sign a bundle.
444
+
445
+ This function tries to code sign an iOS bundle, following the same
446
+ algorithm as Xcode:
447
+ 1. pick the provisioning profile that best match the bundle identifier,
448
+ and copy it into the bundle as embedded.mobileprovision,
449
+ 2. copy Entitlements.plist from user or SDK next to the bundle,
450
+ 3. code sign the bundle.
451
+ """
452
+ substitutions, overrides = self._InstallProvisioningProfile(
453
+ provisioning, self._GetCFBundleIdentifier()
454
+ )
455
+ entitlements_path = self._InstallEntitlements(
456
+ entitlements, substitutions, overrides
457
+ )
458
+
459
+ args = ["codesign", "--force", "--sign", key]
460
+ if preserve == "True":
461
+ args.extend(["--deep", "--preserve-metadata=identifier,entitlements"])
462
+ else:
463
+ args.extend(["--entitlements", entitlements_path])
464
+ args.extend(["--timestamp=none", path])
465
+ subprocess.check_call(args)
466
+
467
+ def _InstallProvisioningProfile(self, profile, bundle_identifier):
468
+ """Installs embedded.mobileprovision into the bundle.
469
+
470
+ Args:
471
+ profile: string, optional, short name of the .mobileprovision file
472
+ to use, if empty or the file is missing, the best file installed
473
+ will be used
474
+ bundle_identifier: string, value of CFBundleIdentifier from Info.plist
475
+
476
+ Returns:
477
+ A tuple containing two dictionary: variables substitutions and values
478
+ to overrides when generating the entitlements file.
479
+ """
480
+ source_path, provisioning_data, team_id = self._FindProvisioningProfile(
481
+ profile, bundle_identifier
482
+ )
483
+ target_path = os.path.join(
484
+ os.environ["BUILT_PRODUCTS_DIR"],
485
+ os.environ["CONTENTS_FOLDER_PATH"],
486
+ "embedded.mobileprovision",
487
+ )
488
+ shutil.copy2(source_path, target_path)
489
+ substitutions = self._GetSubstitutions(bundle_identifier, team_id + ".")
490
+ return substitutions, provisioning_data["Entitlements"]
491
+
492
+ def _FindProvisioningProfile(self, profile, bundle_identifier):
493
+ """Finds the .mobileprovision file to use for signing the bundle.
494
+
495
+ Checks all the installed provisioning profiles (or if the user specified
496
+ the PROVISIONING_PROFILE variable, only consult it) and select the most
497
+ specific that correspond to the bundle identifier.
498
+
499
+ Args:
500
+ profile: string, optional, short name of the .mobileprovision file
501
+ to use, if empty or the file is missing, the best file installed
502
+ will be used
503
+ bundle_identifier: string, value of CFBundleIdentifier from Info.plist
504
+
505
+ Returns:
506
+ A tuple of the path to the selected provisioning profile, the data of
507
+ the embedded plist in the provisioning profile and the team identifier
508
+ to use for code signing.
509
+
510
+ Raises:
511
+ SystemExit: if no .mobileprovision can be used to sign the bundle.
512
+ """
513
+ profiles_dir = os.path.join(
514
+ os.environ["HOME"], "Library", "MobileDevice", "Provisioning Profiles"
515
+ )
516
+ if not os.path.isdir(profiles_dir):
517
+ print(
518
+ "cannot find mobile provisioning for %s" % (bundle_identifier),
519
+ file=sys.stderr,
520
+ )
521
+ sys.exit(1)
522
+ provisioning_profiles = None
523
+ if profile:
524
+ profile_path = os.path.join(profiles_dir, profile + ".mobileprovision")
525
+ if os.path.exists(profile_path):
526
+ provisioning_profiles = [profile_path]
527
+ if not provisioning_profiles:
528
+ provisioning_profiles = glob.glob(
529
+ os.path.join(profiles_dir, "*.mobileprovision")
530
+ )
531
+ valid_provisioning_profiles = {}
532
+ for profile_path in provisioning_profiles:
533
+ profile_data = self._LoadProvisioningProfile(profile_path)
534
+ app_id_pattern = profile_data.get("Entitlements", {}).get(
535
+ "application-identifier", ""
536
+ )
537
+ for team_identifier in profile_data.get("TeamIdentifier", []):
538
+ app_id = f"{team_identifier}.{bundle_identifier}"
539
+ if fnmatch.fnmatch(app_id, app_id_pattern):
540
+ valid_provisioning_profiles[app_id_pattern] = (
541
+ profile_path,
542
+ profile_data,
543
+ team_identifier,
544
+ )
545
+ if not valid_provisioning_profiles:
546
+ print(
547
+ "cannot find mobile provisioning for %s" % (bundle_identifier),
548
+ file=sys.stderr,
549
+ )
550
+ sys.exit(1)
551
+ # If the user has multiple provisioning profiles installed that can be
552
+ # used for ${bundle_identifier}, pick the most specific one (ie. the
553
+ # provisioning profile whose pattern is the longest).
554
+ selected_key = max(valid_provisioning_profiles, key=lambda v: len(v))
555
+ return valid_provisioning_profiles[selected_key]
556
+
557
+ def _LoadProvisioningProfile(self, profile_path):
558
+ """Extracts the plist embedded in a provisioning profile.
559
+
560
+ Args:
561
+ profile_path: string, path to the .mobileprovision file
562
+
563
+ Returns:
564
+ Content of the plist embedded in the provisioning profile as a dictionary.
565
+ """
566
+ with tempfile.NamedTemporaryFile() as temp:
567
+ subprocess.check_call(
568
+ ["security", "cms", "-D", "-i", profile_path, "-o", temp.name]
569
+ )
570
+ return self._LoadPlistMaybeBinary(temp.name)
571
+
572
+ def _MergePlist(self, merged_plist, plist):
573
+ """Merge |plist| into |merged_plist|."""
574
+ for key, value in plist.items():
575
+ if isinstance(value, dict):
576
+ merged_value = merged_plist.get(key, {})
577
+ if isinstance(merged_value, dict):
578
+ self._MergePlist(merged_value, value)
579
+ merged_plist[key] = merged_value
580
+ else:
581
+ merged_plist[key] = value
582
+ else:
583
+ merged_plist[key] = value
584
+
585
+ def _LoadPlistMaybeBinary(self, plist_path):
586
+ """Loads into a memory a plist possibly encoded in binary format.
587
+
588
+ This is a wrapper around plistlib.readPlist that tries to convert the
589
+ plist to the XML format if it can't be parsed (assuming that it is in
590
+ the binary format).
591
+
592
+ Args:
593
+ plist_path: string, path to a plist file, in XML or binary format
594
+
595
+ Returns:
596
+ Content of the plist as a dictionary.
597
+ """
598
+ try:
599
+ # First, try to read the file using plistlib that only supports XML,
600
+ # and if an exception is raised, convert a temporary copy to XML and
601
+ # load that copy.
602
+ return plistlib.readPlist(plist_path)
603
+ except Exception:
604
+ pass
605
+ with tempfile.NamedTemporaryFile() as temp:
606
+ shutil.copy2(plist_path, temp.name)
607
+ subprocess.check_call(["plutil", "-convert", "xml1", temp.name])
608
+ return plistlib.readPlist(temp.name)
609
+
610
+ def _GetSubstitutions(self, bundle_identifier, app_identifier_prefix):
611
+ """Constructs a dictionary of variable substitutions for Entitlements.plist.
612
+
613
+ Args:
614
+ bundle_identifier: string, value of CFBundleIdentifier from Info.plist
615
+ app_identifier_prefix: string, value for AppIdentifierPrefix
616
+
617
+ Returns:
618
+ Dictionary of substitutions to apply when generating Entitlements.plist.
619
+ """
620
+ return {
621
+ "CFBundleIdentifier": bundle_identifier,
622
+ "AppIdentifierPrefix": app_identifier_prefix,
623
+ }
624
+
625
+ def _GetCFBundleIdentifier(self):
626
+ """Extracts CFBundleIdentifier value from Info.plist in the bundle.
627
+
628
+ Returns:
629
+ Value of CFBundleIdentifier in the Info.plist located in the bundle.
630
+ """
631
+ info_plist_path = os.path.join(
632
+ os.environ["TARGET_BUILD_DIR"], os.environ["INFOPLIST_PATH"]
633
+ )
634
+ info_plist_data = self._LoadPlistMaybeBinary(info_plist_path)
635
+ return info_plist_data["CFBundleIdentifier"]
636
+
637
+ def _InstallEntitlements(self, entitlements, substitutions, overrides):
638
+ """Generates and install the ${BundleName}.xcent entitlements file.
639
+
640
+ Expands variables "$(variable)" pattern in the source entitlements file,
641
+ add extra entitlements defined in the .mobileprovision file and the copy
642
+ the generated plist to "${BundlePath}.xcent".
643
+
644
+ Args:
645
+ entitlements: string, optional, path to the Entitlements.plist template
646
+ to use, defaults to "${SDKROOT}/Entitlements.plist"
647
+ substitutions: dictionary, variable substitutions
648
+ overrides: dictionary, values to add to the entitlements
649
+
650
+ Returns:
651
+ Path to the generated entitlements file.
652
+ """
653
+ source_path = entitlements
654
+ target_path = os.path.join(
655
+ os.environ["BUILT_PRODUCTS_DIR"], os.environ["PRODUCT_NAME"] + ".xcent"
656
+ )
657
+ if not source_path:
658
+ source_path = os.path.join(os.environ["SDKROOT"], "Entitlements.plist")
659
+ shutil.copy2(source_path, target_path)
660
+ data = self._LoadPlistMaybeBinary(target_path)
661
+ data = self._ExpandVariables(data, substitutions)
662
+ if overrides:
663
+ for key in overrides:
664
+ if key not in data:
665
+ data[key] = overrides[key]
666
+ plistlib.writePlist(data, target_path)
667
+ return target_path
668
+
669
+ def _ExpandVariables(self, data, substitutions):
670
+ """Expands variables "$(variable)" in data.
671
+
672
+ Args:
673
+ data: object, can be either string, list or dictionary
674
+ substitutions: dictionary, variable substitutions to perform
675
+
676
+ Returns:
677
+ Copy of data where each references to "$(variable)" has been replaced
678
+ by the corresponding value found in substitutions, or left intact if
679
+ the key was not found.
680
+ """
681
+ if isinstance(data, str):
682
+ for key, value in substitutions.items():
683
+ data = data.replace("$(%s)" % key, value)
684
+ return data
685
+ if isinstance(data, list):
686
+ return [self._ExpandVariables(v, substitutions) for v in data]
687
+ if isinstance(data, dict):
688
+ return {k: self._ExpandVariables(data[k], substitutions) for k in data}
689
+ return data
690
+
691
+
692
+ def NextGreaterPowerOf2(x):
693
+ return 2 ** (x).bit_length()
694
+
695
+
696
+ def WriteHmap(output_name, filelist):
697
+ """Generates a header map based on |filelist|.
698
+
699
+ Per Mark Mentovai:
700
+ A header map is structured essentially as a hash table, keyed by names used
701
+ in #includes, and providing pathnames to the actual files.
702
+
703
+ The implementation below and the comment above comes from inspecting:
704
+ http://www.opensource.apple.com/source/distcc/distcc-2503/distcc_dist/include_server/headermap.py?txt
705
+ while also looking at the implementation in clang in:
706
+ https://llvm.org/svn/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp
707
+ """
708
+ magic = 1751998832
709
+ version = 1
710
+ _reserved = 0
711
+ count = len(filelist)
712
+ capacity = NextGreaterPowerOf2(count)
713
+ strings_offset = 24 + (12 * capacity)
714
+ max_value_length = max(len(value) for value in filelist.values())
715
+
716
+ out = open(output_name, "wb")
717
+ out.write(
718
+ struct.pack(
719
+ "<LHHLLLL",
720
+ magic,
721
+ version,
722
+ _reserved,
723
+ strings_offset,
724
+ count,
725
+ capacity,
726
+ max_value_length,
727
+ )
728
+ )
729
+
730
+ # Create empty hashmap buckets.
731
+ buckets = [None] * capacity
732
+ for file, path in filelist.items():
733
+ key = 0
734
+ for c in file:
735
+ key += ord(c.lower()) * 13
736
+
737
+ # Fill next empty bucket.
738
+ while buckets[key & capacity - 1] is not None:
739
+ key = key + 1
740
+ buckets[key & capacity - 1] = (file, path)
741
+
742
+ next_offset = 1
743
+ for bucket in buckets:
744
+ if bucket is None:
745
+ out.write(struct.pack("<LLL", 0, 0, 0))
746
+ else:
747
+ (file, path) = bucket
748
+ key_offset = next_offset
749
+ prefix_offset = key_offset + len(file) + 1
750
+ suffix_offset = prefix_offset + len(os.path.dirname(path) + os.sep) + 1
751
+ next_offset = suffix_offset + len(os.path.basename(path)) + 1
752
+ out.write(struct.pack("<LLL", key_offset, prefix_offset, suffix_offset))
753
+
754
+ # Pad byte since next offset starts at 1.
755
+ out.write(struct.pack("<x"))
756
+
757
+ for bucket in buckets:
758
+ if bucket is not None:
759
+ (file, path) = bucket
760
+ out.write(struct.pack("<%ds" % len(file), file))
761
+ out.write(struct.pack("<s", "\0"))
762
+ base = os.path.dirname(path) + os.sep
763
+ out.write(struct.pack("<%ds" % len(base), base))
764
+ out.write(struct.pack("<s", "\0"))
765
+ path = os.path.basename(path)
766
+ out.write(struct.pack("<%ds" % len(path), path))
767
+ out.write(struct.pack("<s", "\0"))
768
+
769
+
770
+ if __name__ == "__main__":
771
+ sys.exit(main(sys.argv[1:]))