From 91ddbb70b5f3916ba9c13f9cb05528285d10ad5c Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Wed, 14 Dec 2016 19:45:30 +0000 Subject: [PATCH 1/1] Make the executable importable In preparation for moving the executable to an more standard entrypoint, make it safely importable and give it a separate conditional main() execution. --- bin/mudpy | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/bin/mudpy b/bin/mudpy index db4d147..d7ec045 100755 --- a/bin/mudpy +++ b/bin/mudpy @@ -13,21 +13,29 @@ sys.path.append(os.path.realpath(".")) import mudpy -# start it up -mudpy.misc.setup() -# loop indefinitely while the world is not flagged for termination or -# there are still connected users -while not mudpy.misc.universe.terminate_flag or mudpy.misc.universe.userlist: +def main(): - # the world was flagged for a reload of all code/data - if mudpy.misc.universe.reload_flag: - imp.reload(mudpy) - mudpy.misc.reload_data() - mudpy.misc.universe.reload_flag = False + # start it up + mudpy.misc.setup() - # do what needs to be done on each pulse - mudpy.misc.on_pulse() + # loop indefinitely while the world is not flagged for termination or + # there are still connected users + while (not mudpy.misc.universe.terminate_flag or + mudpy.misc.universe.userlist): -# shut it all down -mudpy.misc.finish() + # the world was flagged for a reload of all code/data + if mudpy.misc.universe.reload_flag: + imp.reload(mudpy) + mudpy.misc.reload_data() + mudpy.misc.universe.reload_flag = False + + # do what needs to be done on each pulse + mudpy.misc.on_pulse() + + # shut it all down + mudpy.misc.finish() + + +if __name__ == '__main__': + sys.exit(main()) -- 2.11.0