big cleanup. turn bureaus into proper python packages. mgmt keeps track of processes.

workspace
Brendan Howell 9 years ago
parent 40a645679d
commit bef9fa5e4e

@ -0,0 +1,4 @@
from . import ihr
def main():
ihr.main()

@ -0,0 +1,4 @@
from . import jokes
def main():
jokes.main()

@ -25,6 +25,10 @@ class Humor(Bureau):
self.print_small(jux)
if __name__ == "__main__":
def main():
ha = Humor()
ha.run()
if __name__ == "__main__":
main()

@ -0,0 +1,4 @@
from . import photography
def main():
photography.main()

@ -35,6 +35,10 @@ class Photography(Bureau):
return {"photo": tmpimg.name}
if __name__ == "__main__":
def main():
px = Photography()
px.run()
if __name__ == "__main__":
main()

@ -0,0 +1,4 @@
from . import publicrelations
def main():
publicrelations.main()

@ -59,6 +59,10 @@ class PublicRelations(Bureau):
self.print_small(out)
if __name__ == "__main__":
def main():
pr = PublicRelations()
pr.run()
if __name__ == "__main__":
main()

@ -12,7 +12,10 @@ import os
import time
def mgmt():
"""
Primary management function. Main loop that starts and runs all bureaus.
Some day this will do nice supervisory things like restart crashed buros.
"""
basepath = os.path.expanduser("~/.screenless")
if not os.path.exists(basepath):
os.mkdir(basepath)
@ -21,11 +24,13 @@ def mgmt():
config = configparser.ConfigParser()
procs = {}
try:
config.read("mgmt.ini")
org_chart = config["mgmt"]["bureaus"].split()
except KeyError:
config["mgmt"] = {"bureaus": "ihr typing"}
config["mgmt"] = {"bureaus":
"ihr typing publicrelations photography jokes"}
with open("mgmt.ini", "w") as configfile:
config.write(configfile)
print("created new mgmt.ini config file. please modify this to suit.")
@ -35,9 +40,9 @@ def mgmt():
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()
procs[buro] = proc
proc.start()
while True:
for buro in org_chart:
@ -45,8 +50,6 @@ def mgmt():
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)

Loading…
Cancel
Save