@@ -317,9 +317,12 @@ def get_gnu_data_from_purl(purl):
317317 """Generate `Package` object from the `purl` string of gnu type"""
318318 purl = PackageURL .from_string (purl )
319319 source_archive_url = f"https://ftp.gnu.org/pub/gnu/{ purl .name } /"
320- regex = r"^({}-)([\w.-]*)(.tar.gz)$" .format (purl .name )
320+ version_regex_template = r"^({}-)(?P<version>[\w.-]*)(.tar.gz)$"
321+ version_regex = re .compile (version_regex_template .format (re .escape (purl .name )))
321322
322- yield from extract_packages_from_listing (purl , source_archive_url , regex , [])
323+ yield from extract_packages_from_listing (
324+ purl , source_archive_url , version_regex , []
325+ )
323326
324327
325328@dataclasses .dataclass
@@ -333,8 +336,8 @@ class DirectoryListedSource:
333336 "description" : "Flag indicating whether the archives are nested within another directory"
334337 },
335338 )
336- source_archive_regex : str = dataclasses .field (
337- default = "" ,
339+ source_archive_regex : re . Pattern = dataclasses .field (
340+ default = None ,
338341 metadata = {
339342 "description" : "Regular expression pattern to match files in the directory listing."
340343 },
@@ -368,7 +371,9 @@ def get_package_info(cls, package_url):
368371class IpkgDirectoryListedSource (DirectoryListedSource ):
369372 source_url = "https://web.archive.org/web/20090326020239/http://handhelds.org/download/packages/ipkg/"
370373 is_nested = False
371- source_archive_regex = r"^(ipkg[-_])([\w.-]*)(_arm.ipk|.tar.gz)$"
374+ source_archive_regex = re .compile (
375+ r"^(ipkg[-_])(?P<version>[\w.-]*)(_arm.ipk|.tar.gz)$"
376+ )
372377 ignored_files_and_dir = []
373378
374379 @classmethod
@@ -398,132 +403,144 @@ def get_package_info(cls, package_url):
398403class UtilLinuxDirectoryListedSource (DirectoryListedSource ):
399404 source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/"
400405 is_nested = True
401- source_archive_regex = r"^(util-linux-)([\w.-]*)(.tar.gz)$"
406+ source_archive_regex = re . compile ( r"^(util-linux-)(?P<version> [\w.-]*)(.tar.gz)$" )
402407 ignored_files_and_dir = []
403408
404409
405410class BusyBoxDirectoryListedSource (DirectoryListedSource ):
406411 source_url = "https://www.busybox.net/downloads/"
407- source_archive_regex = r"^(busybox-)([\w.-]*)(.tar.bz2)$"
412+ source_archive_regex = re . compile ( r"^(busybox-)(?P<version> [\w.-]*)(.tar.bz2)$" )
408413 is_nested = False
409414 ignored_files_and_dir = []
410415
411416
412417class UclibcDirectoryListedSource (DirectoryListedSource ):
413418 source_url = "https://www.uclibc.org/downloads/"
414- source_archive_regex = r"^(uClibc-)([\w.-]*)(.tar.gz)$"
419+ source_archive_regex = re . compile ( r"^(uClibc-)(?P<version> [\w.-]*)(.tar.gz)$" )
415420 is_nested = False
416421 ignored_files_and_dir = []
417422
418423
419424class UclibcNGDirectoryListedSource (DirectoryListedSource ):
420425 source_url = "https://downloads.uclibc-ng.org/releases/"
421- source_archive_regex = r"^(uClibc-ng-)([\w.-]*)(.tar.gz)$"
426+ source_archive_regex = re . compile ( r"^(uClibc-ng-)(?P<version> [\w.-]*)(.tar.gz)$" )
422427 is_nested = True
423428 ignored_files_and_dir = []
424429
425430
426431class Bzip2DirectoryListedSource (DirectoryListedSource ):
427432 source_url = "https://sourceware.org/pub/bzip2/"
428- source_archive_regex = r"^(bzip2-)([\w.-]*)(.tar.gz)$"
433+ source_archive_regex = re . compile ( r"^(bzip2-)(?P<version> [\w.-]*)(.tar.gz)$" )
429434 is_nested = False
430435 ignored_files_and_dir = []
431436
432437
433438class OpenSSHDirectoryListedSource (DirectoryListedSource ):
434439 source_url = "https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/"
435- source_archive_regex = r"^(openssh-)([\w.-]*)(.tgz|.tar.gz)$"
440+ source_archive_regex = re . compile ( r"^(openssh-)(?P<version> [\w.-]*)(.tgz|.tar.gz)$" )
436441 is_nested = False
437442 ignored_files_and_dir = []
438443
439444
440445class DnsmasqDirectoryListedSource (DirectoryListedSource ):
441446 source_url = "https://thekelleys.org.uk/dnsmasq/"
442- source_archive_regex = r"^(dnsmasq-)([\w.-]*)(.tar.xz|.tar.gz)$"
447+ source_archive_regex = re .compile (
448+ r"^(dnsmasq-)(?P<version>[\w.-]*)(.tar.xz|.tar.gz)$"
449+ )
443450 is_nested = False
444451 ignored_files_and_dir = []
445452
446453
447454class EbtablesDirectoryListedSource (DirectoryListedSource ):
448455 source_url = "https://www.netfilter.org/pub/ebtables/"
449- source_archive_regex = r"^(ebtables-)([\w.-]*)(.tar.gz)$"
456+ source_archive_regex = re . compile ( r"^(ebtables-)(?P<version> [\w.-]*)(.tar.gz)$" )
450457 is_nested = False
451458 ignored_files_and_dir = []
452459
453460
454461class HostapdDirectoryListedSource (DirectoryListedSource ):
455462 source_url = "https://w1.fi/releases/"
456- source_archive_regex = r"^(hostapd-)([\w.-]*)(.tar.gz)$"
463+ source_archive_regex = re . compile ( r"^(hostapd-)(?P<version> [\w.-]*)(.tar.gz)$" )
457464 is_nested = False
458465 ignored_files_and_dir = []
459466
460467
461468class Iproute2DirectoryListedSource (DirectoryListedSource ):
462469 source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/net/iproute2/"
463- source_archive_regex = r"^(iproute2-)([\w.-]*)(.tar.xz|.tar.gz)$"
470+ source_archive_regex = re .compile (
471+ r"^(iproute2-)(?P<version>[\w.-]*)(.tar.xz|.tar.gz)$"
472+ )
464473 is_nested = False
465474 ignored_files_and_dir = []
466475
467476
468477class IptablesDirectoryListedSource (DirectoryListedSource ):
469478 source_url = "https://www.netfilter.org/pub/iptables/"
470- source_archive_regex = r"^(iptables-)([\w.-]*)(.tar.bz2)$"
479+ source_archive_regex = re . compile ( r"^(iptables-)(?P<version> [\w.-]*)(.tar.bz2)$" )
471480 is_nested = False
472481 ignored_files_and_dir = []
473482
474483
475484class LibnlDirectoryListedSource (DirectoryListedSource ):
476485 source_url = "https://www.infradead.org/~tgr/libnl/files/"
477- source_archive_regex = r"^(libnl-)([\w.-]*)(.tar.gz)$"
486+ source_archive_regex = re . compile ( r"^(libnl-)(?P<version> [\w.-]*)(.tar.gz)$" )
478487 is_nested = False
479488 ignored_files_and_dir = []
480489
481490
482491class LighttpdDirectoryListedSource (DirectoryListedSource ):
483492 source_url = "https://download.lighttpd.net/lighttpd/releases-1.4.x/"
484- source_archive_regex = r"^(lighttpd-)([\w.-]*)(.tar.gz)$"
493+ source_archive_regex = re . compile ( r"^(lighttpd-)(?P<version> [\w.-]*)(.tar.gz)$" )
485494 is_nested = False
486495 ignored_files_and_dir = []
487496
488497
489498class NftablesDirectoryListedSource (DirectoryListedSource ):
490499 source_url = "https://www.netfilter.org/pub/nftables/"
491- source_archive_regex = r"^(nftables-)([\w.-]*)(.tar.xz|.tar.bz2)$"
500+ source_archive_regex = re .compile (
501+ r"^(nftables-)(?P<version>[\w.-]*)(.tar.xz|.tar.bz2)$"
502+ )
492503 is_nested = False
493504 ignored_files_and_dir = []
494505
495506
496507class WpaSupplicantDirectoryListedSource (DirectoryListedSource ):
497508 source_url = "https://w1.fi/releases/"
498- source_archive_regex = r"^(wpa_supplicant-)([\w.-]*)(.tar.gz)$"
509+ source_archive_regex = re .compile (
510+ r"^(wpa_supplicant-)(?P<version>[\w.-]*)(.tar.gz)$"
511+ )
499512 is_nested = False
500513 ignored_files_and_dir = []
501514
502515
503516class SyslinuxDirectoryListedSource (DirectoryListedSource ):
504517 source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/"
505- source_archive_regex = r"^(syslinux-)([\w.-]*)(.tar.gz)$"
518+ source_archive_regex = re . compile ( r"^(syslinux-)(?P<version> [\w.-]*)(.tar.gz)$" )
506519 is_nested = False
507520 ignored_files_and_dir = []
508521
509522
510523class SyslinuxDirectoryListedSource (DirectoryListedSource ):
511524 source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/"
512- source_archive_regex = r"^(syslinux-)([\w.-]*)(.tar.gz)$"
525+ source_archive_regex = re . compile ( r"^(syslinux-)(?P<version> [\w.-]*)(.tar.gz)$" )
513526 is_nested = False
514527 ignored_files_and_dir = []
515528
516529
517530class ToyboxDirectoryListedSource (DirectoryListedSource ):
518531 source_url = "http://www.landley.net/toybox/downloads/"
519- source_archive_regex = r"^(toybox-)([\w.-]*)(.tar.gz|.tar.bz2)$"
532+ source_archive_regex = re .compile (
533+ r"^(toybox-)(?P<version>[\w.-]*)(.tar.gz|.tar.bz2)$"
534+ )
520535 is_nested = False
521536 ignored_files_and_dir = []
522537
523538
524539class DropbearDirectoryListedSource (DirectoryListedSource ):
525540 source_url = "https://matt.ucc.asn.au/dropbear/releases/"
526- source_archive_regex = r"^(dropbear-)([\w.-]*)(.tar.bz2|_i386.deb)$"
541+ source_archive_regex = re .compile (
542+ r"^(dropbear-)(?P<version>[\w.-]*)(.tar.bz2|_i386.deb)$"
543+ )
527544 is_nested = False
528545 ignored_files_and_dir = [
529546 "dropbear-0.44test1.tar.bz2" ,
@@ -539,7 +556,21 @@ class DropbearDirectoryListedSource(DirectoryListedSource):
539556
540557class SambaDirectoryListedSource (DirectoryListedSource ):
541558 source_url = "https://download.samba.org/pub/samba/stable/"
542- source_archive_regex = r"^(samba-)([\w.-]*)(.tar.gz)$"
559+ source_archive_regex = re .compile (r"^(samba-)(?P<version>[\w.-]*)(.tar.gz)$" )
560+ is_nested = False
561+ ignored_files_and_dir = []
562+
563+
564+ class MtdUtilsDirectoryListedSource (DirectoryListedSource ):
565+ source_url = "https://infraroot.at/pub/mtd/"
566+ source_archive_regex = re .compile (r"^(mtd-utils-)(?P<version>[\w.-]*)(.tar.bz2)$" )
567+ is_nested = False
568+ ignored_files_and_dir = []
569+
570+
571+ class BareboxDirectoryListedSource (DirectoryListedSource ):
572+ source_url = "https://www.barebox.org/download/"
573+ source_archive_regex = re .compile (r"^(barebox-)(?P<version>[\w.-]*)(.tar.bz2)$" )
543574 is_nested = False
544575 ignored_files_and_dir = []
545576
@@ -566,6 +597,8 @@ class SambaDirectoryListedSource(DirectoryListedSource):
566597 "pkg:generic/util-linux.*" ,
567598 "pkg:generic/wpa_supplicant.*" ,
568599 "pkg:generic/ipkg.*" ,
600+ "pkg:generic/mtd-utils.*" ,
601+ "pkg:generic/barebox.*" ,
569602]
570603
571604DIR_LISTED_SOURCE_BY_PACKAGE_NAME = {
@@ -589,6 +622,8 @@ class SambaDirectoryListedSource(DirectoryListedSource):
589622 "util-linux" : UtilLinuxDirectoryListedSource ,
590623 "wpa_supplicant" : WpaSupplicantDirectoryListedSource ,
591624 "ipkg" : IpkgDirectoryListedSource ,
625+ "mtd-utils" : MtdUtilsDirectoryListedSource ,
626+ "barebox" : BareboxDirectoryListedSource ,
592627}
593628
594629
@@ -605,16 +640,15 @@ def get_packages_from_listing(purl, source_archive_url, regex, ignored_files_and
605640 """
606641 Return list of package data from a directory listing based on the specified regex.
607642 """
608- pattern = re .compile (regex )
609643 _ , listing = htmllistparse .fetch_listing (source_archive_url )
610644
611645 packages = []
612646 for file in listing :
613- if not pattern .match (file .name ) or file .name in ignored_files_and_dir :
647+ match = regex .match (file .name )
648+ if not match or file .name in ignored_files_and_dir :
614649 continue
615650
616- match = re .search (regex , file .name )
617- version = match .group (2 )
651+ version = match .group ("version" )
618652 version = version .strip ("v" ).strip ()
619653 if not version :
620654 continue
@@ -668,7 +702,7 @@ def extract_package_from_nested_listing(purl, source_url, regex, ignored_files_a
668702 """
669703 _ , listing = htmllistparse .fetch_listing (source_url )
670704 for directory in listing :
671- if not directory .name .endswith ("/" ):
705+ if not directory .name .endswith ("/" ) or directory . name in ignored_files_and_dir :
672706 continue
673707
674708 directory_url = urljoin (source_url , directory .name )
0 commit comments