From 48d7785332de512084c81d1c84f76943c49c63ae Mon Sep 17 00:00:00 2001 From: anonymix007 <48598263+anonymix007@users.noreply.github.com> Date: Sun, 25 Aug 2024 16:01:30 +0300 Subject: [PATCH] builder: build: filesystem.py: Allow downloading files from predefined url in config --- builder/build/filesystem.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/builder/build/filesystem.py b/builder/build/filesystem.py index a86b492..535755b 100644 --- a/builder/build/filesystem.py +++ b/builder/build/filesystem.py @@ -96,8 +96,8 @@ def add_file(ctx: ArchBuilderContext, file: dict): # at least path content if "path" not in file: raise ArchBuilderConfigError("no path set in file") - if "content" not in file and "source" not in file: - raise ArchBuilderConfigError("no content or source set in file") + if "content" not in file and "source" not in file and "url" not in file: + raise ArchBuilderConfigError(f"no content, source or url set in file") root = ctx.get_rootfs() path: str = file["path"] if path.startswith("/"): path = path[1:] @@ -109,7 +109,7 @@ def add_file(ctx: ArchBuilderContext, file: dict): # follow symbolic links follow = file["follow"] if "follow" in file else True - # source is a folder + # source is a folder folder = file["folder"] if "folder" in file else False # files mode @@ -142,6 +142,10 @@ def add_file(ctx: ArchBuilderContext, file: dict): shutil.copytree(src, real, symlinks=follow, dirs_exist_ok=True) else: shutil.copyfile(src, real, follow_symlinks=follow) + elif "url" in file: + cmds = ["wget", file["url"], "-O", real] + ret = ctx.run_external(cmds) + if ret != 0: raise OSError(f"wget failed with {ret}") else: assert False log.debug(f"chmod file {real} to {mode:04o}")