python-apt: use git Mirrors.masterlist as main source
This commit is contained in:
parent
67d17e9a6d
commit
5fd2eab062
2 changed files with 95 additions and 33 deletions
87
helpers/DATA/python-apt/parse-mirror-masterlist.py
Normal file
87
helpers/DATA/python-apt/parse-mirror-masterlist.py
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
#! /usr/bin/python3
|
||||||
|
#
|
||||||
|
# Script to parse Mirrors.masterlist file for python-apt template
|
||||||
|
#
|
||||||
|
# Copyright (C) 2024 Luis Guzmán <ark@switnet.org>
|
||||||
|
#
|
||||||
|
# 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)
|
||||||
|
|
@ -18,44 +18,19 @@
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
#
|
#
|
||||||
|
|
||||||
VERSION=7
|
VERSION=9
|
||||||
COMPONENT=main
|
COMPONENT=main
|
||||||
#Be aware to not pull/build before publish date on T12.
|
#Be aware to not pull/build before publish date on T12.
|
||||||
|
|
||||||
. ./config
|
. ./config
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/ISO_3166-2
|
# Use git Mirrors.masterlist as source.
|
||||||
cat << EOF > data/templates/Trisquel.mirrors
|
Mirrors_masterlist=$(mktemp)
|
||||||
#LOC:AU
|
Mirrors_masterlist_git="trisquel-packages/-/raw/master/extra/mirrors/Mirrors.masterlist"
|
||||||
https://mirrors.middlendian.com/trisquel-packages/
|
|
||||||
#LOC:BR
|
wget https://gitlab.trisquel.org/trisquel/$Mirrors_masterlist_git -o /dev/null -O $Mirrors_masterlist
|
||||||
https://trisquel.c3sl.ufpr.br/packages/
|
python3 $DATA/parse-mirror-masterlist.py $Mirrors_masterlist > data/templates/Trisquel.mirrors
|
||||||
#LOC:CA
|
rm $Mirrors_masterlist
|
||||||
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
|
|
||||||
|
|
||||||
cat << EOF > data/templates/Trisquel.info.in
|
cat << EOF > data/templates/Trisquel.info.in
|
||||||
_ChangelogURI: https://packages.trisquel.org/changelogs/pool/%s/%s/%s/%s_%s/changelog
|
_ChangelogURI: https://packages.trisquel.org/changelogs/pool/%s/%s/%s/%s_%s/changelog
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue