Example #1
0
def enumerate_entries_from_file(filename):
    ''' Yields (filename, num_entry), entry '''
    with open(filename) as f:
        try:
            parsed = yaml.load(f)
        except YAMLError as e:
            msg = 'Cannot parse YAML file %s:\n%s' % (friendly_path(filename), e)
            raise SyntaxMistake(msg)  # TODO: make UserError

        if parsed is None:
            logger.warning('Found an empty file %r.' % friendly_path(filename))
        else:
            if not isinstance(parsed, list):
                msg = ('Expect the file %r to contain a list of dicts,'
                        ' found %s.' % (friendly_path(filename),
                                         describe_type(parsed)))
                raise SyntaxMistake(msg)
                 
            if  not all([isinstance(x, dict) for x in parsed]):
                msg = ('Expect the file %r to contain a list of dicts.' % 
                        filename)
                raise SyntaxMistake(msg)

            if not parsed:
                logger.warning('Found an empty file %r.' % friendly_path(filename))

            for num_entry, entry in enumerate(parsed):
                yield (filename, num_entry), entry
Example #2
0
   def add_class_generic(self, name, pattern, object_class):
       if not '.yaml' in pattern or not '*' in pattern:
           logger.warning('suspicious pattern %r' % pattern)
       from .code_desc import GenericInstance
 
       return self.add_class(name=name, pattern=pattern,
                             check=GenericCodeDescCheck(name),
                             instance=GenericInstance(object_class),
                             object_check=GenericIsinstance(object_class))
Example #3
0
 def get_default_dir(self):
     logger.warning('No default dir given, using current dir.')
     return "."
Example #4
0
def check_exists(key, filename):
    if not os.path.exists(filename):
        msg = ('I resolved the key %r to the path\n\t%r\nbut it does not exist.'
               % (key, filename))
        logger.warning(msg)