diff --git a/screenless/bureau/ihr/__init__.py b/screenless/bureau/ihr/__init__.py new file mode 100644 index 0000000..28145a6 --- /dev/null +++ b/screenless/bureau/ihr/__init__.py @@ -0,0 +1,4 @@ +from . import ihr + +def main(): + ihr.main() diff --git a/screenless/bureau/ihr.py b/screenless/bureau/ihr/ihr.py similarity index 100% rename from screenless/bureau/ihr.py rename to screenless/bureau/ihr/ihr.py diff --git a/screenless/bureau/jokes/__init__.py b/screenless/bureau/jokes/__init__.py new file mode 100644 index 0000000..21e0124 --- /dev/null +++ b/screenless/bureau/jokes/__init__.py @@ -0,0 +1,4 @@ +from . import jokes + +def main(): + jokes.main() diff --git a/screenless/bureau/jokes.py b/screenless/bureau/jokes/jokes.py similarity index 96% rename from screenless/bureau/jokes.py rename to screenless/bureau/jokes/jokes.py index bb96f66..0e61a7e 100644 --- a/screenless/bureau/jokes.py +++ b/screenless/bureau/jokes/jokes.py @@ -25,6 +25,10 @@ class Humor(Bureau): self.print_small(jux) -if __name__ == "__main__": +def main(): ha = Humor() ha.run() + + +if __name__ == "__main__": + main() diff --git a/screenless/bureau/photography/__init__.py b/screenless/bureau/photography/__init__.py new file mode 100644 index 0000000..72b2e91 --- /dev/null +++ b/screenless/bureau/photography/__init__.py @@ -0,0 +1,4 @@ +from . import photography + +def main(): + photography.main() diff --git a/screenless/bureau/photography.py b/screenless/bureau/photography/photography.py similarity index 97% rename from screenless/bureau/photography.py rename to screenless/bureau/photography/photography.py index afd7d7f..2699d60 100644 --- a/screenless/bureau/photography.py +++ b/screenless/bureau/photography/photography.py @@ -35,6 +35,10 @@ class Photography(Bureau): return {"photo": tmpimg.name} -if __name__ == "__main__": +def main(): px = Photography() px.run() + + +if __name__ == "__main__": + main() diff --git a/screenless/bureau/publicrelations/__init__.py b/screenless/bureau/publicrelations/__init__.py new file mode 100644 index 0000000..36d16a0 --- /dev/null +++ b/screenless/bureau/publicrelations/__init__.py @@ -0,0 +1,4 @@ +from . import publicrelations + +def main(): + publicrelations.main() diff --git a/screenless/bureau/publicrelations.py b/screenless/bureau/publicrelations/publicrelations.py similarity index 98% rename from screenless/bureau/publicrelations.py rename to screenless/bureau/publicrelations/publicrelations.py index f0101c6..df27ecf 100644 --- a/screenless/bureau/publicrelations.py +++ b/screenless/bureau/publicrelations/publicrelations.py @@ -59,6 +59,10 @@ class PublicRelations(Bureau): self.print_small(out) -if __name__ == "__main__": +def main(): pr = PublicRelations() pr.run() + + +if __name__ == "__main__": + main() diff --git a/screenless/mgmt.py b/screenless/mgmt.py index cc63917..2feddf9 100644 --- a/screenless/mgmt.py +++ b/screenless/mgmt.py @@ -1,6 +1,6 @@ """ The Management - this module takes care of loading and running subordinate - bureaus in the office organization. Bureaus are enabled in the file + bureaus in the office organization. Bureaus are enabled in the file "~/.screenless/mgmt.ini": [mgmt] bureaus = ihr typing myburo and so on @@ -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,23 +24,25 @@ 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.") 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() + 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)