237 except Exception,e: |
237 except Exception,e: |
238 message = "Could not update " + dest_str + " from " + source_str + " : " + str(e) |
238 message = "Could not update " + dest_str + " from " + source_str + " : " + str(e) |
239 raise IOError(message) |
239 raise IOError(message) |
240 |
240 |
241 return |
241 return |
|
242 |
|
243 |
|
244 |
|
245 ## Commandline processing utilities ## |
|
246 |
|
247 fullCommandOption = "--command" |
|
248 miniCommandOption = "--co" # update this if another "co" option is added |
|
249 |
|
250 def read_command_file(filename, used): |
|
251 """Read commandline options in from a file""" |
|
252 if filename in used: |
|
253 raise IOError("command file '%s' refers to itself" % filename) |
|
254 |
|
255 args = [] |
|
256 try: |
|
257 file = open(filename, "r") |
|
258 for line in file.readlines(): |
|
259 args.extend(line.split()) |
|
260 file.close() |
|
261 except: |
|
262 raise IOError("couldn't read command file '%s'" % filename) |
|
263 |
|
264 # expand any command files in the options we just read. |
|
265 # making sure we don't get stuck in a loop. |
|
266 usedPlusThis = used[:] |
|
267 usedPlusThis.append(filename) |
|
268 return expand_command_options(args, usedPlusThis) |
|
269 |
|
270 def expand_command_options(args, files = []): |
|
271 """process commandline options to recursively expand command files (--command options) into a full list of options.""" |
|
272 expanded = [] |
|
273 previousWasOpt = False |
|
274 |
|
275 for a in args: |
|
276 if previousWasOpt: # then this one is the filename |
|
277 expanded.extend(read_command_file(a, files)) |
|
278 previousWasOpt = False |
|
279 continue |
|
280 |
|
281 if a.startswith(miniCommandOption): |
|
282 if "=" in a: # then this is opt=filename |
|
283 opt = a.split("=") |
|
284 if fullCommandOption.startswith(opt[0]): |
|
285 expanded.extend(read_command_file(opt[1], files)) |
|
286 continue |
|
287 else: # the next one is the filename |
|
288 if fullCommandOption.startswith(a): |
|
289 previousWasOpt = True |
|
290 continue |
|
291 |
|
292 expanded.append(a) # an ordinary arg, nothing to do with command files |
|
293 |
|
294 return expanded |