diff src/parpg/settings.py @ 11:4706e0194af3

Various improvements to the build process including support for self-contained builds. * Note that despite all of these changes PARPG still does not run because asset paths are not standardized, * Modified the SCons script so that by default running `scons` with no arguments creates a self-contained "build" under a build subdirectory to make in-source testing easier. To install PARPG, use `scons install` instead. * Got rid of the binary launcher and replaced it with a shell script for unix and a batch script for Windows (batch script is untested). The binary turned out to be too much trouble to maintain. * Modified the parpg.settings module and parpg.main entry script so that PARPG searches through several default search paths for configuration file(s). PARPG thus no longer crashes if it can't find a configuration file in any particular search path, but will crash it if can't find any configuration files. * Paths supplied to parpg.main are now appended as search paths for the configuration file(s). * Changed the default configuration file name to "parpg.cfg" to simplify searches. * Created the site_scons directory tree where SCons extensions and tools should be placed. * Created a new SCons builder, CopyRecurse, which can copy only certain files and folders from a directory tree using filters (files and folders that start with a leading dot "." e.g. ".svn" are ignored by default). * Added the CPython SCons tool (stands for Compile-Python - I didn't name it!), which provides the InstallPython builder for pre-compiling python sources before they are installed. However, it is currently broken and only installs the python sources.
author M. George Hansen <technopolitica@gmail.com>
date Tue, 31 May 2011 02:46:20 -0700
parents 1fd2201f5c36
children aa3d837024a3
line wrap: on
line diff
--- a/src/parpg/settings.py	Wed Jun 01 00:45:27 2011 -0700
+++ b/src/parpg/settings.py	Tue May 31 02:46:20 2011 -0700
@@ -129,7 +129,8 @@
     """ An object that represents a settings file, its sectons,
         and the options defined within those sections.
     """
-    def __init__(self, settings_path='', system_path='', user_path='', suffix='.cfg'):
+    def __init__(self, settings_path='', system_path='', user_path='',
+                 filename='parpg.cfg'):
         """ initializes a new settings object. If no paths are given, they are
             guessed based on whatever platform the script was run on.
 
@@ -157,13 +158,9 @@
             @param suffix: Suffix of the settings file that will be generated.
             @type suffix: string
         """
-        if not suffix.startswith('.'):
-            suffix = '.' + suffix
-
-        self.suffix = suffix
+        self.filename = filename
         self.settings_file = ''
-
-
+        
         self.paths = {}
         if not system_path and not user_path and not settings_path:
             # use platform-specific values as paths
@@ -224,40 +221,38 @@
         """
         
         if filenames is None:
-            filenames = [os.path.join(self.paths['settings'], 
-                                      'system{0}'.format(self.suffix)),
-                         os.path.join(self.paths['user'],
-                                      'user{0}'.format(self.suffix))]
+            filenames = [os.path.join(self.paths['settings'], self.filename),
+                         os.path.join(self.paths['user'], self.filename)]
         elif hasattr(filenames, 'split'):
             filenames = [filenames]
 
         for filename in filenames:
             section = None
-
-            try:
-                self.settings_file = open(filename, 'r').readlines()
-            except IOError as (errno, strerror):
-                if errno == 2:
-                    if os.path.basename(filename).startswith('system'):
-                        print ('{0} could not be found. Please supply a '
-                               'different path or generate a system settings '
-                               'file with:\n'
-                               'python2 -m parpg.settings').format(filename)
+            if os.path.exists(filename):
+                try:
+                    self.settings_file = open(filename, 'r').readlines()
+                except IOError as (errno, strerror):
+                    if errno == 2:
+                        if os.path.basename(filename).startswith('system'):
+                            print ('{0} could not be found. Please supply a '
+                                   'different path or generate a system settings '
+                                   'file with:\n'
+                                   'python2 -m parpg.settings').format(filename)
+                            sys.exit(1)
+                    else:
+                        print 'Error No. {0}: {1} {2}'.format(errno, filename, strerror)
                         sys.exit(1)
-                else:
-                    print 'Error No. {0}: {1} {2}'.format(errno, filename, strerror)
-                    sys.exit(1)
 
-            for line in self.settings_file:
-                if line.startswith('#') or line.strip() == '':
-                    continue
-                elif line.startswith('[') and line.endswith(']\n'):
-                    getattr(self, line[1:-2])
-                    section = line[1:-2]
-                else:
-                    option, value = [item.strip() 
-                                     for item in line.split('=', 1)]
-                    setattr(getattr(self, section), option, value)
+                for line in self.settings_file:
+                    if line.startswith('#') or line.strip() == '':
+                        continue
+                    elif line.startswith('[') and line.endswith(']\n'):
+                        getattr(self, line[1:-2])
+                        section = line[1:-2]
+                    else:
+                        option, value = [item.strip() 
+                                         for item in line.split('=', 1)]
+                        setattr(getattr(self, section), option, value)
 
     def write(self, filename=None):
         """ Writes a settings file based on the settings object's