diff --git a/helpers/DATA/python-apt/parse-mirror-masterlist.py b/helpers/DATA/python-apt/parse-mirror-masterlist.py new file mode 100644 index 0000000..5066811 --- /dev/null +++ b/helpers/DATA/python-apt/parse-mirror-masterlist.py @@ -0,0 +1,87 @@ +#! /usr/bin/python3 +# +# Script to parse Mirrors.masterlist file for python-apt template +# +# Copyright (C) 2024 Luis Guzmán +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import re +import argparse + +# Set arguments and read input file +parser = argparse.ArgumentParser(description="Parse Mirrors.masterlist") +parser.add_argument( + "file", + help="Path to the Mirrors.masterlist file") +parser.add_argument( + "--country", + "-c", + help="Filter by country (e.g., AU, BR, CA)", + default=None) +args = parser.parse_args() + +with open(args.file, 'r') as file: + input_text = file.read() + +# Split file by blocks per "Site:" +blocks = re.split(r'(?=Site:\s+)', input_text) +filtered_blocks = [ + block.strip() + for block in blocks + if block.strip().startswith("Site:") +] + +# Process block country and site +mirrors = {} +for block in blocks: + country_match = re.search(r'Country:\s+(\w{2})\b', block) + country = country_match.group(1) if country_match else None + + site_match = re.search(r'Site:\s+(\S+)', block) + site = site_match.group(1) if site_match else None + + if not country or not site: + continue + + https_matches = re.findall(r"Archive-https:\s+(\S+)", block) + http_matches = re.findall(r"Archive-http:\s+(\S+)", block) + + https_urls = [f"https://{site}{path}" for path in https_matches] + http_urls = [f"http://{site}{path}" for path in http_matches] + + # Save data in dict + if country not in mirrors: + mirrors[country] = {} + mirrors[country][site] = {"https": https_urls, "http": http_urls} + +# Print output +for country, sites in sorted(mirrors.items()): + if args.country and country != args.country: + continue + + valid_sites = { + site: urls for site, urls in sites.items() + if urls["https"] or urls["http"] + } + if not valid_sites: + continue + + print(f"#LOC:{country}") + for site, urls in valid_sites.items(): + for url in urls["https"]: + print(url) + for url in urls["http"]: + print(url) diff --git a/helpers/make-python-apt b/helpers/make-python-apt index c6b917d..df06663 100644 --- a/helpers/make-python-apt +++ b/helpers/make-python-apt @@ -18,44 +18,19 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # -VERSION=7 +VERSION=9 COMPONENT=main #Be aware to not pull/build before publish date on T12. . ./config -# https://en.wikipedia.org/wiki/ISO_3166-2 -cat << EOF > data/templates/Trisquel.mirrors -#LOC:AU -https://mirrors.middlendian.com/trisquel-packages/ -#LOC:BR -https://trisquel.c3sl.ufpr.br/packages/ -#LOC:CA -https://mirror.csclub.uwaterloo.ca/trisquel/packages/ -#LOC:CN -https://mirrors.ustc.edu.cn/trisquel -https://mirrors.nju.edu.cn/trisquel/ -#LOC:DK -https://mirrors.dotsrc.org/trisquel/ -#LOC:EC -https://mirror.cedia.org.ec/trisquel.packages -#LOC:ES -https://mirror.librelabucm.org/trisquel/ -#LOC:HU -https://quantum-mirror.hu/mirrors/pub/trisquel/packages/ -#LOC:JP -https://repo.jing.rocks/trisquel/ -#LOC:SE -https://ftp.acc.umu.se/mirror/trisquel/packages/ -https://ftpmirror1.infania.net/mirror/trisquel/packages/ -https://ftp.sunet.se/mirror/trisquel/packages/ -#LOC:US -https://archive.trisquel.info/trisquel/ -https://archive.trisquel.org/trisquel/ -https://mirror.fsf.org/trisquel/ -https://mirrors.ocf.berkeley.edu/trisquel/ -https://mirror.math.princeton.edu/pub/trisquel-packages/ -EOF +# Use git Mirrors.masterlist as source. +Mirrors_masterlist=$(mktemp) +Mirrors_masterlist_git="trisquel-packages/-/raw/master/extra/mirrors/Mirrors.masterlist" + +wget https://gitlab.trisquel.org/trisquel/$Mirrors_masterlist_git -o /dev/null -O $Mirrors_masterlist +python3 $DATA/parse-mirror-masterlist.py $Mirrors_masterlist > data/templates/Trisquel.mirrors +rm $Mirrors_masterlist cat << EOF > data/templates/Trisquel.info.in _ChangelogURI: https://packages.trisquel.org/changelogs/pool/%s/%s/%s/%s_%s/changelog