Exemple #1
0
    def enable_file_logging(self, file_name, mode='a', verbose=True):
        """
        Write all logger messages to this file using the given mode.
        """
        from opus_core.store.sftp_flt_storage import redirect_sftp_url_to_local_tempdir
        local_file_name = redirect_sftp_url_to_local_tempdir(file_name)
        if local_file_name != file_name:
            file_name = local_file_name
            verbose = True  #always prompt where the log file is

        if verbose:
            self.log_status('Logging to file: ' +
                            os.path.join(os.getcwd(), file_name))

        self.log_to_file = True

        if self._file_stack is None:
            self._file_stack = []

        file_stream = open(file_name, mode)
        self._file_stack.append({
            "file_name": file_name,
            "file_stream": file_stream,
            "file_mode": mode
        })
        os.getcwd()
Exemple #2
0
 def run(self, year, output_file=None):
     """Runs the daysim executables, using appropriate info from config. 
     Assumes the daysim input files are present. 
     Raise an exception if the daysim run fails. 
     """        
     daysim_config_file = self.get_daysim_config_file(year)
     daysim_dir = self.get_daysim_dir(year)
     logger.log_status('Using DaySim directory %s for year %d' % (daysim_dir, year))
     os.chdir(daysim_dir)
     if output_file is None:
         log_file_path = os.path.join(self.config['cache_directory'], 'daysim_%d_log.txt' % year)
     else:
         log_file_path = output_file
     
     # if log_file_path is a remote sftp URL, redirect the log file to tempdir           
     log_file_path = redirect_sftp_url_to_local_tempdir(log_file_path)
     cmd = """%(system_cmd)s"%(config_file)s" > %(log_file_path)s""" % {
             'system_cmd': self.config['travel_model_configuration'].get('daysim_system_command', 'cmd /c '),
             'config_file':daysim_config_file, 
             'log_file_path':log_file_path,
             } 
     logger.log_status('Running command %s' % cmd)
     cmd_result = os.system(cmd)
     if cmd_result != 0:
         error_msg = "DaySim Run failed. Code returned by cmd was %d" % (cmd_result)
         logger.log_error(error_msg)
         raise StandardError(error_msg)        
Exemple #3
0
 def run(self, year, output_file=None):
     """Runs the emme2 executables, using appropriate info from config. 
     Assumes the emme2 input files are present. 
     Raise an exception if the emme2 run fails. 
     """        
     emme2_batch_file_path = self.get_emme2_batch_file_path(year)
     emme2_dir, emme2_batch_file_name = os.path.split(emme2_batch_file_path)
     logger.log_status('Using emme2 dir %s for year %d' % (emme2_dir, year))
     os.chdir(emme2_dir)
     if output_file is None:
         log_file_path = os.path.join(self.config['cache_directory'], 'emme2_%d_log.txt' % year)
     else:
         log_file_path = output_file
     
     # if log_file_path is a remote sftp URL, redirect the log file to tempdir           
     log_file_path = redirect_sftp_url_to_local_tempdir(log_file_path)
     cmd = """%(system_cmd)s"%(emme2_batch_file_name)s" > %(log_file_path)s""" % {
             'system_cmd': self.config['travel_model_configuration'].get('system_command', 'cmd /c '),
             'emme2_batch_file_name':emme2_batch_file_path, 
             'log_file_path':log_file_path,
             } 
     logger.log_status('Running command %s' % cmd)
     cmd_result = os.system(cmd)
     if cmd_result != 0:
         error_msg = "Emme2 Run failed. Code returned by cmd was %d" % (cmd_result)
         logger.log_error(error_msg)
         raise StandardError(error_msg)        
