From 0f01e404a4e5d6218f5704c3fadcf77dd55b74a4 Mon Sep 17 00:00:00 2001 From: derrod Date: Thu, 14 May 2020 16:32:08 +0200 Subject: [PATCH] [cli/core/downloader] Support multiple filter arguments Fixes #20 --- legendary/cli.py | 8 ++++---- legendary/core.py | 4 ++-- legendary/downloader/manager.py | 23 +++++++++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/legendary/cli.py b/legendary/cli.py index 83dd5e3..fa5734a 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -646,11 +646,11 @@ def main(): help='Set download manager and worker processes\' loglevel to debug') install_parser.add_argument('--platform', dest='platform_override', action='store', metavar='', type=str, help='Platform override for download (disables install)') - install_parser.add_argument('--prefix', dest='file_prefix', action='store', metavar='', type=str, + install_parser.add_argument('--prefix', dest='file_prefix', action='append', metavar='', help='Only fetch files whose path starts with (case insensitive)') - install_parser.add_argument('--exclude', dest='file_exclude_prefix', action='store', metavar='', + install_parser.add_argument('--exclude', dest='file_exclude_prefix', action='append', metavar='', type=str, help='Exclude files starting with (case insensitive)') - install_parser.add_argument('--install-tag', dest='install_tag', action='store', metavar='', + install_parser.add_argument('--install-tag', dest='install_tag', action='append', metavar='', type=str, help='Only download files with the specified install tag (testing)') install_parser.add_argument('--enable-reordering', dest='order_opt', action='store_true', help='Enable reordering to attempt to optimize RAM usage during download') @@ -708,7 +708,7 @@ def main(): help='Force upload even if local saves are older') sync_saves_parser.add_argument('--force-download', dest='force_download', action='store_true', help='Force download even if local saves are newer') - sync_saves_parser.add_argument('--save-path', dest='save_path', action='store', + sync_saves_parser.add_argument('--save-path', dest='save_path', action='store', metavar='', help='Override savegame path (only if app name is specified)') args, extra = parser.parse_known_args() diff --git a/legendary/core.py b/legendary/core.py index 916a03f..d94ecd6 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -514,8 +514,8 @@ class LegendaryCore: force: bool = False, disable_patching: bool = False, game_folder: str = '', override_manifest: str = '', override_old_manifest: str = '', override_base_url: str = '', - platform_override: str = '', file_prefix_filter: str = '', - file_exclude_filter: str = '', file_install_tag: str = '', + platform_override: str = '', file_prefix_filter: list = None, + file_exclude_filter: list = None, file_install_tag: list = None, dl_optimizations: bool = False, dl_timeout: int = 10 ) -> (DLManager, AnalysisResult, ManifestMeta): # load old manifest diff --git a/legendary/downloader/manager.py b/legendary/downloader/manager.py index d9ea321..15a76eb 100644 --- a/legendary/downloader/manager.py +++ b/legendary/downloader/manager.py @@ -120,8 +120,11 @@ class DLManager(Process): # Not entirely sure what install tags are used for, only some titles have them. # Let's add it for testing anyway. if file_install_tag: + if isinstance(file_install_tag, str): + file_install_tag = [file_install_tag] + files_to_skip = set(i.filename for i in manifest.file_manifest_list.elements - if file_install_tag not in i.install_tags) + if not any(fit in i.install_tags for fit in file_install_tag)) self.log.info(f'Found {len(files_to_skip)} files to skip based on install tag.') mc.added -= files_to_skip mc.changed -= files_to_skip @@ -129,17 +132,25 @@ class DLManager(Process): # if include/exclude prefix has been set: mark all files that are not to be downloaded as unchanged if file_exclude_filter: - file_exclude_filter = file_exclude_filter.lower() - files_to_skip = set(i for i in mc.added | mc.changed if i.lower().startswith(file_exclude_filter)) + if isinstance(file_exclude_filter, str): + file_exclude_filter = [file_exclude_filter] + + file_exclude_filter = [f.lower() for f in file_exclude_filter] + files_to_skip = set(i.filename for i in manifest.file_manifest_list.elements if + any(i.filename.lower().startswith(pfx) for pfx in file_exclude_filter)) self.log.info(f'Found {len(files_to_skip)} files to skip based on exclude prefix.') mc.added -= files_to_skip mc.changed -= files_to_skip mc.unchanged |= files_to_skip if file_prefix_filter: - file_prefix_filter = file_prefix_filter.lower() - files_to_skip = set(i for i in mc.added | mc.changed if not i.lower().startswith(file_prefix_filter)) - self.log.info(f'Found {len(files_to_skip)} files to skip based on include prefix.') + if isinstance(file_prefix_filter, str): + file_prefix_filter = [file_prefix_filter] + + file_prefix_filter = [f.lower() for f in file_prefix_filter] + files_to_skip = set(i.filename for i in manifest.file_manifest_list.elements if not + any(i.filename.lower().startswith(pfx) for pfx in file_prefix_filter)) + self.log.info(f'Found {len(files_to_skip)} files to skip based on include prefix(es)') mc.added -= files_to_skip mc.changed -= files_to_skip mc.unchanged |= files_to_skip