| 3 |  | import logging | 
| 4 |  | import os | 
| 5 |  | import subprocess | 
| 6 | + | import logging | 
| 7 |  |  | 
| 8 |  | fraw_list = []#List of all .md files found (even the includes). | 
| 9 |  | fmd_list = []#List of all config .md files that can be run (not the includes). | 
| 13 |  | dir_openmd = ""#Absolute path for openmd | 
| 14 |  | dir_base = ""#Directory where the script is run from. | 
| 15 |  |  | 
| 16 | + | FORMAT = '%(asctime)-15s %(message)s' | 
| 17 | + | logging.basicConfig(format=FORMAT) | 
| 18 | + |  | 
| 19 |  | """ | 
| 20 |  | Function sets up the dir_base and dir_openmd. If an openmd executable is not | 
| 21 |  | found, script exits. Function looks for the openmd in the relative location | 
| 24 |  | """ | 
| 25 |  | def setupDirectories(): | 
| 26 |  | global dir_base, dir_openmd, dir_cwd | 
| 27 | + | logger = logging.getLogger("tcpserver") | 
| 28 |  | dir_base = os.getcwd() | 
| 29 |  | if(os.path.isfile("../build/bin/openmd")): | 
| 30 |  | os.chdir("../build/bin/") | 
| 31 |  | dir_openmd = os.getcwd() | 
| 32 |  | os.chdir(dir_base) | 
| 33 |  | else: | 
| 34 | < | print "OpenMD executable not found." | 
| 34 | > | logger.error("OpenMD : %s", "openmd executable not found at the expected location. Script Will Quit...") | 
| 35 |  | sys.exit() | 
| 36 |  |  | 
| 37 |  |  | 
| 50 |  | validate_status_time = 0 | 
| 51 |  | validate_sample_time = 0 | 
| 52 |  | validate_run_time = 0 | 
| 53 | < |  | 
| 53 | > | logger = logging.getLogger("tcpserver") | 
| 54 | > |  | 
| 55 |  | samplefh = open(sample_file, "r") | 
| 56 |  | validatefh = open(validate_file, "r") | 
| 57 |  |  | 
| 92 |  | if (sample_status_time > 0) or (validate_status_time > 0): | 
| 93 |  | if sample_status_time == validate_status_time: | 
| 94 |  | return True | 
| 89 | – | else: | 
| 90 | – | return False | 
| 95 |  |  | 
| 96 |  | if (sample_sample_time > 0) or (validate_sample_time > 0): | 
| 97 |  | if sample_sample_time == validate_sample_time: | 
| 98 |  | return True | 
| 95 | – | else: | 
| 96 | – | return False | 
| 99 |  |  | 
| 100 |  | if (sample_run_time > 0) or (validate_run_time > 0): | 
| 101 |  | if sample_run_time == validate_run_time: | 
| 102 |  | return True | 
| 101 | – | else: | 
| 102 | – | return False | 
| 103 |  |  | 
| 104 | + | logger.warning("MD File: %s", "Sample/Validation times do not match.") | 
| 105 |  | return False | 
| 106 |  |  | 
| 107 |  | """ | 
| 144 |  | @return boolean | 
| 145 |  | """ | 
| 146 |  | def compare(fExpected, fNew, epsilon = 0.00001, ignore_sign=False): | 
| 147 | + | logger = logging.getLogger("tcpserver") | 
| 148 |  | fone = open(fExpected, 'r') | 
| 149 |  | ftwo = open(fNew, 'r') | 
| 150 |  |  | 
| 164 |  |  | 
| 165 |  | if lenone != lentwo: | 
| 166 |  | diffs = diffs + 1 | 
| 167 | < | print "Line " + str(i) + " do not match in the files." | 
| 167 | > | logger.warning("Line: %d - %s", i, "no mach") | 
| 168 |  | return True | 
| 169 |  | else: | 
| 170 |  | for j in range(lenone): | 
| 221 |  | @author Samuel Njoroge | 
| 222 |  | """ | 
| 223 |  | def runMdFiles(): | 
| 224 | + | logger = logging.getLogger("tcpserver") | 
| 225 |  | global dir_base, dir_openmd, dir_cwd | 
| 226 |  | output = [] | 
| 227 |  | for x in range(0, len(fmd_list)): | 
| 228 |  | #subprocess.call(["export FORCE_PARAM_PATH=/Users/snjoroge/Documents/openmd/development/forceFields"]) | 
| 229 |  | if "argon" in fmd_list[x]: | 
| 230 | < | print "Switching to Directory: " + os.path.dirname(fmd_list[x]) | 
| 230 | > | logger.debug("Switching to Directory: %s", os.path.dirname(fmd_list[x])) | 
| 231 |  | os.chdir(os.path.dirname(fmd_list[x])) | 
| 232 | < | print "Running file: " + fmd_list[x] | 
| 232 | > | logger.debug("Running: %s", fmd_list[x]) | 
| 233 |  | output = subprocess.call([dir_openmd + "/openmd", fmd_list[x]]) | 
| 234 |  | if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")): | 
| 235 |  | #print "Renaming File: " + fmd_base_list[x] + ".stat - " + fmd_base_list[x] + "_v.stat" | 
| 236 |  | #subprocess.call(["cp", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat"]) | 
| 237 | < | print "Comparing: " + fmd_base_list[x] + ".stat <=> " + fmd_base_list[x] + "_v.stat" | 
| 237 | > | logger.debug("Comparing: %s", "Comparing: " + fmd_base_list[x] + ".stat <=> " + fmd_base_list[x] + "_v.stat") | 
| 238 |  | if(compare(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat")): | 
| 239 | < | print "Files Do not match." | 
| 239 | > | logger.warning("Files: %s", "Files do not match.") | 
| 240 |  | else: | 
| 241 | < | print "Files match." | 
| 241 | > | logger.debug("Files Match") | 
| 242 |  | os.chdir(dir_base) | 
| 243 |  |  | 
| 244 |  | def cleanUp(): | 
| 245 | < | print "delete all files generated so not to commit" | 
| 245 | > | print "Delete all files generated." | 
| 246 |  | for x in range(0, len(fmd_list)): | 
| 247 | < | print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor" | 
| 248 | < | os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor") | 
| 249 | < | print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat" | 
| 250 | < | os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat") | 
| 251 | < | print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump" | 
| 252 | < | os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump") | 
| 247 | > | if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor")): | 
| 248 | > | print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor" | 
| 249 | > | os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor") | 
| 250 | > | if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")): | 
| 251 | > | print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat" | 
| 252 | > | os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat") | 
| 253 | > | if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump")): | 
| 254 | > | print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump" | 
| 255 | > | os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump") | 
| 256 |  |  |