Skip to content

Commit

Permalink
Modernize freebsd, pkgsrc INDEX parsers
Browse files Browse the repository at this point in the history
- Switch to factory context manager
- Stricten format checks
- Switch to add_links
  • Loading branch information
AMDmi3 committed Oct 4, 2024
1 parent d15cb00 commit 830bef2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
36 changes: 17 additions & 19 deletions repology/parsers/parsers/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

from typing import Iterable

from repology.logger import Logger
from repology.packagemaker import NameType, PackageFactory, PackageMaker
from repology.package import LinkType
from repology.parsers import Parser
from repology.parsers.maintainers import extract_maintainers
from repology.parsers.versions import VersionStripper
Expand All @@ -30,21 +30,19 @@ def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMake

with open(path, encoding='utf-8') as indexfile:
for line in indexfile:
pkg = factory.begin()

fields = line.strip().split('|')
if len(fields) != 13:
pkg.log('skipping, unexpected number of fields {}'.format(len(fields)), severity=Logger.ERROR)
continue

name, version = fields[0].rsplit('-', 1)

pkg.add_name(name, NameType.BSD_PKGNAME)
pkg.add_name('/'.join(fields[1].rsplit('/', 2)[1:]), NameType.BSD_ORIGIN)
pkg.set_version(version, normalize_version)
pkg.set_summary(fields[3])
pkg.add_maintainers(extract_maintainers(fields[5]))
pkg.add_categories(fields[6].split())
pkg.add_homepages(fields[9].split())

yield pkg
with factory.begin() as pkg:
fields = line.strip().split('|')
if len(fields) != 13:
raise RuntimeError(f'unexpected number of fields {len(fields)} != 13')

name, version = fields[0].rsplit('-', 1)

pkg.add_name(name, NameType.BSD_PKGNAME)
pkg.add_name('/'.join(fields[1].rsplit('/', 2)[1:]), NameType.BSD_ORIGIN)
pkg.set_version(version, normalize_version)
pkg.set_summary(fields[3])
pkg.add_maintainers(extract_maintainers(fields[5]))
pkg.add_categories(fields[6].split())
pkg.add_links(LinkType.UPSTREAM_HOMEPAGE, fields[9].split())

yield pkg
39 changes: 18 additions & 21 deletions repology/parsers/parsers/pkgsrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

from typing import Iterable

from repology.logger import Logger
from repology.packagemaker import NameType, PackageFactory, PackageMaker
from repology.package import LinkType
from repology.parsers import Parser
from repology.parsers.maintainers import extract_maintainers
from repology.parsers.versions import VersionStripper
Expand All @@ -30,28 +30,25 @@ def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMake

with open(path, encoding='utf-8') as indexfile:
for line in indexfile:
pkg = factory.begin()
with factory.begin() as pkg:
fields = line.strip().split('|')
if len(fields) != 12:
raise RuntimeError(f'unexpected number of fields {len(fields)} != 12')
if not fields[0]:
raise RuntimeError('empty package name')

fields = line.strip().split('|')
if len(fields) != 12:
pkg.log('skipping, unexpected number of fields {}'.format(len(fields)), severity=Logger.ERROR)
continue
if not fields[0]:
pkg.log('skipping, empty first field', severity=Logger.ERROR)
continue
name, version = fields[0].rsplit('-', 1)

name, version = fields[0].rsplit('-', 1)
pkg.add_name(name, NameType.BSD_PKGNAME)
pkg.add_name(fields[1], NameType.BSD_ORIGIN)
pkg.set_version(version, normalize_version)
pkg.set_summary(fields[3])

pkg.add_name(name, NameType.BSD_PKGNAME)
pkg.add_name(fields[1], NameType.BSD_ORIGIN)
pkg.set_version(version, normalize_version)
pkg.set_summary(fields[3])
# sometimes OWNER variable is used in which case
# there's no MAINTAINER OWNER doesn't get to INDEX
pkg.add_maintainers(extract_maintainers(fields[5]))

# sometimes OWNER variable is used in which case
# there's no MAINTAINER OWNER doesn't get to INDEX
pkg.add_maintainers(extract_maintainers(fields[5]))
pkg.add_categories(fields[6].split())
pkg.add_links(LinkType.UPSTREAM_HOMEPAGE, fields[11].split())

pkg.add_categories(fields[6].split())
pkg.add_homepages(fields[11])

yield pkg
yield pkg

0 comments on commit 830bef2

Please sign in to comment.