OLD | NEW |
| (Empty) |
1 #!/usr/bin/python2.4 | |
2 # | |
3 # Copyright 2011 Google Inc. All Rights Reserved. | |
4 # | |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | |
6 # you may not use this file except in compliance with the License. | |
7 # You may obtain a copy of the License at | |
8 # | |
9 # http://www.apache.org/licenses/LICENSE-2.0 | |
10 # | |
11 # Unless required by applicable law or agreed to in writing, software | |
12 # distributed under the License is distributed on an "AS IS" BASIS, | |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 # See the License for the specific language governing permissions and | |
15 # limitations under the License. | |
16 # ======================================================================== | |
17 | |
18 """Generates Omaha build file and Omaha customization unit test file.""" | |
19 | |
20 import commands | |
21 import os | |
22 | |
23 | |
24 omaha_project_path = os.path.dirname(__file__) + "\\.." | |
25 proxy_clsid_file_name = omaha_project_path + "\\proxy_clsids.txt" | |
26 customization_ut_file_name = (omaha_project_path + | |
27 "\\common\\omaha_customization_proxy_clsid.h") | |
28 | |
29 | |
30 def _GetStatusOutput(cmd): | |
31 """Return (status, output) of executing cmd in a shell.""" | |
32 if os.name == "nt": | |
33 pipe = os.popen(cmd + " 2>&1", "r") | |
34 text = pipe.read() | |
35 sts = pipe.close() | |
36 if sts is None: sts = 0 | |
37 if text[-1:] == "\n": text = text[:-1] | |
38 return sts, text | |
39 else: | |
40 return commands.getstatusoutput(cmd) | |
41 | |
42 | |
43 def _GenerateGuid(): | |
44 (status, guid) = _GetStatusOutput("uuidgen.exe /c") | |
45 if status != 0: | |
46 raise SystemError("Failed to get GUID: %s" % guid) | |
47 return guid | |
48 | |
49 | |
50 def _GuidToCStructFormat(guid): | |
51 return ("{0x%s, 0x%s, 0x%s, " | |
52 "{0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}") % ( | |
53 guid[0:8], guid[9:13], guid[14:18], | |
54 guid[19:21], guid[21:23], guid[24:26], guid[26:28], | |
55 guid[28:30], guid[30:32], guid[32:34], guid[34:36]) | |
56 | |
57 | |
58 def _GenerateProxySconsText(machine_proxy_clsid, | |
59 user_proxy_clsid): | |
60 proxy_clsid_text_format = ("PROXY_CLSID_IS_MACHINE=%s\n" | |
61 "PROXY_CLSID_IS_USER=%s\n") | |
62 return proxy_clsid_text_format % (_GuidToCStructFormat(machine_proxy_clsid), | |
63 _GuidToCStructFormat(user_proxy_clsid)) | |
64 | |
65 | |
66 def _GenerateCustomizationUTText(machine_proxy_clsid, user_proxy_clsid): | |
67 customization_ut_template = ( | |
68 "//\n" | |
69 "// !!! AUTOGENERATED FILE. DO NOT HAND-EDIT !!!\n" | |
70 "//\n\n" | |
71 "namespace omaha {\n\n" | |
72 "%s\n%s\n} // namespace omaha\n") | |
73 customization_ut_machine_proxy_clsid_string = ( | |
74 "// PROXY_CLSID_IS_MACHINE = {%s}\n" | |
75 "const GUID kProxyClsidIsMachineGuid =\n" | |
76 " %s;\n") % (machine_proxy_clsid, | |
77 _GuidToCStructFormat(machine_proxy_clsid)) | |
78 | |
79 customization_ut_user_proxy_clsid_string = ( | |
80 "// PROXY_CLSID_IS_USER = {%s}\n" | |
81 "const GUID kProxyClsidIsUserGuid =\n" | |
82 " %s;\n") % (user_proxy_clsid, | |
83 _GuidToCStructFormat(user_proxy_clsid)) | |
84 | |
85 return customization_ut_template % ( | |
86 customization_ut_machine_proxy_clsid_string, | |
87 customization_ut_user_proxy_clsid_string) | |
88 | |
89 | |
90 def _GenerateProxyClsidFile(machine_proxy_clsid, | |
91 user_proxy_clsid): | |
92 proxy_clsid_output = _GenerateProxySconsText(machine_proxy_clsid, | |
93 user_proxy_clsid) | |
94 f_out = open(proxy_clsid_file_name, "w") | |
95 f_out.write(proxy_clsid_output) | |
96 f_out.close() | |
97 | |
98 | |
99 def _GenerateCustomizationUnitTestFile(machine_proxy_clsid, | |
100 user_proxy_clsid): | |
101 customization_ut_output = _GenerateCustomizationUTText(machine_proxy_clsid, | |
102 user_proxy_clsid) | |
103 f_out = open(customization_ut_file_name, "w") | |
104 f_out.write(customization_ut_output) | |
105 f_out.close() | |
106 | |
107 | |
108 def _GenerateProxyClsidsFiles(): | |
109 if (os.path.isfile(proxy_clsid_file_name) and | |
110 os.path.isfile(customization_ut_file_name)): | |
111 return | |
112 | |
113 machine_proxy_clsid = _GenerateGuid() | |
114 user_proxy_clsid = _GenerateGuid() | |
115 | |
116 _GenerateProxyClsidFile(machine_proxy_clsid, user_proxy_clsid) | |
117 _GenerateCustomizationUnitTestFile(machine_proxy_clsid, | |
118 user_proxy_clsid) | |
119 | |
120 | |
121 def _GetProxyClsidsFromFile(target_proxy_clsid): | |
122 proxy_clsid = "" | |
123 f = open(proxy_clsid_file_name, "r") | |
124 for line in f: | |
125 if not line.startswith("#") and target_proxy_clsid in line: | |
126 proxy_clsid = line[len(target_proxy_clsid):].rstrip() | |
127 break | |
128 f.close() | |
129 | |
130 if not proxy_clsid: | |
131 raise StandardError("Failed to get auto-generated proxy CLSID") | |
132 | |
133 return proxy_clsid | |
134 | |
135 | |
136 def GetMachineProxyClsid(): | |
137 """Loads machine proxy CLSID from the generated file.""" | |
138 return _GetProxyClsidsFromFile("PROXY_CLSID_IS_MACHINE=") | |
139 | |
140 | |
141 def GetUserProxyClsid(): | |
142 """Loads user proxy CLSID from the generated file.""" | |
143 return _GetProxyClsidsFromFile("PROXY_CLSID_IS_USER=") | |
144 | |
145 | |
146 def _Main(): | |
147 """Generates proxy_clsids.txt and customization unit test file.""" | |
148 _GenerateProxyClsidsFiles() | |
149 | |
150 | |
151 if __name__ == "__main__": | |
152 _Main() | |
OLD | NEW |