Add the ability to create symlinks

This commit is contained in:
Olivier 'reivilibre' 2020-11-01 21:30:58 +00:00
parent 950cb2b761
commit 5e7020e19d
2 changed files with 47 additions and 0 deletions

View File

@ -25,6 +25,7 @@ from scone.default.utensils.basic_utensils import (
Chmod,
Chown,
MakeDirectory,
MakeSymlink,
SimpleExec,
Stat,
)
@ -133,6 +134,43 @@ class EnsureDirectory(Recipe):
k.get_dependency_tracker()
class EnsureSymlink(Recipe):
"""
Makes a symbolic link.
"""
_NAME = "symlink"
def __init__(self, recipe_context: RecipeContext, args: dict, head):
super().__init__(recipe_context, args, head)
self.path = check_type(args.get("path"), str)
self.target = check_type(args.get("target"), str)
self.is_dir = check_type(args.get("is_dir", False), bool)
self.checked = check_type(args.get("checked", True), bool)
# user and permissions don't make sense for symlinks
def prepare(self, preparation: Preparation, head: "Head"):
super().prepare(preparation, head)
path = Path(self.path)
preparation.needs("directory", str(path.parent))
kind = "directory" if self.is_dir else "file"
preparation.provides(kind, str(path))
if self.checked:
preparation.needs(kind, str(Path(path, self.target)))
async def cook(self, k: Kitchen):
await k.ut0(MakeSymlink(self.path, self.target))
# mark as tracked.
k.get_dependency_tracker()
class ExtractTar(Recipe):
"""
Extracts a tar archive, expecting to get at least some files.

View File

@ -63,6 +63,15 @@ class MakeDirectory(Utensil):
os.umask(oldumask)
@attr.s(auto_attribs=True)
class MakeSymlink(Utensil):
path: str
target: str
async def execute(self, channel: Channel, worktop):
os.symlink(self.target, self.path)
@attr.s(auto_attribs=True)
class Stat(Utensil):
path: str