Skip to content

Commit 1eff92a

Browse files
committed
Use regex group to extract version from filename
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 0d1bfce commit 1eff92a

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/fetchcode/package.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import htmllistparse
2525
import requests
26-
from commoncode.version import hint
2726
from packageurl import PackageURL
2827
from packageurl.contrib.route import NoRouteAvailable
2928
from packageurl.contrib.route import Router
@@ -341,7 +340,7 @@ def get_gnu_data_from_purl(purl):
341340
"""Generate `Package` object from the `purl` string of gnu type"""
342341
purl = PackageURL.from_string(purl)
343342
source_archive_url = f"https://ftp.gnu.org/pub/gnu/{purl.name}/"
344-
regex = r"^({}-)[\w.]*(.tar.gz)$".format(purl.name)
343+
regex = r"^({}-)([\w.-]*)(.tar.gz)$".format(purl.name)
345344

346345
yield from extract_packages_from_listing(purl, source_archive_url, regex)
347346

@@ -392,139 +391,139 @@ def get_package_info(cls, package_url):
392391
class IpkgDirectoryListedSource(DirectoryListedSource):
393392
source_url = "https://web.archive.org/web/20090326020239/http://handhelds.org/download/packages/ipkg/"
394393
is_nested = False
395-
source_archive_regex = r"^(ipkg[-_])[\w.]*(_arm.ipk|.tar.gz)$"
394+
source_archive_regex = r"^(ipkg[-_])([\w.-]*)(_arm.ipk|.tar.gz)$"
396395
ignored_files_and_dir = []
397396

398397

399398
class UtilLinuxDirectoryListedSource(DirectoryListedSource):
400399
source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/"
401400
is_nested = True
402-
source_archive_regex = r"^(util-linux-)[\w.]*(.tar.gz)$"
401+
source_archive_regex = r"^(util-linux-)([\w.-]*)(.tar.gz)$"
403402
ignored_files_and_dir = []
404403

405404

406405
class BusyBoxDirectoryListedSource(DirectoryListedSource):
407406
source_url = "https://www.busybox.net/downloads/"
408-
source_archive_regex = r"^(busybox-)[\w.]*(.tar.bz2)$"
407+
source_archive_regex = r"^(busybox-)([\w.-]*)(.tar.bz2)$"
409408
is_nested = False
410409
ignored_files_and_dir = []
411410

412411

413412
class UclibcDirectoryListedSource(DirectoryListedSource):
414413
source_url = "https://www.uclibc.org/downloads/"
415-
source_archive_regex = r"^(uClibc-)[\w.]*(.tar.gz)$"
414+
source_archive_regex = r"^(uClibc-)([\w.-]*)(.tar.gz)$"
416415
is_nested = False
417416
ignored_files_and_dir = []
418417

419418

420419
class UclibcNGDirectoryListedSource(DirectoryListedSource):
421420
source_url = "https://downloads.uclibc-ng.org/releases/"
422-
source_archive_regex = r"^(uClibc-ng-)[\w.]*(.tar.gz)$"
421+
source_archive_regex = r"^(uClibc-ng-)([\w.-]*)(.tar.gz)$"
423422
is_nested = False
424423
ignored_files_and_dir = []
425424

426425

427426
class Bzip2DirectoryListedSource(DirectoryListedSource):
428427
source_url = "https://sourceware.org/pub/bzip2/"
429-
source_archive_regex = r"^(bzip2-)[\w.]*(.tar.gz)$"
428+
source_archive_regex = r"^(bzip2-)([\w.-]*)(.tar.gz)$"
430429
is_nested = False
431430
ignored_files_and_dir = []
432431

433432

434433
class OpenSSHDirectoryListedSource(DirectoryListedSource):
435434
source_url = "https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/"
436-
source_archive_regex = r"^(openssh-)[\w.]*(.tgz|.tar.gz)$"
435+
source_archive_regex = r"^(openssh-)([\w.-]*)(.tgz|.tar.gz)$"
437436
is_nested = False
438437
ignored_files_and_dir = []
439438

440439

441440
class DnsmasqDirectoryListedSource(DirectoryListedSource):
442441
source_url = "https://thekelleys.org.uk/dnsmasq/"
443-
source_archive_regex = r"^(dnsmasq-)[\w.]*(.tar.xz|.tar.gz)$"
442+
source_archive_regex = r"^(dnsmasq-)([\w.-]*)(.tar.xz|.tar.gz)$"
444443
is_nested = False
445444
ignored_files_and_dir = []
446445

447446

