Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/build/sage_bootstrap/download/app.py
4055 views
1
# -*- coding: utf-8 -*-
2
"""
3
Controller for the commandline actions
4
"""
5
6
7
# ****************************************************************************
8
# Copyright (C) 2016 Volker Braun <[email protected]>
9
#
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation, either version 2 of the License, or
13
# (at your option) any later version.
14
# https://www.gnu.org/licenses/
15
# ****************************************************************************
16
17
import logging
18
log = logging.getLogger()
19
20
21
from sage_bootstrap.tarball import Tarball
22
from sage_bootstrap.download.mirror_list import MirrorList
23
from sage_bootstrap.download.transfer import Download
24
25
26
class Application(object):
27
28
def __init__(self, timeout, quiet):
29
import socket
30
socket.setdefaulttimeout(timeout)
31
self.quiet = quiet
32
33
def print_fastest_mirror(self):
34
print(MirrorList().fastest)
35
36
def download_url(self, url, destination):
37
Download(url, destination, progress=not self.quiet, ignore_errors=False).run()
38
39
def download_tarball(self, tarball_filename, destination=None, allow_upstream=False):
40
tarball = Tarball(tarball_filename)
41
tarball.download(allow_upstream=allow_upstream)
42
if destination is not None:
43
tarball.save_as(destination)
44
45
46