OLD | NEW |
| (Empty) |
1 #!/usr/bin/python2.4 | |
2 # | |
3 # Copyright 2007-2009 Google Inc. | |
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 """ | |
19 Generates IDL file for the OneClick ActiveX control from the passed-in IDL | |
20 template. The input template is a complete IDL file in all but one respect; | |
21 It has one replaceable entry for the CLSID for GoopdateOneClickControl. | |
22 We generate a GUID using UUIDGEN.EXE, and write out an IDL with a new CLSID. | |
23 | |
24 """ | |
25 | |
26 import sys | |
27 import os | |
28 import getopt | |
29 import commands | |
30 | |
31 | |
32 def _GetStatusOutput(cmd): | |
33 """Return (status, output) of executing cmd in a shell.""" | |
34 if os.name == "nt": | |
35 pipe = os.popen(cmd + " 2>&1", 'r') | |
36 text = pipe.read() | |
37 sts = pipe.close() | |
38 if sts is None: sts = 0 | |
39 if text[-1:] == '\n': text = text[:-1] | |
40 return sts, text | |
41 else: | |
42 return commands.getstatusoutput(cmd) | |
43 | |
44 | |
45 def _GenerateIDLText(idl_template): | |
46 (status, guid) = _GetStatusOutput("uuidgen.exe") | |
47 if status != 0: | |
48 raise SystemExit("Failed to get GUID: %s" % guid) | |
49 | |
50 return idl_template % guid | |
51 | |
52 | |
53 def _GenerateIDLFile(idl_template_filename, idl_output_filename): | |
54 f_in = open(idl_template_filename, 'r') | |
55 idl_template = f_in.read() | |
56 f_in.close() | |
57 | |
58 idl_output = _GenerateIDLText(idl_template) | |
59 | |
60 f_out = open(idl_output_filename, 'w') | |
61 f_out.write(""" | |
62 // ** AUTOGENERATED FILE. DO NOT HAND-EDIT ** | |
63 """) | |
64 f_out.write(idl_output) | |
65 f_out.close() | |
66 | |
67 | |
68 def _Usage(): | |
69 """Prints out script usage information.""" | |
70 print """ | |
71 generate_oneclick_idl.py: Write out the given IDL file. | |
72 | |
73 Usage: | |
74 generate_oneclick_idl.py [--help | |
75 | --idl_template_file filename | |
76 --idl_output_file filename] | |
77 | |
78 Options: | |
79 --help Show this information. | |
80 --idl_output_file filename Path/name of output IDL filename. | |
81 --idl_template_file filename Path/name of input IDL template. | |
82 """ | |
83 | |
84 | |
85 def _Main(): | |
86 """Generates IDL file.""" | |
87 # use getopt to parse the option and argument list; this may raise, but | |
88 # don't catch it | |
89 _ARGUMENT_LIST = ["help", "idl_template_file=", "idl_output_file="] | |
90 (opts, args) = getopt.getopt(sys.argv[1:], "", _ARGUMENT_LIST) | |
91 if not opts or ("--help", "") in opts: | |
92 _Usage() | |
93 sys.exit() | |
94 | |
95 idl_template_filename = "" | |
96 idl_output_filename = "" | |
97 | |
98 for (o, v) in opts: | |
99 if o == "--idl_template_file": | |
100 idl_template_filename = v | |
101 if o == "--idl_output_file": | |
102 idl_output_filename = v | |
103 | |
104 # make sure we have work to do | |
105 if not idl_template_filename: | |
106 raise SystemExit("no idl_template_filename specified") | |
107 if not idl_output_filename: | |
108 raise SystemExit("no idl_output_filename specified") | |
109 | |
110 _GenerateIDLFile(idl_template_filename, idl_output_filename) | |
111 sys.exit() | |
112 | |
113 | |
114 if __name__ == "__main__": | |
115 _Main() | |
116 | |
OLD | NEW |