[cli/core/downloader] Support multiple filter arguments

Fixes #20
This commit is contained in:
derrod 2020-05-14 16:32:08 +02:00
parent d648d29810
commit 0f01e404a4
3 changed files with 23 additions and 12 deletions

View file

@ -646,11 +646,11 @@ def main():
help='Set download manager and worker processes\' loglevel to debug') help='Set download manager and worker processes\' loglevel to debug')
install_parser.add_argument('--platform', dest='platform_override', action='store', metavar='<Platform>', install_parser.add_argument('--platform', dest='platform_override', action='store', metavar='<Platform>',
type=str, help='Platform override for download (disables install)') type=str, help='Platform override for download (disables install)')
install_parser.add_argument('--prefix', dest='file_prefix', action='store', metavar='<prefix>', type=str, install_parser.add_argument('--prefix', dest='file_prefix', action='append', metavar='<prefix>',
help='Only fetch files whose path starts with <prefix> (case insensitive)') help='Only fetch files whose path starts with <prefix> (case insensitive)')
install_parser.add_argument('--exclude', dest='file_exclude_prefix', action='store', metavar='<prefix>', install_parser.add_argument('--exclude', dest='file_exclude_prefix', action='append', metavar='<prefix>',
type=str, help='Exclude files starting with <prefix> (case insensitive)') type=str, help='Exclude files starting with <prefix> (case insensitive)')
install_parser.add_argument('--install-tag', dest='install_tag', action='store', metavar='<tag>', install_parser.add_argument('--install-tag', dest='install_tag', action='append', metavar='<tag>',
type=str, help='Only download files with the specified install tag (testing)') type=str, help='Only download files with the specified install tag (testing)')
install_parser.add_argument('--enable-reordering', dest='order_opt', action='store_true', install_parser.add_argument('--enable-reordering', dest='order_opt', action='store_true',
help='Enable reordering to attempt to optimize RAM usage during download') 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') help='Force upload even if local saves are older')
sync_saves_parser.add_argument('--force-download', dest='force_download', action='store_true', sync_saves_parser.add_argument('--force-download', dest='force_download', action='store_true',
help='Force download even if local saves are newer') 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='<path>',
help='Override savegame path (only if app name is specified)') help='Override savegame path (only if app name is specified)')
args, extra = parser.parse_known_args() args, extra = parser.parse_known_args()

View file

@ -514,8 +514,8 @@ class LegendaryCore:
force: bool = False, disable_patching: bool = False, force: bool = False, disable_patching: bool = False,
game_folder: str = '', override_manifest: str = '', game_folder: str = '', override_manifest: str = '',
override_old_manifest: str = '', override_base_url: str = '', override_old_manifest: str = '', override_base_url: str = '',
platform_override: str = '', file_prefix_filter: str = '', platform_override: str = '', file_prefix_filter: list = None,
file_exclude_filter: str = '', file_install_tag: str = '', file_exclude_filter: list = None, file_install_tag: list = None,
dl_optimizations: bool = False, dl_timeout: int = 10 dl_optimizations: bool = False, dl_timeout: int = 10
) -> (DLManager, AnalysisResult, ManifestMeta): ) -> (DLManager, AnalysisResult, ManifestMeta):
# load old manifest # load old manifest

View file

@ -120,8 +120,11 @@ class DLManager(Process):
# Not entirely sure what install tags are used for, only some titles have them. # Not entirely sure what install tags are used for, only some titles have them.
# Let's add it for testing anyway. # Let's add it for testing anyway.
if file_install_tag: 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 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.') self.log.info(f'Found {len(files_to_skip)} files to skip based on install tag.')
mc.added -= files_to_skip mc.added -= files_to_skip
mc.changed -= 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 include/exclude prefix has been set: mark all files that are not to be downloaded as unchanged
if file_exclude_filter: if file_exclude_filter:
file_exclude_filter = file_exclude_filter.lower() if isinstance(file_exclude_filter, str):
files_to_skip = set(i for i in mc.added | mc.changed if i.lower().startswith(file_exclude_filter)) 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.') self.log.info(f'Found {len(files_to_skip)} files to skip based on exclude prefix.')
mc.added -= files_to_skip mc.added -= files_to_skip
mc.changed -= files_to_skip mc.changed -= files_to_skip
mc.unchanged |= files_to_skip mc.unchanged |= files_to_skip
if file_prefix_filter: if file_prefix_filter:
file_prefix_filter = file_prefix_filter.lower() if isinstance(file_prefix_filter, str):
files_to_skip = set(i for i in mc.added | mc.changed if not i.lower().startswith(file_prefix_filter)) file_prefix_filter = [file_prefix_filter]
self.log.info(f'Found {len(files_to_skip)} files to skip based on include prefix.')
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.added -= files_to_skip
mc.changed -= files_to_skip mc.changed -= files_to_skip
mc.unchanged |= files_to_skip mc.unchanged |= files_to_skip