def prepare_for_run(self, config, year, check_tcw_process=False): """before calling travel model macro, check if transcad GUI is running, if not, try to start transcad binary process""" ## TODO: TransCAD COM server is very picky about tcw.exe process in memory ## as of April 2007, a tcw process started by python won't work ## so manually start TransCAD program is needed before running this script set_project_ini_file(config, year) if not check_tcw_process: return cmdline = config['transcad_binary'] head, tail = os.path.split(cmdline) procname, ext = os.path.splitext(tail) #tcw kill_process = False start_program = False tc_program_classname = "tcFrame" #ClassName for TransCAD program try: hwnd=win32gui.FindWindow(tc_program_classname, None) except: start_program = True # No Transcand Window found, we'll need to start TransCAD program else: try: #first check if tcw process is in memory win32pdhutil.GetPerformanceAttributes('Process','ID Process',procname) pids=win32pdhutil.FindPerformanceAttributesByName(procname) for pid in pids: win32process.TerminateProcess(pid) start_program = True except: raise RuntimeError, "Unable to kill TransCAD process in memory" ##transcad not started, try to start it if start_program: try: pass cmdline = win32api.GetShortPathName(cmdline) cmdline = cmdline + " -q" os.system('start /B "start TransCAD" ' + cmdline) #start TransCAD in background time.sleep(9) #procHandles = win32process.CreateProcess(None, cmdline, None, None, 0, 0, None, None, #win32process.STARTUPINFO()) #self.hProcess, hThread, PId, TId = procHandles except: logger.log_error( "Unable to start TransCAD in %s; it must be running to invoke travel model macro." % cmdline) sys.exit(1)
def prepare_for_run(self, config, year): set_project_ini_file(config, year)
def prepare_for_run(self, config, year): if config.has_key('project_ini'): set_project_ini_file(config, year)