Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: tools/generate_omaha3_idl.py

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/build.scons ('k') | tools/goopdump/build.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 IDL file Omaha3 internfaces."""
19
20 import commands
21 import getopt
22 import os
23 import sys
24
25
26 def _GetStatusOutput(cmd):
27 """Return (status, output) of executing cmd in a shell."""
28 if os.name == "nt":
29 pipe = os.popen(cmd + " 2>&1", "r")
30 text = pipe.read()
31 sts = pipe.close()
32 if sts is None: sts = 0
33 if text[-1:] == "\n": text = text[:-1]
34 return sts, text
35 else:
36 return commands.getstatusoutput(cmd)
37
38
39 def _GenerateGuid():
40 (status, guid) = _GetStatusOutput("uuidgen.exe /c")
41 if status != 0:
42 raise SystemError("Failed to get GUID: %s" % guid)
43 return guid
44
45
46 def _GenerateIDLText(idl_template):
47 guid_placehold_marker = "___AUTO_GENERATED_GUID___"
48 while guid_placehold_marker in idl_template:
49 idl_template = idl_template.replace(guid_placehold_marker,
50 _GenerateGuid(),
51 1)
52 return idl_template
53
54
55 def _GenerateIDLFile(idl_template_filename, idl_output_filename):
56 f_in = open(idl_template_filename, "r")
57 idl_template = f_in.read()
58 f_in.close()
59
60 idl_output = _GenerateIDLText(idl_template)
61
62 f_out = open(idl_output_filename, "w")
63 f_out.write("// *** AUTOGENERATED FILE. DO NOT HAND-EDIT ***\n\n")
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_omaha3_idl.py: Write out the given IDL file.
72
73 Usage:
74 generate_omaha3_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, unused_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 StandardError("no idl_template_filename specified")
107 if not idl_output_filename:
108 raise StandardError("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
OLDNEW
« no previous file with comments | « tools/build.scons ('k') | tools/goopdump/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698