Make the executable importable
[mudpy.git] / bin / mudpy
index a0d764e..d7ec045 100755 (executable)
--- a/bin/mudpy
+++ b/bin/mudpy
@@ -1,32 +1,41 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-u"""Skeletal executable for the mudpy engine."""
+#!/usr/bin/env python3
+"""Skeletal executable for the mudpy engine."""
 
-# Copyright (c) 2004-2010 Jeremy Stanley <fungi@yuggoth.org>. Permission
+# Copyright (c) 2004-2016 Jeremy Stanley <fungi@yuggoth.org>. Permission
 # to use, copy, modify, and distribute this software is granted under
 # terms provided in the LICENSE file distributed with this software.
 
 # core objects for the mudpy engine
-import os.path
+import imp
+import os
 import sys
-sys.path.append(os.path.realpath(u"lib"))
+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():
+
+    # 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):
+
+        # 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()
 
-    # the world was flagged for a reload of all code/data
-    if mudpy.misc.universe.reload_flag:
-        reload(mudpy)
-        mudpy.misc.reload_data()
-        mudpy.misc.universe.reload_flag = False
+    # shut it all down
+    mudpy.misc.finish()
 
-    # 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())