448447
class EbtablesDirectoryListedSource(DirectoryListedSource):
449448
source_url = "https://www.netfilter.org/pub/ebtables/"
450-
source_archive_regex = r"^(ebtables-)[\w.]*(.tar.gz)$"
449+
source_archive_regex = r"^(ebtables-)([\w.-]*)(.tar.gz)$"
451450
is_nested = False
452451
ignored_files_and_dir = []
453452

454453

455454
class HostapdDirectoryListedSource(DirectoryListedSource):
456455
source_url = "https://w1.fi/releases/"
457-
source_archive_regex = r"^(hostapd-)[\w.]*(.tar.gz)$"
456+
source_archive_regex = r"^(hostapd-)([\w.-]*)(.tar.gz)$"
458457
is_nested = False
459458
ignored_files_and_dir = []
460459

461460

462461
class Iproute2DirectoryListedSource(DirectoryListedSource):
463462
source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/net/iproute2/"
464-
source_archive_regex = r"^(iproute2-)[\w.]*(.tar.xz|.tar.gz)$"
463+
source_archive_regex = r"^(iproute2-)([\w.-]*)(.tar.xz|.tar.gz)$"
465464
is_nested = False
466465
ignored_files_and_dir = []
467466

468467

469468
class IptablesDirectoryListedSource(DirectoryListedSource):
470469
source_url = "https://www.netfilter.org/pub/iptables/"
471-
source_archive_regex = r"^(iptables-)[\w.]*(.tar.bz2)$"
470+
source_archive_regex = r"^(iptables-)([\w.-]*)(.tar.bz2)$"
472471
is_nested = False
473472
ignored_files_and_dir = []
474473

475474

476475
class LibnlDirectoryListedSource(DirectoryListedSource):
477476
source_url = "https://www.infradead.org/~tgr/libnl/files/"
478-
source_archive_regex = r"^(libnl-)[\w.]*(.tar.gz)$"
477+
source_archive_regex = r"^(libnl-)([\w.-]*)(.tar.gz)$"
479478
is_nested = False
480479
ignored_files_and_dir = []
481480

482481

483482
class LighttpdDirectoryListedSource(DirectoryListedSource):
484483
source_url = "https://download.lighttpd.net/lighttpd/releases-1.4.x/"
485-
source_archive_regex = r"^(lighttpd-)[\w.]*(.tar.gz)$"
484+
source_archive_regex = r"^(lighttpd-)([\w.-]*)(.tar.gz)$"
486485
is_nested = False
487486
ignored_files_and_dir = []
488487

489488

490489
class NftablesDirectoryListedSource(DirectoryListedSource):
491490
source_url = "https://www.netfilter.org/pub/nftables/"
492-
source_archive_regex = r"^(nftables-)[\w.]*(.tar.xz|.tar.bz2)$"
491+
source_archive_regex = r"^(nftables-)([\w.-]*)(.tar.xz|.tar.bz2)$"
493492
is_nested = False
494493
ignored_files_and_dir = []
495494

496495

497496
class WpaSupplicantDirectoryListedSource(DirectoryListedSource):
498497
source_url = "https://w1.fi/releases/"
499-
source_archive_regex = r"^(wpa_supplicant-)[\w.]*(.tar.gz)$"
498+
source_archive_regex = r"^(wpa_supplicant-)([\w.-]*)(.tar.gz)$"
500499
is_nested = False
501500
ignored_files_and_dir = []
502501

503502

504503
class SyslinuxDirectoryListedSource(DirectoryListedSource):
505504
source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/"
506-
source_archive_regex = r"^(syslinux-)[\w.]*(.tar.gz)$"
505+
source_archive_regex = r"^(syslinux-)([\w.-]*)(.tar.gz)$"
507506
is_nested = False
508507
ignored_files_and_dir = []
509508

510509

511510
class SyslinuxDirectoryListedSource(DirectoryListedSource):
512511
source_url = "https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/"
513-
source_archive_regex = r"^(syslinux-)[\w.]*(.tar.gz)$"
512+
source_archive_regex = r"^(syslinux-)([\w.-]*)(.tar.gz)$"
514513
is_nested = False
515514
ignored_files_and_dir = []
516515

517516

518517
class ToyboxDirectoryListedSource(DirectoryListedSource):
519518
source_url = "http://www.landley.net/toybox/downloads/"
520-
source_archive_regex = r"^(toybox-)[\w.]*(.tar.gz|.tar.bz2)$"
519+
source_archive_regex = r"^(toybox-)([\w.-]*)(.tar.gz|.tar.bz2)$"
521520
is_nested = False
522521
ignored_files_and_dir = []
523522

