Add settings entries for --keep & --archive-dest

This allows a user to turn on `--keep` every time they run the program,
and to set the default archive destination when `--keep` is turned on.
Using `--archive-dest` overrides the archive destination in setting.ini.
This commit is contained in:
David Dalcino
2021-11-24 14:01:26 -08:00
parent db4db6c9a4
commit 7d5ee32ac3
4 changed files with 30 additions and 5 deletions

View File

@@ -305,6 +305,14 @@ class SettingsClass:
result = record["modules"]
return result
@property
def archive_download_location(self):
return self.config.get("aqt", "archive_download_location", fallback=".")
@property
def always_keep_archives(self):
return self.config.getboolean("aqt", "always_keep_archives", fallback=False)
@property
def concurrency(self):
"""concurrency configuration.

View File

@@ -228,12 +228,13 @@ class Cli:
There are three potential behaviors here:
1. By default, return a temp directory that will be removed on program exit.
2. If the user has asked to keep archives, but has not specified a destination, we return ".".
2. If the user has asked to keep archives, but has not specified a destination,
we return Settings.archive_download_location ("." by default).
3. If the user has asked to keep archives and specified a destination,
we create the destination dir if it doesn't exist, and return that directory.
"""
if not archive_dest:
return Path("." if keep else temp_dir)
return Path(Settings.archive_download_location if keep else temp_dir)
dest = Path(archive_dest)
dest.mkdir(parents=True, exist_ok=True)
return dest
@@ -254,7 +255,7 @@ class Cli:
else:
qt_version: str = args.qt_version
Cli._validate_version_str(qt_version)
keep: bool = args.keep
keep: bool = args.keep or Settings.always_keep_archives
archive_dest: Optional[str] = args.archive_dest
output_dir = args.outputdir
if output_dir is None:
@@ -342,7 +343,7 @@ class Cli:
base_dir = os.getcwd()
else:
base_dir = output_dir
keep: bool = args.keep
keep: bool = args.keep or Settings.always_keep_archives
archive_dest: Optional[str] = args.archive_dest
if args.base is not None:
base = args.base
@@ -430,7 +431,7 @@ class Cli:
version = getattr(args, "version", None)
if version is not None:
Cli._validate_version_str(version, allow_minus=True)
keep: bool = args.keep
keep: bool = args.keep or Settings.always_keep_archives
archive_dest: Optional[str] = args.archive_dest
if args.base is not None:
base = args.base

View File

@@ -5,6 +5,8 @@ concurrency: 4
baseurl: https://download.qt.io
7zcmd: 7z
print_stacktrace_on_error: False
always_keep_archives: False
archive_download_location: .
[requests]
connection_timeout: 3.5

View File

@@ -20,6 +20,8 @@ A file is like as follows:
baseurl: https://download.qt.io
7zcmd: 7z
print_stacktrace_on_error: False
always_keep_archives: False
archive_download_location: .
[requests]
connection_timeout: 3.5
@@ -71,6 +73,18 @@ print_stacktrace_on_error:
The ``False`` setting will hide the stack trace, unless an unhandled
exception occurs.
always_keep_archives:
This is either ``True`` or ``False``.
The ``True`` setting turns on the ``--keep`` option every time you run aqt,
and cannot be overridden by command line options.
The ``False`` setting will require you to set ``--keep`` manually every time
you run aqt, unless you don't want to keep ``.7z`` archives.
archive_download_location:
This is the relative or absolute path to the location in which ``.7z`` archives
will be downloaded, when ``--keep`` is turned on.
You can override this location with the ``--archives-dest`` option.
The ``[requests]`` section controls the way that ``aqt`` makes network requests.