mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-17 04:34:37 +03:00
settings.ini: use multiline configuration for URL list
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
@@ -159,6 +159,23 @@ def altlink(url: str, alt: str, logger=None):
|
||||
)
|
||||
|
||||
|
||||
class MyConfigParser(configparser.ConfigParser):
|
||||
def getlist(self, section, option, fallback=None):
|
||||
value = self.get(section, option)
|
||||
try:
|
||||
result = list(filter(None, (x.strip() for x in value.splitlines())))
|
||||
except Exception:
|
||||
result = fallback
|
||||
return result
|
||||
|
||||
def getlistint(self, section, option, fallback=None):
|
||||
try:
|
||||
result = [int(x) for x in self.getlist(section, option)]
|
||||
except Exception:
|
||||
result = fallback
|
||||
return result
|
||||
|
||||
|
||||
class Settings(object):
|
||||
"""Class to hold configuration and settings.
|
||||
Actual values are stored in 'settings.ini' file.
|
||||
@@ -177,7 +194,7 @@ class Settings(object):
|
||||
if self.config is None:
|
||||
with self._lock:
|
||||
if self.config is None:
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config = MyConfigParser()
|
||||
# load default config file
|
||||
with open(
|
||||
os.path.join(os.path.dirname(__file__), "settings.ini"), "r"
|
||||
@@ -242,7 +259,7 @@ class Settings(object):
|
||||
:returns: list of site URLs(scheme and host part)
|
||||
:rtype: List[str]
|
||||
"""
|
||||
return ast.literal_eval(self.config.get("mirrors", "blacklist", fallback="[]"))
|
||||
return self.config.getlist("mirrors", "blacklist", fallback=[])
|
||||
|
||||
@property
|
||||
def baseurl(self):
|
||||
@@ -250,15 +267,15 @@ class Settings(object):
|
||||
|
||||
@property
|
||||
def connection_timeout(self):
|
||||
return self.config.getint("aqt", "connection_timeout", fallback=3.5)
|
||||
return self.config.getfloat("aqt", "connection_timeout", fallback=3.5)
|
||||
|
||||
@property
|
||||
def response_timeout(self):
|
||||
return self.config.getint("aqt", "response_timeout", fallback=3.5)
|
||||
return self.config.getfloat("aqt", "response_timeout", fallback=3.5)
|
||||
|
||||
@property
|
||||
def fallbacks(self):
|
||||
return ast.literal_eval(self.config.get("mirrors", "fallbacks", fallback="[]"))
|
||||
return self.config.getlist("mirrors", "fallbacks", fallback=[])
|
||||
|
||||
@property
|
||||
def zipcmd(self):
|
||||
|
||||
@@ -8,5 +8,12 @@ baseurl: https://download.qt.io
|
||||
7zcmd: 7z
|
||||
|
||||
[mirrors]
|
||||
blacklist: ['http://mirrors.ustc.edu.cn', 'http://mirrors.tuna.tsinghua.edu.cn', 'http://mirrors.geekpie.club']
|
||||
fallbacks: ["https://mirrors.ocf.berkeley.edu/qt", "https://ftp.jaist.ac.jp/pub/qtproject", "http://ftp1.nluug.nl/languages/qt", "https://mirrors.dotsrc.org/qtproject"]
|
||||
blacklist:
|
||||
http://mirrors.ustc.edu.cn
|
||||
http://mirrors.tuna.tsinghua.edu.cn
|
||||
http://mirrors.geekpie.club
|
||||
fallbacks:
|
||||
https://mirrors.ocf.berkeley.edu/qt
|
||||
https://ftp.jaist.ac.jp/pub/qtproject
|
||||
http://ftp1.nluug.nl/languages/qt
|
||||
https://mirrors.dotsrc.org/qtproject
|
||||
|
||||
@@ -6,4 +6,8 @@ connection_timeout: 10
|
||||
response_timeout: 10
|
||||
|
||||
[mirrors]
|
||||
blacklist: ['http://mirrors.ustc.edu.cn', 'http://mirrors.tuna.tsinghua.edu.cn', 'http://mirrors.geekpie.club', 'http://mirrors.sjtug.sjtu.edu.cn']
|
||||
blacklist:
|
||||
http://mirrors.ustc.edu.cn
|
||||
http://mirrors.tuna.tsinghua.edu.cn
|
||||
http://mirrors.geekpie.club
|
||||
http://mirrors.sjtug.sjtu.edu.cn
|
||||
|
||||
79
docs/configuration.rst
Normal file
79
docs/configuration.rst
Normal file
@@ -0,0 +1,79 @@
|
||||
.. _configuration-ref:
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
``aqtinstall`` can be configured through a configuration file.
|
||||
A default configuration is stored in ``aqt/settings.ini`` file.
|
||||
|
||||
You can specify custom configuration file through ``AQT_CONFIG`` environment variable.
|
||||
A configuration should read very early stage of ``aqtinstall``, it cannot be specified
|
||||
through command line.
|
||||
|
||||
A file is like as follows:
|
||||
|
||||
.. code-block::
|
||||
|
||||
[DEFAULTS]
|
||||
|
||||
[aqt]
|
||||
concurrency: 4
|
||||
connection_timeout: 3.5
|
||||
response_timeout: 30
|
||||
baseurl: https://download.qt.io
|
||||
7zcmd: 7z
|
||||
|
||||
[mirrors]
|
||||
blacklist:
|
||||
http://mirrors.ustc.edu.cn
|
||||
http://mirrors.tuna.tsinghua.edu.cn
|
||||
http://mirrors.geekpie.club
|
||||
fallbacks:
|
||||
https://mirrors.ocf.berkeley.edu/qt
|
||||
https://ftp.jaist.ac.jp/pub/qtproject
|
||||
http://ftp1.nluug.nl/languages/qt
|
||||
https://mirrors.dotsrc.org/qtproject
|
||||
|
||||
|
||||
Settings
|
||||
--------
|
||||
|
||||
An ``[aqt]`` section is a configuration for basic behavior.
|
||||
|
||||
concurrency:
|
||||
``concurrency`` is a setting how many download concurrently starts.
|
||||
It should be a integer value.
|
||||
|
||||
connection_timeout:
|
||||
``connection_timeout`` is a timeout in second for connection.
|
||||
It is passed to ``requests`` library.
|
||||
|
||||
response_timeout:
|
||||
``response_timeout`` is a timeout in second how much time waiting for response.
|
||||
It is passed to ``requests`` library.
|
||||
|
||||
baseurl:
|
||||
``baseurl`` is a URL of Qt download site.
|
||||
When you have your own Qt download site repository, you can set it here.
|
||||
It is as same as ``--base`` option.
|
||||
|
||||
7zcmd:
|
||||
It is a command name of 7-zip. When ``aqtinstall`` is installed **without**
|
||||
recommended library ``py7zr``, it is used to extract archive instead of
|
||||
``py7zr`` library.
|
||||
When ``--external`` option specified, a value is override with option's one.
|
||||
|
||||
|
||||
A ``[mirrors]`` section is a configuration for mirror handling.
|
||||
|
||||
blacklist:
|
||||
It is a list of URL where is a problematic mirror site.
|
||||
Some mirror sites ignore a connection from IP addresses out of their preffered one.
|
||||
It will cause connection error or connection timeout.
|
||||
There are some known mirror sites in default.
|
||||
When you are happy with the default sites,
|
||||
you can override with your custom settings.
|
||||
|
||||
fallbacks:
|
||||
It is a list of URL where is a good for access.
|
||||
When mirror site cause an error, aqt use fallbacks when possible.
|
||||
@@ -9,6 +9,7 @@ Contents:
|
||||
installation
|
||||
cli
|
||||
available_versions
|
||||
configuration
|
||||
internals
|
||||
changes
|
||||
devguide
|
||||
|
||||
@@ -4,4 +4,6 @@
|
||||
concurrency: 3
|
||||
|
||||
[mirrors]
|
||||
blacklist: ['http://mirror.example.com', 'http://mirrors.geekpie.club/']
|
||||
blacklist:
|
||||
http://mirror.example.com
|
||||
http://mirrors.geekpie.club
|
||||
|
||||
Reference in New Issue
Block a user