home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.5)
-
- from base.g import *
- import os.path as os
- import re
- import glob
-
- class ModelData:
-
- def __init__(self, root_path = None):
- if root_path is None:
- self.root_path = prop.models_dir
- else:
- self.root_path = root_path
- self._ModelData__cache = { }
- self.reset_includes()
- self.sec = re.compile('^\\[(.*)\\]')
- self.inc = re.compile('^\\%include (.*)', re.IGNORECASE)
- self.inc_line = re.compile('^\\%(.*)\\%')
- self.eq = re.compile('^([^=]+)=(.*)')
-
-
- def read_all_files(self, unreleased = True):
- released_dat = os.path.join(self.root_path, 'models.dat')
- log.debug('Reading file: %s' % released_dat)
- self.read_section(released_dat)
- unreleased_dir = os.path.join(self.root_path, 'unreleased')
- if unreleased and os.path.exists(unreleased_dir):
- unreleased_dat = os.path.join(self.root_path, 'unreleased', 'unreleased.dat')
- log.debug('Reading file: %s' % unreleased_dat)
- self.read_section(unreleased_dat)
-
- return self._ModelData__cache
-
-
- def read_section(self, filename, section = None, is_include = False):
- found = False
- in_section = False
- if section is not None:
- section = section.lower()
- if is_include:
- log.debug('Searching for include [%s] in file %s' % (section, filename))
- else:
- log.debug('Searching for section [%s] in file %s' % (section, filename))
-
- if is_include:
- cache = self._ModelData__includes
- else:
- cache = self._ModelData__cache
-
- try:
- fd = file(filename)
- except IOError:
- e = None
- log.error('I/O Error: %s (%s)' % (filename, e.strerror))
- return False
-
- while True:
- line = fd.readline()
- if not line:
- break
-
- if line[0] in ('#', ';'):
- continue
-
- if line[0] == '[':
- if in_section and section is not None:
- break
-
- match = self.sec.search(line)
- if match is not None:
- in_section = True
- read_section = match.group(1).lower()
- if section is not None:
- found = in_section = read_section == section
-
- if in_section:
- if section is not None:
- log.debug('Found section [%s] in file %s' % (read_section, filename))
-
- cache[read_section] = { }
-
- in_section
- continue
-
- if line[0] == '%':
- match = self.inc.match(line)
- if match is not None:
- inc_file = match.group(1)
- log.debug('Found include file directive: %%include %s' % inc_file)
- self._ModelData__include_files.append(os.path.join(os.path.dirname(filename), inc_file))
- continue
-
- if in_section:
- match = self.inc_line.match(line)
- if match is not None:
- inc_sect = match.group(1)
- log.debug('Found include directive %%%s%%' % inc_sect)
-
- try:
- self._ModelData__includes[inc_sect]
- except KeyError:
- for inc in self._ModelData__include_files:
- if self.read_section(inc, inc_sect, True):
- break
- continue
-
-
-
- None<EXCEPTION MATCH>KeyError
-
-
- if in_section:
- match = self.eq.search(line)
- if match is not None:
- value = match.group(2)
-
- try:
- value = int(value)
- except ValueError:
- pass
-
- cache[read_section][match.group(1)] = value
-
- match is not None
- fd.close()
- return found
-
-
- def reset_includes(self):
- self._ModelData__include_files = []
- self._ModelData__includes = { }
-
-
- def __getitem__(self, model):
- model = model.lower()
-
- try:
- return self._ModelData__cache[model]
- except:
- log.debug('Cache miss: %s' % model)
- released_dat = os.path.join(self.root_path, 'models.dat')
- log.debug('Reading file: %s' % released_dat)
- if self.read_section(released_dat, model):
- return self._ModelData__cache[model]
-
- unreleased_dir = os.path.join(self.root_path, 'unreleased')
- if os.path.exists(unreleased_dir):
- unreleased_dat = os.path.join(self.root_path, 'unreleased', 'unreleased.dat')
- log.debug('Reading file: %s' % unreleased_dat)
- if self.read_section(unreleased_dat, model):
- return self._ModelData__cache[model]
-
-
- return { }
-
-
-
- def all_models(self):
- return self._ModelData__cache
-
-
-