Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a single mirror throughout script #3

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions install_texlive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def is_current(version):
return current_version == version


def get_mirror():
"""Get a CTAN mirror"""
r = requests.get(URL, allow_redirects=False)
r.raise_for_status()
return r.headers["Location"]


def download(version=None, outdir='.', url=None):
os.makedirs(outdir, exist_ok=True)

Expand Down
15 changes: 9 additions & 6 deletions install_texlive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
import subprocess as sp

from . import command, download, OLDURL, get_size, is_current
from . import command, download, OLDURL, get_size, is_current, get_mirror
from .parser import parser


Expand All @@ -31,20 +31,23 @@ def main():
os.environ["TEXLIVE_INSTALL_ENV_NOCHECK"] = "1"
log.info('Installing texlive to {}'.format(args.prefix or '/usr/local/texlive'))

if args.repository is None:
if args.version is None or is_current(args.version):
args.repository = get_mirror()
else:
args.repository = OLDURL.format(v=args.version)

if args.install_tl:
install_script = args.install_tl
cmd = install_script
else:
log.info("Using repository: %s", args.repository)
directory = os.path.join(
tempfile.gettempdir(), 'texlive-{}'.format(args.version or 'current')
)
download(version=args.version, outdir=directory, url=args.repository)
install_script = glob(os.path.join(directory, 'install-tl-*/install-tl'))[-1]

if args.version is None or is_current(args.version):
cmd = install_script
else:
cmd = install_script + ' --repository=' + OLDURL.format(v=args.version)
cmd = install_script + ' --repository={}'.format(args.repository)

log.info(cmd)

Expand Down
Loading