folder-stowed

Example:

# 'stow' a folder
- folder-stowed:
    dirname: subfolder_1
    src: /tmp/source
    target: /tmp/target

Description

Stow a folder.

This uses the stow application to symbolically link a folder (recursively).

If target_owner is set, the destination folder will be changed to be owned by this user (and created with root permissions if it doesn't exist yet), and stow will be executed as that user.

This does not install 'stow', use the 'stow-installed' frecklet beforehand if necessary.

Resources

Variables

Name Type Default Description

dirname

string --

The name of the directory to stow. Required

src

string --

The (parent) source directory to stow from. Required

target

string --

The (parent) target directory to stow into. Required

become

boolean --

Whether to stow using root permissions.

target_owner

string --

The user to who owns the destination folder.

Examples

Example 1

'stow' a folder

Code
- folder-stowed:
    dirname: subfolder_1
    src: /tmp/source
    target: /tmp/target
Description

'stow' child folder subfolder_1 from /tmp/source/ its contents into /tmp/target

Code

doc:
  short_help: Stow (symlink) a folder.
  help: |
    Stow a folder.

    This uses the [stow](https://www.gnu.org/software/stow/) application to symbolically link a folder (recursively).

    If ``target_owner`` is set, the destination folder will be changed to be owned by this user (and created with root permissions if
    it doesn't exist yet), and stow will be executed as that user.

    This does not install 'stow', use the 'stow-installed' frecklet beforehand if necessary.

  references:
    stow homepage: https://www.gnu.org/software/stow/
  examples:
  - title: "'stow' a folder"
    desc: |
      'stow' child folder ``subfolder_1`` from ``/tmp/source/`` its contents into ``/tmp/target``
    vars:
      dirname: subfolder_1
      src: /tmp/source
      target: /tmp/target

args:
  dirname:
    doc:
      short_help: The name of the directory to stow.
    type: string
    required: true
  src:
    doc:
      short_help: The (parent) source directory to stow from.
    type: string
    required: true
  target:
    doc:
      short_help: The (parent) target directory to stow into.
    type: string
    required: true
  become:
    doc:
      short_help: Whether to stow using root permissions.
    type: boolean
    required: false
    cli:
      is_flag: true
  target_owner:
    doc:
      short_help: The user to who owns the destination folder.
    type: string
    required: false

meta:
  is_interface: true
  tags:
  - stow
  - symlink
  - folder
  - filesystem

frecklets:
#  - stow-installed
- folder-exists:
    path: '{{:: target ::}}'
    owner: '{{:: target_owner ::}}'
- task:
    become: '{{:: become ::}}'
    become_user: '{{:: target_owner ::}}'
  frecklet:
    name: stow
    type: ansible-module
    desc:
      short: "stow folder '{{:: src ::}} -> {{:: target ::}}"
      long: |
        Stow folder '{{:: dirname ::}}' (from '{{:: src ::}}') into '{{:: target ::}}'.

        {%:: if target_owner ::%}Use user '{{:: target_owner ::}}' for the stowing process, which means the target link(s) will be owned by it.{%:: endif ::%}
      references:
        "'stow' Ansible module (non-official)": https://gitlab.com/nsbl/nsbl-plugins/blob/master/library/stow.py
    properties:
      idempotent: true
      internet: false
      elevated: '{{:: become ::}}'
  vars:
    name: '{{:: dirname ::}}'
    source_dir: '{{:: src ::}}'
    target_dir: '{{:: target ::}}'
frecklecute folder-stowed --help

Usage: frecklecute folder-stowed [OPTIONS]

  Stow a folder.

  This uses the [stow](https://www.gnu.org/software/stow/) application to
  symbolically link a folder (recursively).

  If ``target_owner`` is set, the destination folder will be changed to be
  owned by this user (and created with root permissions if it doesn't exist
  yet), and stow will be executed as that user.

  This does not install 'stow', use the 'stow-installed' frecklet beforehand
  if necessary.

Options:
  --dirname DIRNAME            The name of the directory to stow.  [required]
  --src SRC                    The (parent) source directory to stow from.
                               [required]
  --target TARGET              The (parent) target directory to stow into.
                               [required]
  --become / --no-become       Whether to stow using root permissions.
  --target-owner TARGET_OWNER  The user to who owns the destination folder.
  --help                       Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.folder_stowed.FolderStowed
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class FolderStowed(AutoPycklet):
    """Stow a folder.

     This uses the [stow](https://www.gnu.org/software/stow/) application to symbolically link a folder (recursively).

     If ``target_owner`` is set, the destination folder will be changed to be owned by this user (and created with root permissions if
     it doesn't exist yet), and stow will be executed as that user.

     This does not install 'stow', use the 'stow-installed' frecklet beforehand if necessary.

       Args:
         become: Whether to stow using root permissions.
         dirname: The name of the directory to stow.
         src: The (parent) source directory to stow from.
         target: The (parent) target directory to stow into.
         target_owner: The user to who owns the destination folder.

    """

    FRECKLET_ID = "folder-stowed"

    become: bool = None
    dirname: str = None
    src: str = None
    target: str = None
    target_owner: str = None


    def __post_init__(self):
        super(FolderStowed, self).__init__(var_names=["become", "dirname", "src", "target", "target_owner"])


frecklet_class = FolderStowed
# -*- coding: utf-8 -*-


#
# module path: pycklets.folder_stowed.FolderStowed
#


from pyckles import AutoPycklet

class FolderStowed(AutoPycklet):
    """Stow a folder.

     This uses the [stow](https://www.gnu.org/software/stow/) application to symbolically link a folder (recursively).

     If ``target_owner`` is set, the destination folder will be changed to be owned by this user (and created with root permissions if
     it doesn't exist yet), and stow will be executed as that user.

     This does not install 'stow', use the 'stow-installed' frecklet beforehand if necessary.

       Args:
         become: Whether to stow using root permissions.
         dirname: The name of the directory to stow.
         src: The (parent) source directory to stow from.
         target: The (parent) target directory to stow into.
         target_owner: The user to who owns the destination folder.

    """

    FRECKLET_ID = "folder-stowed"

    def __init__(self, become=None, dirname=None, src=None, target=None, target_owner=None):

        super(FolderStowed, self).__init__(var_names=["become", "dirname", "src", "target", "target_owner"])
        self._become = become
        self._dirname = dirname
        self._src = src
        self._target = target
        self._target_owner = target_owner

    @property
    def become(self):
        return self._become

    @become.setter
    def become(self, become):
        self._become = become

    @property
    def dirname(self):
        return self._dirname

    @dirname.setter
    def dirname(self, dirname):
        self._dirname = dirname

    @property
    def src(self):
        return self._src

    @src.setter
    def src(self, src):
        self._src = src

    @property
    def target(self):
        return self._target

    @target.setter
    def target(self, target):
        self._target = target

    @property
    def target_owner(self):
        return self._target_owner

    @target_owner.setter
    def target_owner(self, target_owner):
        self._target_owner = target_owner



frecklet_class = FolderStowed