156 from optparse import OptionParser
157
158 parser = OptionParser(
159 description="Produce a patch file from a CMT project. "
160 "The patch contains the changes with respect "
161 "to the CVS repository, including new files "
162 "that are present only locally. Run the script "
163 "from the cmt directory of a package."
164 )
165 parser.add_option(
166 "-x",
167 "--exclude",
168 action="append",
169 type="string",
170 metavar="PATTERN",
171 dest="exclusions",
172 help="Pattern to exclude new files from the patch",
173 )
174 parser.add_option(
175 "-o",
176 "--output",
177 action="store",
178 type="string",
179 help="Name of the file to send the output to. Standard "
180 "output is used if not specified",
181 )
182 parser.add_option(
183 "-v",
184 "--verbose",
185 action="store_true",
186 help="Print some progress information on standard error",
187 )
188 parser.add_option(
189 "--debug", action="store_true", help="Print debug information on standard error"
190 )
191 parser.set_defaults(exclusions=[])
192
193 opts, args = parser.parse_args()
194
195 if opts.debug:
196 logging.basicConfig(level=logging.DEBUG)
197 elif opts.verbose:
198 logging.basicConfig(level=logging.INFO)
199
200
201 opts.exclusions += [
202 "*.py[co]",
203 "*.patch",
204 "cmt/cleanup.*",
205 "cmt/setup.*",
206 "cmt/*.make",
207 "cmt/Makefile",
208 "cmt/*.nmake",
209 "cmt/*.nmakesav",
210 "cmt/NMake",
211 "cmt/install*.history",
212 "cmt/build.*.log",
213 "cmt/version.cmt",
214 "genConf",
215 "slc3_ia32_gcc323*",
216 "slc4_ia32_gcc34*",
217 "slc4_amd64_gcc34*",
218 "slc4_amd64_gcc43*",
219 "win32_vc71*",
220 "i686-slc[34567]-[ig]cc*",
221 "i686-slc[34567]-clang*",
222 "x86_64-slc[34567]-[ig]cc*",
223 "x86_64-slc[34567]-clang*",
224 ".eclipse",
225 ]
226 if "CMTCONFIG" in os.environ:
227 opts.exclusions.append(os.environ["CMTCONFIG"])
228
229
230 if not (os.path.basename(os.getcwd()) == "cmt" and os.path.exists("requirements")):
231 logging.error(
232 "This script must be executed from the cmt directory of a package."
233 )
234 return 1
235
236 pkgs = broadcast_packages()
237 num_pkgs = len(pkgs)
238 count = 0
239
240 patch = ""
241 for name, path in pkgs:
242 count += 1
243 logging.info(
244 "Processing %s from %s (%d/%d)",
245 name,
246 os.path.dirname(path),
247 count,
248 num_pkgs,
249 )
250 patch += diff_pkg(name, path, opts.exclusions)
251
252 if sys.platform.startswith("win"):
253
254 patch = patch.replace("\r", "")
255
256 if opts.output:
257 logging.info("Writing patch file %r", opts.output)
258 open(opts.output, "w").write(patch)
259 else:
260 sys.stdout.write(patch)
261 return 0
262
263