forked from djpetti/ecosystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·62 lines (47 loc) · 1.63 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python3
from modified_logger import Logger
# This has to happen before anything uses a Logger.
Logger.set_path("simulation.log")
import logging
logger = logging.getLogger(__name__)
import select
import sys
import yaml
try:
from yaml import CLoader as Loader
except ImportError:
logger.warning("Falling back on Python yaml parser.")
from yaml import Loader
from library import Library
from simulation import Simulation
def main():
if len(sys.argv) != 2:
print("Usage: main.py conf_file")
sys.exit()
# Read configuration from file.
logger.info("Reading configuration from '%s'." % (sys.argv[1]))
config_file = open(sys.argv[1])
config = yaml.load(config_file, Loader = Loader)
config_file.close()
# Load all the organisms specified.
if "Organisms" not in config:
logger.fatal("Invalid config, needs 'Organisms' section.")
if ("GridXSize" not in config and "GridYSize" not in config):
logger.fatal("Invalid config, needs GridXSize and GridYSize")
if "IterationTime" not in config:
logger.fatal("Invalid config, needs IterationTime.")
simulation = Simulation(config["GridXSize"], config["GridYSize"],
config["IterationTime"])
# Add them to the simulation.
for organism in config["Organisms"]:
for i in range(0, organism["Quantity"]):
library = Library(organism["Library"])
simulation.add_organism(organism["Library"], organism["Name"])
# Start it running.
logger.info("Delegating to simulation process.")
simulation.start()
# Wait forever.
select.select([], [], [])
logger.critical("Exiting main.py.")
if __name__ == "__main__":
main()