From: Jeremy Stanley Date: Wed, 14 Dec 2016 19:45:30 +0000 (+0000) Subject: Make the executable importable X-Git-Tag: 0.0.1~173 X-Git-Url: https://mudpy.org/gitweb?a=commitdiff_plain;h=91ddbb70b5f3916ba9c13f9cb05528285d10ad5c;p=mudpy.git 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. --- 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())