524523

525524
class DropbearDirectoryListedSource(DirectoryListedSource):
526525
source_url = "https://matt.ucc.asn.au/dropbear/releases/"
527-
source_archive_regex = r"^(dropbear-)[\w.]*(.tar.bz2|_i386.deb)$"
526+
source_archive_regex = r"^(dropbear-)([\w.-]*)(.tar.bz2|_i386.deb)$"
528527
is_nested = False
529528
ignored_files_and_dir = [
530529
"dropbear-0.44test1.tar.bz2",
@@ -539,47 +538,47 @@ class DropbearDirectoryListedSource(DirectoryListedSource):
539538

540539

541540
DIR_SUPPORTED_PURLS = [
542-
"pkg:generic/ipkg.*",
543-
"pkg:generic/util-linux.*",
544541
"pkg:generic/busybox.*",
545-
"pkg:generic/uclibc.*",
546-
"pkg:generic/uclibc-ng.*",
547542
"pkg:generic/bzip2.*",
548-
"pkg:generic/openssh.*",
549543
"pkg:generic/dnsmasq.*",
544+
"pkg:generic/dropbear.*",
550545
"pkg:generic/ebtables.*",
551546
"pkg:generic/hostapd.*",
552547
"pkg:generic/iproute2.*",
553548
"pkg:generic/iptables.*",
554549
"pkg:generic/libnl.*",
555550
"pkg:generic/lighttpd.*",
556551
"pkg:generic/nftables.*",
557-
"pkg:generic/wpa_supplicant.*",
552+
"pkg:generic/openssh.*",
558553
"pkg:generic/syslinux.*",
559554
"pkg:generic/toybox.*",
560-
"pkg:generic/dropbear.*",
555+
"pkg:generic/uclibc.*",
556+
"pkg:generic/uclibc-ng.*",
557+
"pkg:generic/util-linux.*",
558+
"pkg:generic/wpa_supplicant.*",
559+
"pkg:generic/ipkg.*",
561560
]
562561

563562
DIR_LISTED_SOURCE_BY_PACKAGE_NAME = {
564-
"ipkg": IpkgDirectoryListedSource,
565-
"util-linux": UtilLinuxDirectoryListedSource,
566563
"busybox": BusyBoxDirectoryListedSource,
567-
"uclibc": UclibcDirectoryListedSource,
568-
"uclibc-ng": UclibcNGDirectoryListedSource,
569564
"bzip2": Bzip2DirectoryListedSource,
570-
"openssh": OpenSSHDirectoryListedSource,
571565
"dnsmasq": DnsmasqDirectoryListedSource,
566+
"dropbear": DropbearDirectoryListedSource,
572567
"ebtables": EbtablesDirectoryListedSource,
573568
"hostapd": HostapdDirectoryListedSource,
574569
"iproute2": Iproute2DirectoryListedSource,
575570
"iptables": IptablesDirectoryListedSource,
576571
"libnl": LibnlDirectoryListedSource,
577572
"lighttpd": LighttpdDirectoryListedSource,
578573
"nftables": NftablesDirectoryListedSource,
579-
"wpa_supplicant": WpaSupplicantDirectoryListedSource,
574+
"openssh": OpenSSHDirectoryListedSource,
580575
"syslinux": SyslinuxDirectoryListedSource,
581576
"toybox": ToyboxDirectoryListedSource,
582-
"dropbear": DropbearDirectoryListedSource,
577+
"uclibc": UclibcDirectoryListedSource,
578+
"uclibc-ng": UclibcNGDirectoryListedSource,
579+
"util-linux": UtilLinuxDirectoryListedSource,
580+
"wpa_supplicant": WpaSupplicantDirectoryListedSource,
581+
"ipkg": IpkgDirectoryListedSource,
583582
}
584583

585584

@@ -604,11 +603,12 @@ def get_packages_from_listing(purl, source_archive_url, regex, ignored_files_and
604603
if not pattern.match(file.name) or file.name in ignored_files_and_dir:
605604
continue
606605

607-
version = hint(file.name)
606+
match = re.search(regex, file.name)
607+
version = match.group(2)
608+
version = version.strip("v").strip()
608609
if not version:
609610
continue
610-
611-
version = version.strip("v").strip()
611+
612612
modified_time = file.modified
613613
date = datetime.utcfromtimestamp(time.mktime(modified_time))
614614

0 commit comments

Comments
 (0)