Mercurial > repos > pieterlukasse > nist_wrapper
comparison nist_wrapper.py @ 16:c21e96bb68c8
added clean-up after execution
author | pieter.lukasse@wur.nl |
---|---|
date | Fri, 23 Jan 2015 14:57:55 +0100 |
parents | 92cf554fca03 |
children | 82368bd06e1d |
comparison
equal
deleted
inserted
replaced
15:76d6d8a5fa29 | 16:c21e96bb68c8 |
---|---|
83 o.write(line) | 83 o.write(line) |
84 o.close() | 84 o.close() |
85 | 85 |
86 return new_nist_home | 86 return new_nist_home |
87 | 87 |
88 def _clean_up_NIST(new_nist_home): | |
89 ''' | |
90 remove folder | |
91 ''' | |
92 utils.remove_dir(new_nist_home) | |
93 | |
88 def _run_NIST(new_nist_home, output_file, is_wine, log_file, job_size): | 94 def _run_NIST(new_nist_home, output_file, is_wine, log_file, job_size): |
89 ''' | 95 ''' |
90 - run : (wine) new_nist_home/MSSEARCH/nistms$.exe /INSTRUMENT /PAR=2 | 96 - run : (wine) new_nist_home/MSSEARCH/nistms$.exe /INSTRUMENT /PAR=2 |
91 - monitor : new_nist_home/MSSEARCH/SRCREADY.TXT for content = "1" | 97 - monitor : new_nist_home/MSSEARCH/SRCREADY.TXT for content = "1" |
92 - when ready: | 98 - when ready: |
96 > finish | 102 > finish |
97 ''' | 103 ''' |
98 # to avoid conflicts in the orphan process killing (see end of this method), we will | 104 # to avoid conflicts in the orphan process killing (see end of this method), we will |
99 # only run NIST again after previous nistms.exe process has been killed: | 105 # only run NIST again after previous nistms.exe process has been killed: |
100 # TODO : solution is currently only for wine (in the windows context the solution is not there yet, but parallel calls are not expected as in windows we only run tests one by one for now) | 106 # TODO : solution is currently only for wine (in the windows context the solution is not there yet, but parallel calls are not expected as in windows we only run tests one by one for now) |
101 # if is_wine: | |
102 # while True: | |
103 # # check if process exists. If not, break loop and continue | |
104 # pid = utils.get_process_pid("nistms.exe") | |
105 # if pid == -1: | |
106 # break | |
107 # time.sleep(2) | |
108 | 107 |
109 | 108 |
110 # remove old file, if it is there: | 109 # remove old file, if it is there: |
111 file_to_monitor = new_nist_home+"/MSSEARCH/SRCREADY.TXT" | 110 file_to_monitor = new_nist_home+"/MSSEARCH/SRCREADY.TXT" |
112 if os.path.exists(file_to_monitor): | 111 if os.path.exists(file_to_monitor): |
152 #stays open...and orphan..killing it: | 151 #stays open...and orphan..killing it: |
153 | 152 |
154 if is_wine: | 153 if is_wine: |
155 # pid = utils.get_process_pid("nistms.exe") | 154 # pid = utils.get_process_pid("nistms.exe") |
156 # os.kill(pid, 9) | 155 # os.kill(pid, 9) |
157 os.killpg(pro.pid, 9) | 156 os.killpg(pro.pid, 9) |
158 else: | 157 else: |
159 # windows case: | 158 # windows case: |
160 proc_name = "nistms.exe" | 159 proc_name = "nistms.exe" |
161 os.system("taskkill /f /im " + proc_name) | 160 os.system("taskkill /f /im " + proc_name) |
162 | 161 |
316 # run NIST search command: | 315 # run NIST search command: |
317 spectra_dict = utils.get_spectra_file_as_dict(spectrum_file) | 316 spectra_dict = utils.get_spectra_file_as_dict(spectrum_file) |
318 job_size = len(spectra_dict) | 317 job_size = len(spectra_dict) |
319 _run_NIST(new_nist_home, nist_output_file, is_wine, output_log_file, job_size) | 318 _run_NIST(new_nist_home, nist_output_file, is_wine, output_log_file, job_size) |
320 | 319 |
320 # clean-up NIST environment: | |
321 _clean_up_NIST(new_nist_home) | |
322 | |
321 # write output tabular: | 323 # write output tabular: |
322 hits_dict = utils.get_nist_out_as_dict(nist_output_file) | 324 hits_dict = utils.get_nist_out_as_dict(nist_output_file) |
323 utils.save_dict_as_tsv(hits_dict, final_output_file) | 325 utils.save_dict_as_tsv(hits_dict, final_output_file) |
324 | 326 |
325 # create report: | 327 # create report: |