You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB
Python

"""
The Management - this module takes care of loading and running subordinate
bureaus in the office organization. Bureaus are enabled in the file
"~/.screenless/mgmt.ini":
[mgmt]
bureaus = ihr typing myburo and so on
"""
import configparser
import importlib
import multiprocessing
import os
import time
def mgmt():
basepath = os.path.expanduser("~/.screenless")
if not os.path.exists(basepath):
os.mkdir(basepath)
os.chdir(basepath)
config = configparser.ConfigParser()
procs = {}
try:
config.read("mgmt.ini")
org_chart = config["mgmt"]["bureaus"].split()
except KeyError:
config["mgmt"] = {"bureaus": "ihr typing"}
with open("mgmt.ini", "w") as configfile:
config.write(configfile)
print("created new mgmt.ini config file. please modify this to suit.")
org_chart = config["mgmt"]["bureaus"].split()
print("org chart:", org_chart)
for buro in org_chart:
lib = importlib.import_module("bureau." + buro)
# run lib.main() in a separate process
proc = multiprocessing.Process(target=lib.main)
procs[buro] = proc.start()
while True:
for buro in org_chart:
proc = procs[buro]
if not proc.is_alive():
print("bureau", buro, "has crashed! Call the consultants!")
#TODO this should probably restart in some sensible way
else:
print("bureau", buro, "still running...")
time.sleep(1)
if __name__ == "__main__":
mgmt()