6 def setup_server_io(io_db):
7 """Fill IO files DB with proper file( path)s. Write process IO test string.
9 Ensure IO files directory at server/. Remove any old in file if found. Set
10 up new in file (io_db["file_in"]) for reading at io_db["path_in"], and new
11 out file (io_db["file_out"]) for writing at io_db["path_out"]. Start out
12 file with process hash line of format PID + " " + floated UNIX time
13 (io_db["teststring"]). Set worldstate file path io_db["path_worldstate"].
16 io_db["path_in"] = io_dir + "in"
17 io_db["path_out"] = io_dir + "out"
18 io_db["path_worldstate"] = io_dir + "worldstate"
19 io_db["teststring"] = str(os.getpid()) + " " + str(time.time())
20 os.makedirs(io_dir, exist_ok=True)
21 io_db["file_out"] = open(io_db["path_out"], "w")
22 io_db["file_out"].write(io_db["teststring"] + "\n")
23 if os.access(io_db["path_in"], os.F_OK):
24 os.remove(io_db["path_in"])
25 io_db["file_in"] = open(io_db["path_in"], "w")
26 io_db["file_in"].close()
27 io_db["file_in"] = open(io_db["path_in"], "r")
30 def cleanup_server_io(io_db):
31 """Close and remove all files in IO files DB."""
32 io_db["file_out"].close()
33 os.remove(io_db["path_out"])
34 io_db["file_in"].close()
35 os.remove(io_db["path_in"])
36 if "file_worldstate" in io_db: # This file's only set up
37 io_db["file_worldstate"].close() # properly when the game
38 if os.access(io_db["path_worldstate"], os.F_OK): # world is active, which
39 os.remove(io_db["path_worldstate"]) # is not guaranteed.
43 print("DUMMY: Obey command-line arguments.")
44 print("DUMMY: Open files.")
45 setup_server_io(io_db)
46 print("DUMMY: Run game.")
48 print("SOMETHING WENT WRONG\n")
51 cleanup_server_io(io_db)
52 print("DUMMY: (Clean up C heap.)")