(cls, yaml_data, package_only=False)
| 53 | |
| 54 | @classmethod |
| 55 | def _parse(cls, yaml_data, package_only=False): |
| 56 | package_data = models.PackageData( |
| 57 | datasource_id=cls.datasource_id, |
| 58 | type=cls.default_package_type, |
| 59 | qualifiers=dict( |
| 60 | arch=yaml_data.get('arch'), |
| 61 | origin=yaml_data.get('origin'), |
| 62 | ) |
| 63 | ) |
| 64 | |
| 65 | # mapping of top level manifest items to the PackageData object field name |
| 66 | plain_fields = [ |
| 67 | ('name', 'name'), |
| 68 | ('version', 'version'), |
| 69 | ('www', 'homepage_url'), |
| 70 | ('desc', 'description'), |
| 71 | ('categories', 'keywords'), |
| 72 | ] |
| 73 | |
| 74 | for source, target in plain_fields: |
| 75 | value = yaml_data.get(source) |
| 76 | if value: |
| 77 | if isinstance(value, str): |
| 78 | value = value.strip() |
| 79 | if value: |
| 80 | setattr(package_data, target, value) |
| 81 | |
| 82 | # mapping of top level +COMPACT_MANIFEST items to a function accepting as |
| 83 | # arguments the package.json element value and returning an iterable of key, |
| 84 | # values Package Object to update |
| 85 | field_mappers = [ |
| 86 | ('maintainer', maintainer_mapper), |
| 87 | ('origin', origin_mapper), |
| 88 | ('arch', arch_mapper), |
| 89 | ] |
| 90 | |
| 91 | for source, func in field_mappers: |
| 92 | logger.debug('parse: %(source)r, %(func)r' % locals()) |
| 93 | value = yaml_data.get(source) or None |
| 94 | if value: |
| 95 | func(value, package_data) |
| 96 | |
| 97 | # license_mapper needs multiple fields |
| 98 | license_mapper(yaml_data, package_data) |
| 99 | |
| 100 | if not package_only: |
| 101 | cls.populate_license_fields(package_data) |
| 102 | |
| 103 | if TRACE: |
| 104 | logger_debug( |
| 105 | f"package_data: {package_data}" |
| 106 | ) |
| 107 | |
| 108 | return package_data |
| 109 | |
| 110 | @classmethod |
| 111 | def parse(cls, location, package_only=False): |
no test coverage detected