Skip to content

Commit

Permalink
Merge pull request #3 from maxnoe/fixed_mirror
Browse files Browse the repository at this point in the history
Use a single mirror throughout script
  • Loading branch information
maxnoe authored Apr 3, 2024
2 parents 7a2161b + fdca531 commit 605dd1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions install_texlive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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

0 comments on commit 605dd1e

Please sign in to comment.