Exemple #4
0
    def run(self, macro_group_name, year, output_file=None):
        """This is the main entry point.  It is initialized with the appropriate values from the 
        travel_model_configuration part of this config, and then runs the specified 
        emme/2 macros. The macro specification should also have a specification of the bank it should run in.
        'macro_group_name' is the group name of the macros, such as 'export_macros'.
        The macros should live in the base directory of travel model, subdirectory given by the entry 'path' in each macro.  
        'config' must contain an entry ['travel_model_configuration'][year][macro_group_name].
        """
        from opus_emme2.travel_model_output import TravelModelOutput
        import opus_emme2
        tm_output = TravelModelOutput(self.emme_cmd)
        specified_macros = self.config['travel_model_configuration'][year][
            macro_group_name]
        if output_file is None:
            tmp_output_file = os.path.join(
                self.config['cache_directory'],
                "emme2_export_macros_%s_log.txt" % year)
        else:
            tmp_output_file = output_file
        ## if tmp_output_file is a remote sftp URL, redirect file to local tempdir
        tmp_output_file = redirect_sftp_url_to_local_tempdir(tmp_output_file)

        for macro_name, macro_info in specified_macros.iteritems():
            bank = macro_info['bank']
            bank_path = self.get_emme2_dir(year, bank)
            macro_path = os.path.join(self.get_emme2_base_dir(),
                                      macro_info.get('path', ''), macro_name)
            tm_output.run_emme2_macro(macro_path,
                                      bank_path,
                                      macro_info['scenario'],
                                      output_file=tmp_output_file)
 def enable_file_logging(self, file_name, mode='a', verbose=True):
     """
     Write all logger messages to this file using the given mode.
     """
     from opus_core.store.sftp_flt_storage import redirect_sftp_url_to_local_tempdir
     local_file_name = redirect_sftp_url_to_local_tempdir(file_name)
     if local_file_name != file_name:
         file_name = local_file_name
         verbose = True #always prompt where the log file is
     
     if verbose:
         self.log_status('Logging to file: ' + os.path.join(os.getcwd(),file_name))
         
     self.log_to_file = True
     
     if self._file_stack is None:
         self._file_stack = []
                     
     file_stream = open(file_name,mode)
     self._file_stack.append({"file_name" : file_name,
                              "file_stream" : file_stream,
                              "file_mode" : mode})
     os.getcwd()
Exemple #6
0
 def run(self, macro_group_name, year, output_file=None):
     """This is the main entry point.  It is initialized with the appropriate values from the 
     travel_model_configuration part of this config, and then runs the specified 
     emme/2 macros. The macro specification should also have a specification of the bank it should run in.
     'macro_group_name' is the group name of the macros, such as 'export_macros'.
     The macros should live in the base directory of travel model, subdirectory given by the entry 'path' in each macro.  
     'config' must contain an entry ['travel_model_configuration'][year][macro_group_name].
     """
     from opus_emme2.travel_model_output import TravelModelOutput
     import opus_emme2
     tm_output = TravelModelOutput(self.emme_cmd)
     specified_macros = self.config['travel_model_configuration'][year][macro_group_name]
     if output_file is None:
         tmp_output_file = os.path.join(self.config['cache_directory'], "emme2_export_macros_%s_log.txt" % year)
     else:
         tmp_output_file = output_file
     ## if tmp_output_file is a remote sftp URL, redirect file to local tempdir
     tmp_output_file = redirect_sftp_url_to_local_tempdir(tmp_output_file)
     
     for macro_name, macro_info in specified_macros.iteritems():
         bank = macro_info['bank']
         bank_path = self.get_emme2_dir(year, bank)
         macro_path = os.path.join(self.get_emme2_base_dir(), macro_info.get('path',''), macro_name)
         tm_output.run_emme2_macro(macro_path, bank_path, macro_info['scenario'], output_file=tmp_output_file)
    def run(self, year, output_file=None):
        # if output_file is a remote sftp URL, redirect it to tempdir
        output_file = redirect_sftp_url_to_local_tempdir(output_file)

        RunMacrosAbstract.run(self, 'export_macros', year, output_file)
    def run(self, year, output_file=None):
        # if output_file is a remote sftp URL, redirect it to tempdir
        output_file = redirect_sftp_url_to_local_tempdir(output_file)

        RunMacrosAbstract.run(self, 'export_macros', year, output_file)