Project

General

Profile

« Previous | Next » 

Revision f42f5c19

Added by koszko over 1 year ago

incorporate version 2 of Hydrilla JSON schemas

View differences:

src/hydrilla/builder/build.py
51 51

  
52 52
_ = util.translation(here / 'locales').gettext
53 53

  
54
index_validator = util.validator_for('package_source-2.schema.json')
54
def index_validator(major_schema_version):
55
    """
56
    Create an index.json schema validator specific to the requested schema
57
    version series.
58
    """
59
    exact_version = {1: '1.0.1', 2: '2'}[major_schema_version]
60

  
61
    return util.validator_for(f'package_source-{exact_version}.schema.json')
55 62

  
56 63
schemas_root = 'https://hydrilla.koszko.org/schemas'
57 64

  
......
158 165
        if not index_json_path.is_absolute():
159 166
            index_json_path = (self.srcdir / index_json_path)
160 167

  
161
        with open(index_json_path, 'rt') as index_file:
162
            index_json_text = index_file.read()
168
        index_obj, major = util.load_instance_from_file(index_json_path)
163 169

  
164
        index_obj = json.loads(util.strip_json_comments(index_json_text))
170
        if major not in (1, 2):
171
            msg = _('unknown_schema_package_source_{}')\
172
                .format(index_json_path)
173
            raise util.UnknownSchemaError(msg)
165 174

  
166 175
        index_desired_path = PurePosixPath('index.json')
167 176
        self.files_by_path[index_desired_path] = \
168
            FileRef(index_desired_path, index_json_text.encode())
177
            FileRef(index_desired_path, index_json_path.read_bytes())
169 178

  
170
        self._process_index_json(index_obj)
179
        self._process_index_json(index_obj, major)
171 180

  
172 181
    def _process_file(self, filename: Union[str, PurePosixPath],
173 182
                      piggybacked: Piggybacked,
......
308 317
        props_in_ref = ('type', 'identifier', 'version', 'long_name')
309 318
        return dict([(prop, new_item_obj[prop]) for prop in props_in_ref])
310 319

  
311
    def _process_index_json(self, index_obj: dict):
320
    def _process_index_json(self, index_obj: dict,
321
                            major_schema_version: int) -> None:
312 322
        """
313 323
        Process 'index_obj' as contents of source package's index.json and store
314 324
        in memory this source package's zipfile as well as package's individual
315 325
        files and computed definitions of the source package and items defined
316 326
        in it.
317 327
        """
318
        index_validator.validate(index_obj)
328
        index_validator(major_schema_version).validate(index_obj)
329

  
319 330
        match = re.match(r'.*-((([1-9][0-9]*|0)\.)+)schema\.json$',
320 331
                         index_obj['$schema'])
321 332
        self.source_schema_ver = \

Also available in: Unified diff