예제 #1
0
class YAMLDefinition(object):
    def __init__(self, db_path=None, db_default_file=None,
                 db_cache_path=None):
        db_cache_path = db_cache_path or conf.get('db_cache_path') or db_path
        self.yback = YAMLBackend(
            db_path or conf.get('db_path'),
            db_default_file=db_default_file or conf.get('db_default_file'),
            db_cache_path=db_cache_path)
        self.yback.load_db()
        self.hashes_str = SHA.new(
            "".join(self.yback.hashes).encode(errors='ignore')).hexdigest()
        self.default_data, self.data = self.yback.get_data()
        self._merge()

    def _check_basic(self, key, schema, identifier):
        """ Verify schema and no data duplicated
        """
        issues = []
        ids = set()
        for d in self.data:
            data = d.get(key, {})
            try:
                schema_validate({key: data},
                                yaml.load(schema))
            except Exception as e:
                issues.append(e.message)
            duplicated = set(data.keys()) & ids
            if duplicated:
                issues.append("%s IDs [%s,] are duplicated" % (
                              identifier, ",".join(duplicated)))
            ids.update(set(data.keys()))
        return ids, issues
예제 #2
0
class YAMLDefinition(object):
    def __init__(self, db_path=None, db_default_file=None,
                 db_cache_path=None):
        db_cache_path = db_cache_path or conf.get('db_cache_path') or db_path
        self.yback = YAMLBackend(
            db_path or conf.get('db_path'),
            db_default_file=db_default_file or conf.get('db_default_file'),
            db_cache_path=db_cache_path)
        self.yback.load_db()
        self.hashes_str = SHA.new(
            "".join(self.yback.hashes).encode(errors='ignore')).hexdigest()
        self.default_data, self.data = self.yback.get_data()
        self._merge()

    def _check_basic(self, key, schema, identifier):
        """ Verify schema and no data duplicated
        """
        issues = []
        ids = set()
        for d in self.data:
            data = d.get(key, {})
            try:
                schema_validate({key: data},
                                yaml.load(schema))
            except Exception as e:
                issues.append(e.message)
            duplicated = set(data.keys()) & ids
            if duplicated:
                issues.append("%s IDs [%s,] are duplicated" % (
                              identifier, ",".join(duplicated)))
            ids.update(set(data.keys()))
        return ids, issues
예제 #3
0
 def __init__(self, db_path=None, db_default_file=None):
     self.yback = YAMLBackend(db_path or conf.db_path,
                              db_default_file=db_default_file
                              or conf.get('db_default_file'))
     self.yback.load_db()
     self.default_data, self.data = self.yback.get_data()
     self._merge()
예제 #4
0
파일: __init__.py 프로젝트: ohe/repoxplorer
 def __init__(self, db_path=None, db_default_file=None,
              db_cache_path=None):
     db_cache_path = db_cache_path or conf.get('db_cache_path') or db_path
     self.yback = YAMLBackend(
         db_path or conf.get('db_path'),
         db_default_file=db_default_file or conf.get('db_default_file'),
         db_cache_path=db_cache_path)
     self.yback.load_db()
     self.hashes_str = SHA.new("".join(self.yback.hashes)).hexdigest()
     self.default_data, self.data = self.yback.get_data()
     self._merge()
예제 #5
0
    def test_yamlbackend_load(self):
        f1 = """
---
key: value
"""
        f2 = """
---
key2: value2
"""
        files = {'f1.yaml': f1, 'f2.yaml': f2}
        self.create_db(files)
        backend = YAMLBackend(db_path=self.db)
        backend.load_db()
        default_data, data = backend.get_data()
        self.assertEqual(default_data, None)
        self.assertEqual(len(data), 2)
예제 #6
0
    def test_yamlbackend_load_with_default(self):
        f1 = """
---
key: value
"""
        f2 = """
---
key2: value2
"""
        files = {'default.yaml': f1, 'f2.yaml': f2}
        self.create_db(files)
        backend = YAMLBackend(
            db_path=self.db,
            db_default_file=os.path.join(self.db, 'default.yaml'))
        backend.load_db()
        default_data, data = backend.get_data()
        self.assertDictEqual(default_data, {'key': 'value'})
        self.assertEqual(len(data), 1)
        self.assertDictEqual(data[0], {'key2': 'value2'})
예제 #7
0
 def __init__(self, db_path=None, db_default_file=None,
              db_cache_path=None):
     db_cache_path = db_cache_path or conf.get('db_cache_path') or db_path
     self.yback = YAMLBackend(
         db_path or conf.get('db_path'),
         db_default_file=db_default_file or conf.get('db_default_file'),
         db_cache_path=db_cache_path)
     self.yback.load_db()
     self.hashes_str = SHA.new(
         "".join(self.yback.hashes).encode(errors='ignore')).hexdigest()
     self.default_data, self.data = self.yback.get_data()
     self._merge()