Add mirror url option

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2019-05-29 21:27:37 +09:00
parent e1515c6284
commit b34a8099e6
4 changed files with 36 additions and 23 deletions

View File

@@ -14,6 +14,8 @@ Current changes
Added Added
----- -----
* Option to specify mirror site.
Changed Changed
------- -------

View File

@@ -33,44 +33,43 @@ class QtPackage:
url = "" url = ""
archive = "" archive = ""
desc = "" desc = ""
mirror = None
def __init__(self, name, archive_url, archive, package_desc): def __init__(self, name, archive_url, archive, package_desc, has_mirror=False):
self.name = name self.name = name
self.url = archive_url self.url = archive_url
self.archive = archive self.archive = archive
self.desc = package_desc self.desc = package_desc
self.has_mirror = has_mirror
def get_name(self):
return self.name
def get_url(self):
return self.url
def get_archive(self):
return self.archive
def get_desc(self):
return self.desc
class QtArchives: class QtArchives:
BASE_URL = 'https://download.qt.io/online/qtsdkrepository/' BASE_URL = 'https://download.qt.io/online/qtsdkrepository/'
archives = [] archives = []
base = None
def __init__(self, os_name, qt_version, target, arch): def __init__(self, os_name, qt_version, target, arch, mirror=None):
self.qt_version = qt_version self.qt_version = qt_version
self.target = target self.target = target
self.arch = arch self.arch = arch
self.base = mirror
if mirror is not None:
self.has_mirror = True
else:
self.base = self.BASE_URL
qt_ver_num = qt_version.replace(".", "") qt_ver_num = qt_version.replace(".", "")
if os_name == 'windows': if os_name == 'windows':
archive_url = self.BASE_URL + os_name + '_x86/' + target + '/' + 'qt5_' + qt_ver_num + '/' archive_url = self.base + os_name + '_x86/' + target + '/' + 'qt5_' + qt_ver_num + '/'
else: else:
archive_url = self.BASE_URL + os_name + '_x64/' + target + '/' + 'qt5_' + qt_ver_num + '/' archive_url = self.base + os_name + '_x64/' + target + '/' + 'qt5_' + qt_ver_num + '/'
# Get packages index # Get packages index
update_xml_url = "{0}Updates.xml".format(archive_url) update_xml_url = "{0}Updates.xml".format(archive_url)
try: try:
r = aqt.metalink.get(update_xml_url) if mirror is not None:
r = requests.get(update_xml_url)
else:
r = aqt.metalink.get(update_xml_url)
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
print("Caught download error: %s" % e.args) print("Caught download error: %s" % e.args)
exc_buffer = StringIO() exc_buffer = StringIO()
@@ -98,7 +97,8 @@ class QtArchives:
package_desc = packageupdate.find("Description").text package_desc = packageupdate.find("Description").text
for archive in downloadable_archives: for archive in downloadable_archives:
package_url = archive_url + name + "/" + full_version + archive package_url = archive_url + name + "/" + full_version + archive
self.archives.append(QtPackage(name, package_url, archive, package_desc)) self.archives.append(QtPackage(name, package_url, archive, package_desc,
has_mirror=(mirror is not None)))
if len(self.archives) == 0: if len(self.archives) == 0:
print("Error while parsing package information!") print("Error while parsing package information!")

View File

@@ -36,6 +36,7 @@ class Cli():
target = args.target target = args.target
os_name = args.host os_name = args.host
output_dir = args.outputdir output_dir = args.outputdir
mirror = args.mirror
if arch is None: if arch is None:
if os_name == "linux" and target == "desktop": if os_name == "linux" and target == "desktop":
arch = "gcc_64" arch = "gcc_64"
@@ -48,11 +49,15 @@ class Cli():
args.print_help() args.print_help()
exit(1) exit(1)
qt_version = args.qt_version qt_version = args.qt_version
if mirror is not None:
if not mirror.startswith('http://') or mirror.startswith('https://') or mirror.startswith('ftp://'):
args.print_help()
exit(1)
if output_dir is not None: if output_dir is not None:
QtInstaller(QtArchives(os_name, qt_version, target, arch)).install(target_dir=output_dir) QtInstaller(QtArchives(os_name, qt_version, target, arch, mirror=mirror)).install(target_dir=output_dir)
else: else:
QtInstaller(QtArchives(os_name, qt_version, target, arch)).install() QtInstaller(QtArchives(os_name, qt_version, target, arch, mirror=mirror)).install()
sys.stdout.write("\033[K") sys.stdout.write("\033[K")
print("Finished installation") print("Finished installation")
@@ -83,6 +88,9 @@ class Cli():
"\nandroid: android_x86, android_armv7") "\nandroid: android_x86, android_armv7")
install_parser.add_argument('-O', '--outputdir', nargs='?', install_parser.add_argument('-O', '--outputdir', nargs='?',
help='Target output directory(default current directory)') help='Target output directory(default current directory)')
install_parser.add_argument('-m', '--mirror', nargs='?',
help="Specify mirror base url such as http://mirrors.ocf.berkeley.edu/qt/, "
"where 'online' folder exist.")
list_parser = subparsers.add_parser('list') list_parser = subparsers.add_parser('list')
list_parser.set_defaults(func=self.run_list) list_parser.set_defaults(func=self.run_list)
list_parser.add_argument("qt_version", help="Qt version in the format of \"5.X.Y\"") list_parser.add_argument("qt_version", help="Qt version in the format of \"5.X.Y\"")

View File

@@ -50,11 +50,14 @@ class QtInstaller:
@staticmethod @staticmethod
def retrieve_archive(package, path=None): def retrieve_archive(package, path=None):
archive = package.get_archive() archive = package.archive
url = package.get_url() url = package.url
print("-Downloading {}...".format(url)) print("-Downloading {}...".format(url))
try: try:
r = aqt.metalink.get(url, stream=True) if package.has_mirror:
r = aqt.metalink.get(url, stream=True)
else:
r = requests.get(url, stream=True)
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
print("Caught download error: %s" % e.args) print("Caught download error: %s" % e.args)
return False return False