Example #1
0
 def get_format_info(self, section, specific=None):
     """Queries the config file and returns the formatting information
     Args:
         section (string): the section of the config file to check
         specific (string):
     return (string or dict): string if just getting a format
                              list if getting specific but not actually format
                              dictionary if getting section
     """
     cfg_file = tb.get_config_filepath()
     try:
         parser = ConfigParser.SafeConfigParser()
         parser.read( cfg_file )
         # Get all format names
         if specific == 'format':
             return parser.get(section, specific)
         # Config is just separated by spaces so get raw and split
         elif specific:
             return parser.get(section, specific, raw=True).split(' ')
         # Otherwise we just want the entire section split into a dictionary
         else:
             result = {}
             section_options = parser.options(section)
             for section_option in section_options:
                 result[section_option] = parser.get(section, section_option)
             return result
     except IOError as exc:
         raise IOError("%s: %s" % ( _cfg_file, exc.strerror ))
Example #2
0
    def __init__(self, format=None):
        super(AssetNameFormatter, self).__setattr__("_format_table", {})
        self._suffix_lookup = {}
        self._table_order = {}
        self.reset_table()
        self._format = None
        self._format_order = None

        _cfg_file = tb.get_config_filepath()
        self._parser = ConfigParser.SafeConfigParser()
        self._parser.read(_cfg_file)
        # get all format names
        for section_name in self._parser.sections():
            if section_name == "naming_conventions":
                for name, value in self._parser.items(section_name):
                    self._suffix_lookup[name] = value
        # set the format order
        self._set_format(self._parser.get("naming_format", "format"))
        if format:
            self._set_format(format)