Ignore:
Timestamp:
03/07/11 05:14:00 (8 years ago)
Author:
aspidites
Message:

Patch by Aspidites:

  • removed files related to windows packaging
  • simplified settings module API:

+ paths argument no longer exists. There is now exactly

3 arguments: system_path, user_path, and prefix, which

will eventually be explained in documentation

+ user config file is now properly created, leaving the

system config file untouched

+ by default, the new suffix is '.cfg'.
+ sections and options are now properties instead of callables

  • updated menus.py to cope with these minor changes
  • updated setup scripts (both) with missing path information

+ only thing remaining for the windows installer is to test on

on a windows machine (as opposed to wine), and to get
prerequisites installed correctly (fife installer giving trouble)

Location:
branches/active/character_customization/game/parpg
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/active/character_customization/game/parpg/gamescenecontroller.py

    r774 r790  
    131131            # F7 saves a screenshot to fife/clients/parpg/screenshots 
    132132             
    133             screenshot_file = "screenshots/screen-%s.png" % \ 
    134                     (datetime.now().strftime('%Y-%m-%d-%H-%M-%S')) 
     133            screenshotdir = model.settings.parpg.ScreenshotsDirectory 
     134            screenshot_file = os.path.join(screenshotdir,  
     135                                           'screen-{0}.png'.format( 
     136                                           datetime.now().strftime( 
     137                                           '%Y-%m-%d-%H-%M-%S'))) 
    135138            print "PARPG: Saved:", screenshot_file 
    136139            self.engine.getRenderBackend().captureScreen(screenshot_file) 
  • branches/active/character_customization/game/parpg/gui/menus.py

    r768 r790  
    139139        self.settings.fife.FullScreen = fullscreen 
    140140        self.settings.fife.PlaySounds = sound 
    141         self.settings.write(self.settings.paths[-1]) 
     141        self.settings.write() 
    142142        
    143143        self.restart_dialog.show() 
  • branches/active/character_customization/game/parpg/settings.py

    r772 r790  
    8888 
    8989        return return_value 
    90         """ 
    91         try: 
    92             return dict((key, value[1:-1]) for (key, value) in  
    93                         object.__getattribute__(self, option) if 
    94                         value.startswith("\"") and value.endswith("\"")) 
    95         except TypeError: 
    96             return object.__getattribute__(self, option) 
    97         """ 
    98         #return object.__getattribute__(self, option) 
    99  
     90 
     91    @property 
    10092    def options(self): 
    10193        """ Returns a dictionary of existing options """ 
     
    111103        and the options defined within those sections. 
    112104    """ 
    113     def __init__(self, **kwargs): 
     105    def __init__(self, system_path, user_path=None, suffix='.cfg'): 
    114106        """ initializes a new settings object. 
    115107 
     
    133125        """ 
    134126 
     127        self.suffix = suffix 
    135128        self.settings_file = '' 
    136         self.paths = kwargs.get('paths', None) 
    137         self.filename = kwargs.get('filename', 'settings.ini') 
    138  
    139         if self.paths is not None: 
    140             self.read(self.paths) 
    141         else: 
    142             self.paths = '.' 
     129 
     130        if user_path is None: 
     131            user_path = system_path 
     132 
     133        self.filenames = {'system': os.path.join(system_path,  
     134                                                 'system{0}'.format(self.suffix)), 
     135                          'user': os.path.join(user_path, 
     136                                               'user{0}'.format(self.suffix))} 
     137 
     138        self.read() 
    143139 
    144140    def __getattr__(self, name): 
     
    159155        return getattr(self, name) 
    160156 
    161     def read(self, paths=None, filename=None): 
     157    def read(self, filenames=None): 
    162158        """ Reads a settings file and populates the settings object  
    163159            with its sections and options. Calling this method without 
     
    168164            @type path: string 
    169165        """ 
    170         if filename is not None: 
    171             self.filename = filename 
    172  
    173         if paths is None: 
    174             paths = self.paths 
    175  
    176         if hasattr(paths, 'split'): 
    177             self.paths = [paths] 
    178         else: 
    179             self.paths = paths 
    180  
    181         for path in self.paths: 
    182             location = os.path.join(path, self.filename) 
     166         
     167        if filenames is None: 
     168            filenames = [self.filenames['system'], self.filenames['user']] 
     169 
     170        for filename in filenames: 
    183171            section = None 
    184172            try: 
    185                 self.settings_file = open(location, 'r').readlines() 
     173                self.settings_file = open(filename, 'r').readlines() 
    186174            except IOError: 
    187175                pass 
     
    198186                    setattr(getattr(self, section), option, value) 
    199187 
    200     def write(self, path=None, filename=None): 
     188    def write(self, filename=None): 
    201189        """ Writes a settings file based on the settings object's  
    202190            sections and options 
     
    207195            @type path: string 
    208196        """ 
    209         if path is None: 
    210             path = self.paths[-1] 
    211  
    212197        if filename is None: 
    213             filename = self.filename 
    214  
    215         for section in self.sections(): 
     198            filename = self.filenames['user'] 
     199 
     200        for section in self.sections: 
    216201            if '[{0}]\n'.format(section) not in self.settings_file: 
    217202                self.settings_file.append('\n[{0}]\n'.format(section)) 
    218                 for option, value in getattr(self, section).options().iteritems(): 
     203                for option, value in getattr(self, section).options.iteritems(): 
    219204                    template = '{0} = {1}\n'.format(option, value) 
    220205                    self.settings_file.append(template) 
     
    224209 
    225210                for option, value in getattr(self,  
    226                                              section).options().iteritems(): 
     211                                             section).options.iteritems(): 
    227212                    if hasattr(value, 'sort'): 
    228213                        value = '[{0}]'.format(', '.join(value)) 
     
    242227                        self.settings_file.insert(start_of_section, template) 
    243228 
    244         location = os.path.join(path, filename) 
    245         with open(location, 'w') as out_stream: 
     229        with open(filename, 'w') as out_stream: 
    246230            for line in self.settings_file: 
    247231                out_stream.write(line) 
    248232 
     233    @property 
    249234    def sections(self): 
    250235        """ Returns a list of existing sections""" 
    251236        sections = self.__dict__.keys() 
    252237        sections.pop(sections.index('settings_file')) 
    253         sections.pop(sections.index('paths')) 
    254         sections.pop(sections.index('filename')) 
     238        sections.pop(sections.index('filenames')) 
     239        sections.pop(sections.index('suffix')) 
    255240         
    256241        return sections 
Note: See TracChangeset for help on using the changeset viewer.