|
| 1 | +# Copyright (C) 2024 Gavin John <[email protected]> |
| 2 | +# |
| 3 | +# This file is part of repology |
| 4 | +# |
| 5 | +# repology is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# repology is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with repology. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +import json |
| 19 | + |
| 20 | +from typing import Iterable |
| 21 | + |
| 22 | +from repology.package import LinkType |
| 23 | +from repology.packagemaker import NameType, PackageFactory, PackageMaker |
| 24 | +from repology.parsers import Parser |
| 25 | + |
| 26 | + |
| 27 | +class OpenVSXParser(Parser): |
| 28 | + def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMaker]: |
| 29 | + with open(path, 'r') as extdatafile: |
| 30 | + extension_data = json.load(extdatafile) |
| 31 | + raw_extensions = extension_data['extensions'] |
| 32 | + |
| 33 | + for extension in raw_extensions: |
| 34 | + with factory.begin() as pkg: |
| 35 | + # TODO: More metadata is available, it's just harder to fetch and will require its own fetcher, in all likelihood |
| 36 | + pkg.add_name('vscode-extension:{namespace}-{name}'.format(**extension), NameType.GENERIC_SRC_NAME) |
| 37 | + pkg.set_version(extension['version']) |
| 38 | + pkg.set_summary(extension['description']) |
| 39 | + pkg.add_maintainers('{namespace}@openvsx'.format(**extension)) |
| 40 | + pkg.add_links(LinkType.UPSTREAM_HOMEPAGE, 'https://open-vsx.org/extension/{namespace}/{name}'.format(**extension)) |
| 41 | + pkg.add_links(LinkType.UPSTREAM_DOWNLOAD, extension['files']['download']) |
| 42 | + |
| 43 | + yield pkg |
0 commit comments