diff src/parpg/main.py @ 180:59c4db30fe05

Created parpg.py and moved code from parpg\main.py to it.
author KarstenBock@gmx.net
date Mon, 10 Oct 2011 15:12:33 +0200
parents 2e2d6d9009a3
children
line wrap: on
line diff
--- a/src/parpg/main.py	Mon Oct 10 15:05:15 2011 +0200
+++ b/src/parpg/main.py	Mon Oct 10 15:12:33 2011 +0200
@@ -11,81 +11,62 @@
 
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-#TODO: Modularize this script
+import logging
 import sys
-import logging
-
-from optparse import OptionParser
+from os.path import abspath
 
 from parpg.settings import Settings
 
-usage = ('usage: %prog [options] settings_path [system_path user_path]\n\n'
-         'The settings_path argument is mandatory and is the directory in \n'
-         'which your system.cfg file is located. Optionally, you may \n'
-         'specify where data files are located (system_path), and where \n'
-         'the user settings and data files should be saved to (user_path)\n\n'
-         'Example: python %prog .')
-
-parser = OptionParser(description='PARPG Launcher Script', usage=usage)
-parser.add_option('-f', '--logfile',
-                  help='Name of log file to save to')
-parser.add_option('-l', '--loglevel', default='critical',
-                  help='desired output level for log file')
-opts, args = parser.parse_args()
-
-if not args:
-    parser.print_help()
-    sys.exit(1)
-            
-
-
-settings = Settings(*args)
-
-levels = {'debug': logging.DEBUG,
-          'info': logging.INFO,
-          'warning': logging.WARNING,
-          'error': logging.ERROR,
-          'critical': logging.CRITICAL}
-
-#TODO: setup formating
-logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
-logger = logging.getLogger('parpg')
-
-try:
-    old_path = sys.path
-    sys.path = [settings.parpg.FifePath]
-    import fife
-except AttributeError:
-    logger.warning('[parpg] section has no FifePath option')
-except ImportError:
-    logger.critical("Could not import fife module. Please install fife or add "
-                    "'FifePath' to the [parpg] section of your settings file")
-    sys.exit(1)
-finally:
-    sys.path = old_path
-
-from parpg.application import PARPGApplication
-from parpg.common import utils
-
-# enable psyco if available and in settings file
-try:
-    import psyco
-    psyco_available = True
-except ImportError:
-    logger.warning('Psyco Acceleration unavailable')
-    psyco_available = False
-
-if settings.fife.UsePsyco:
-    if psyco_available:
-        psyco.full()
-        logger.info('Psyco Acceleration enabled')
+      
+def main(args, opts):
+    settings = Settings(*args)
+    
+    settings.parpg.DataPath = abspath(settings.parpg.DataPath)
+    
+    levels = {'debug': logging.DEBUG,
+              'info': logging.INFO,
+              'warning': logging.WARNING,
+              'error': logging.ERROR,
+              'critical': logging.CRITICAL}
+    
+    #TODO: setup formating
+    logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
+    logger = logging.getLogger('parpg')
+    
+    try:
+        old_path = sys.path
+        sys.path = [settings.parpg.FifePath]
+        import fife
+    except AttributeError:
+        logger.warning('[parpg] section has no FifePath option')
+    except ImportError:
+        logger.critical("Could not import fife module. Please install fife or add "
+                        "'FifePath' to the [parpg] section of your settings file")
+        sys.exit(1)
+    finally:
+        sys.path = old_path
+    
+    from parpg.application import PARPGApplication
+    from parpg.common import utils
+    
+    # enable psyco if available and in settings file
+    try:
+        import psyco
+        psyco_available = True
+    except ImportError:
+        logger.warning('Psyco Acceleration unavailable')
+        psyco_available = False
+    
+    if settings.fife.UsePsyco:
+        if psyco_available:
+            psyco.full()
+            logger.info('Psyco Acceleration enabled')
+        else:
+            logger.warning('Please install psyco before attempting to use it'
+                            'Psyco Acceleration disabled')
     else:
-        logger.warning('Please install psyco before attempting to use it'
-                        'Psyco Acceleration disabled')
-else:
-    logger.info('Psycho Acceleration disabled')
-
-# run the game
-app = PARPGApplication(settings)
-app.run()
+        logger.info('Psycho Acceleration disabled')
+    
+    # run the game
+    app = PARPGApplication(settings)
+    app.run()