Changeset 4152

Show
Ignore:
Timestamp:
02/21/09 19:47:49 (4 years ago)
Author:
gpolo
Message:

Fixed ticket #172 (also cleaned up the add_profile code)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/umitCore/UmitConf.py

    r3953 r4152  
    2525 
    2626from types import StringTypes 
    27 from ConfigParser import NoSectionError, NoOptionError 
     27from ConfigParser import NoSectionError, NoOptionError, DuplicateSectionError 
    2828 
    2929from umitCore.Paths import Path 
     
    196196    def add_profile(self, profile_name, **attributes): 
    197197        log.debug(">>> Add Profile '%s': %s" % (profile_name, attributes)) 
    198         try: self.add_section(profile_name) 
    199         except: return None 
    200          
    201         [self._set_it(profile_name, attr, attributes[attr]) \ 
    202          for attr in attributes if attr != "options"] 
     198        try: 
     199            self.add_section(profile_name) 
     200        except DuplicateSectionError: 
     201            return None 
     202 
     203        for attr in attributes: 
     204            if attr != "options": 
     205                self._set_it(profile_name, attr, attributes[attr]) 
     206 
    203207        options = attributes["options"] 
    204         if type(options) in StringTypes: 
     208        if isinstance(options, basestring): 
    205209            self._set_it(profile_name, "options", options) 
    206         elif type(options) == type({}): 
     210            # Assuming there are no values for these options 
     211            options = {} 
     212        elif isinstance(options, dict): 
    207213            self._set_it(profile_name, "options", ",".join(options.keys())) 
    208214