parent-folder-exists

Example:

# Create parent folder for a path.
- parent-folder-exists:
    path: /tmp/parent_1/parent_2/freckles.txt

Description

Ensure the parent folder of a path exists. If the owner and/or group variables is/are specified, those will be created if they don't exist yet and set alongside the mode for that folder.

If the parent folder already exists and owner/group/mode attributes are provided, those won't be applied.

If a owner value is provided, this will use 'root' permissions to (potentially) create the parent folder, and the file.

Variables

Name Type Default Description

path

string --

The path to the child file/folder. Required

group

string --

The group of the folder, will be created if necessary.

mode

string --

The permissions of the folder.

owner

string --

The owner of the folder, will be created if necessary.

system_user

boolean False

Whether the user and group should be of system user/group type.

Examples

Example 1

Create parent folder for a path.

Code
- parent-folder-exists:
    path: /tmp/parent_1/parent_2/freckles.txt
Description

Create folder /tmp/parent_1/parent_2. Doesn't do anything else, like 'touching' the freckles.txt file.

Code

doc:
  short_help: Ensure the parent folder of a path exists.
  help: |
    Ensure the parent folder of a path exists. If the ``owner`` and/or ``group`` variables is/are specified, those will be created if they don't exist yet
    and set alongside the mode for that folder.

    If the parent folder already exists and owner/group/mode attributes are provided, those won't be applied.

    If a ``owner`` value is provided, this will use 'root' permissions to (potentially) create the parent folder, and the file.

  examples:
  - title: Create parent folder for a path.
    desc: |
      Create folder ``/tmp/parent_1/parent_2``. Doesn't do anything else, like 'touching' the ``freckles.txt`` file.
    vars:
      path: /tmp/parent_1/parent_2/freckles.txt

args:
  path:
    doc:
      short_help: The path to the child file/folder.
    type: string
    required: true
    cli:
      param_type: argument
  owner:
    doc:
      short_help: The owner of the folder, will be created if necessary.
    type: string
    required: false
    cli:
      metavar: USER_NAME
  group:
    doc:
      short_help: The group of the folder, will be created if necessary.
    type: string
    required: false
    cli:
      metavar: GROUP_NAME
  mode:
    doc:
      short_help: The permissions of the folder.
    type: string
    required: false
    cli:
      metavar: MODE
#  become:
#    doc:
#      short_help: Whether to use root privileges to create the folder.
#    type: boolean
#    default: false
#    required: false
#    cli:
#      is_flag: true
  system_user:
    doc:
      short_help: Whether the user and group should be of system user/group type.
    type: boolean
    required: false
    default: false
    cli:
      show_default: true
      is_flag: true
meta:
  is_interface: true
  tags:
  - file
  - filesystem
  - folder
  - mkdir
  - featured-frecklecutable

frecklets:

- folder-exists:
#      frecklet::desc:
#        long: |
#          Create parent folder for '{{:: path ::}}' (if it doesn't exist yet). Fail if it already exists and is not a folder.
#
#          {%:: if mode ::%}Ensure the folders mode is '{{:: mode ::}}' (recursively, incl. children){%:: else ::%}Leave the folders mode as is (or default if folder has to be created){%:: endif ::%}. {%:: if group ::%}Set group (recursively, incl. children) to be '{{:: group ::}}'{%:: else ::%}Use the executing users main group (or leave be if file already exists){%:: endif ::%} and {%:: if owner ::%}set user to be '{{:: owner ::}}' (recursively){%:: else ::%}use the executing users name as the owner (or leave be if file already exists){%:: endif ::%}.
    path: '{{:: path | dirname ::}}'
    owner: '{{:: owner ::}}'
    group: '{{:: group ::}}'
    mode: '{{:: mode ::}}'
    system: '{{:: system_user ::}}'
    force_chown: false
frecklecute parent-folder-exists --help

Usage: frecklecute parent-folder-exists [OPTIONS] PATH

  Ensure the parent folder of a path exists. If the ``owner`` and/or
  ``group`` variables is/are specified, those will be created if they don't
  exist yet and set alongside the mode for that folder.

  If the parent folder already exists and owner/group/mode attributes are
  provided, those won't be applied.

  If a ``owner`` value is provided, this will use 'root' permissions to
  (potentially) create the parent folder, and the file.

Options:
  --group GROUP_NAME              The group of the folder, will be created if
                                  necessary.
  --mode MODE                     The permissions of the folder.
  --owner USER_NAME               The owner of the folder, will be created if
                                  necessary.
  --system-user / --no-system-user
                                  Whether the user and group should be of
                                  system user/group type.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.parent_folder_exists.ParentFolderExists
#


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

@dataclass
class ParentFolderExists(AutoPycklet):
    """Ensure the parent folder of a path exists. If the ``owner`` and/or ``group`` variables is/are specified, those will be created if they don't exist yet
     and set alongside the mode for that folder.

     If the parent folder already exists and owner/group/mode attributes are provided, those won't be applied.

     If a ``owner`` value is provided, this will use 'root' permissions to (potentially) create the parent folder, and the file.

       Args:
         group: The group of the folder, will be created if necessary.
         mode: The permissions of the folder.
         owner: The owner of the folder, will be created if necessary.
         path: The path to the child file/folder.
         system_user: Whether the user and group should be of system user/group type.

    """

    FRECKLET_ID = "parent-folder-exists"

    group: str = None
    mode: str = None
    owner: str = None
    path: str = None
    system_user: bool = None


    def __post_init__(self):
        super(ParentFolderExists, self).__init__(var_names=["group", "mode", "owner", "path", "system_user"])


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


#
# module path: pycklets.parent_folder_exists.ParentFolderExists
#


from pyckles import AutoPycklet

class ParentFolderExists(AutoPycklet):
    """Ensure the parent folder of a path exists. If the ``owner`` and/or ``group`` variables is/are specified, those will be created if they don't exist yet
     and set alongside the mode for that folder.

     If the parent folder already exists and owner/group/mode attributes are provided, those won't be applied.

     If a ``owner`` value is provided, this will use 'root' permissions to (potentially) create the parent folder, and the file.

       Args:
         group: The group of the folder, will be created if necessary.
         mode: The permissions of the folder.
         owner: The owner of the folder, will be created if necessary.
         path: The path to the child file/folder.
         system_user: Whether the user and group should be of system user/group type.

    """

    FRECKLET_ID = "parent-folder-exists"

    def __init__(self, group=None, mode=None, owner=None, path=None, system_user=None):

        super(ParentFolderExists, self).__init__(var_names=["group", "mode", "owner", "path", "system_user"])
        self._group = group
        self._mode = mode
        self._owner = owner
        self._path = path
        self._system_user = system_user

    @property
    def group(self):
        return self._group

    @group.setter
    def group(self, group):
        self._group = group

    @property
    def mode(self):
        return self._mode

    @mode.setter
    def mode(self, mode):
        self._mode = mode

    @property
    def owner(self):
        return self._owner

    @owner.setter
    def owner(self, owner):
        self._owner = owner

    @property
    def path(self):
        return self._path

    @path.setter
    def path(self, path):
        self._path = path

    @property
    def system_user(self):
        return self._system_user

    @system_user.setter
    def system_user(self, system_user):
        self._system_user = system_user



frecklet_class = ParentFolderExists