Mercurial > repos > pieterlukasse > nist_wrapper
diff nist_wrapper.py @ 14:92cf554fca03
minor changes/improvements
author | pieter.lukasse@wur.nl |
---|---|
date | Fri, 23 Jan 2015 14:14:08 +0100 |
parents | 3a69874edaf7 |
children | c21e96bb68c8 |
line wrap: on
line diff
--- a/nist_wrapper.py Fri Jan 23 12:34:33 2015 +0100 +++ b/nist_wrapper.py Fri Jan 23 14:14:08 2015 +0100 @@ -85,7 +85,7 @@ return new_nist_home -def _run_NIST(new_nist_home, output_file, is_wine, log_file): +def _run_NIST(new_nist_home, output_file, is_wine, log_file, job_size): ''' - run : (wine) new_nist_home/MSSEARCH/nistms$.exe /INSTRUMENT /PAR=2 - monitor : new_nist_home/MSSEARCH/SRCREADY.TXT for content = "1" @@ -117,7 +117,6 @@ pro = "" if is_wine: utils.log_message(log_file, "calling wine with " + exec_path) - print "calling wine with " + exec_path cmd = ["wine "+ exec_path + " /INSTRUMENT /PAR=2"] # The os.setsid() is passed in the argument preexec_fn so # it's run after the fork() and before exec() to run the shell. @@ -132,14 +131,21 @@ timeSleeping = 0 + startUpTime = 30 # monitor process by checking state file: utils.log_message(log_file, "monitoring SRCREADY.TXT...") - while timeSleeping < 20: + # TODO2: do the controller part + # TODO3: do the popover part + while True: # check if SRCREADY.TXT is there already: if os.path.exists(file_to_monitor): break time.sleep(2) timeSleeping = timeSleeping+2 + if timeSleeping > (startUpTime + job_size*2): + # abort with timeout: + utils.log_message(log_file, "No results after " + timeSleeping + " seconds...") + raise Exception('Error: timeout waiting for NIST results.') # kill process: #p.terminate() - not needed, nistm$ will terminate...nistms.exe is the one that @@ -171,16 +177,14 @@ ''' # step 1 : generate HTML via the jinja template engine # step 1.1: make sure to link the query spectrum data to the corresponding html object for quick rendering when needed + + # copy necessary .js files as well: + templates_folder = os.path.dirname(__file__) + '/templates/' + utils.copy_dir(templates_folder, output_html_report_files_path) html_file = open(output_html_report,'w') html_render = ReportGenerator(os.path.dirname(__file__), 'templates/main_template.html',hits_dict, spectra_dict) html_render.render(html_file) - # copy necessary .js files as well: - templates_folder = os.path.dirname(__file__) + '/templates/' - #utils.copy_file(templates_folder + 'spectrum_gen.js', output_html_report_files_path+"/spectrum_gen.js") - #utils.copy_dir(templates_folder + 'lib', output_html_report_files_path+'/lib' ) - #utils.copy_dir(templates_folder + 'images', output_html_report_files_path+'/images' ) - utils.copy_dir(templates_folder, output_html_report_files_path) html_file.close() @@ -310,15 +314,16 @@ new_nist_home = _prepare_NIST(uuid_value, nist_home_dir, nist_ini_file, spectrum_file, is_wine, output_log_file) # run NIST search command: - _run_NIST(new_nist_home, nist_output_file, is_wine, output_log_file) + spectra_dict = utils.get_spectra_file_as_dict(spectrum_file) + job_size = len(spectra_dict) + _run_NIST(new_nist_home, nist_output_file, is_wine, output_log_file, job_size) # write output tabular: hits_dict = utils.get_nist_out_as_dict(nist_output_file) utils.save_dict_as_tsv(hits_dict, final_output_file) # create report: - if len(sys.argv) > 6: - spectra_dict = utils.get_spectra_file_as_dict(spectrum_file) + if len(sys.argv) > 7: _create_html_report(output_html_report, output_html_report_files_path, hits_dict, spectra_dict)