Copy Plugin

Walk directories at a source directory and copy files to an output directory

Example config

In this first example we want to copy all files from ./source/dir_1 and ./source/dir_2 to ./output/dir_1 and ./output/dir_2 respectively.

ctl:
  plugins:

    - name: copy
      type: copy
      config:

        # source directory (path)

        source: source

        # output directory (path)

        output: output

        # we want to copy files from source/dir_1 and
        # source/dir_3, skipping source/dir_2

        walk_dirs:
          - dir_1
          - dir_3

  permissions:
    - namespace: ctl
      permission: crud

Run the command

The command will be exposed as an operation in the ctl cli by it's name, so we simply run it as such

ctl copy
[2019-10-09 08:22:34,496] [usage] ran command: `copy`
[2019-10-09 08:22:34,497] [ctl.plugins.copy] Skip dotfiles: True
[2019-10-09 08:22:34,498] [ctl.plugins.copy] output/dir_1/file.txt
[2019-10-09 08:22:34,499] [ctl.plugins.copy] output/dir_3/file.txt

Example: Ignore files based on pattern

You can use the ignore config to ignore certain file types or paths

ctl:
  plugins:

    - name: copy
      type: copy
      config:

        source: source
        output: output
        walk_dirs:
          - dir_1

        # ignore all *.cfg files
        ignore:
          - \.cfg$

  permissions:
    - namespace: ctl
      permission: crud

Example: process files based on pattern

You can use the process config to process files after they have been copied.

We can defer to other plugins for such actions.

In the following example we do a simple search and replace on *.html files via a command plugin.

ctl:
  plugins:

    # the replace command we will use to process the
    # files

    - name: replace
      type: command

      config:
        shell: true
        arguments:

          # `source` and `output` will be individual file paths passed on
          # from the `copy` plugin, so we need to make sure the
          # command knows about them

          - name: source
            type: str
          - name: output
            type: str

        command:
          - "sed  -i 's/ cats / dogs /g' {{ kwargs.output }}"

    # the copy plugin

    - name: copy
      type: copy
      config:

        source: source
        output: output
        walk_dirs:
          - dir_1
        process:

          # process *.html files

          - pattern: \.html$

            # we want to process with this plugin

            plugin: replace

            # we want to use this method of the plugin
            # to handle the processing

            action: execute



  permissions:
    - namespace: ctl
      permission: crud

Usage

Plugin name

This usage documentation assumes that the plugin instance name is copy

usage: ctl copy [-h] [--no-copy-metadata] [--debug] [--output OUTPUT]
                [--no-skip-dotfiles] [--source SOURCE]

optional arguments:
  -h, --help          show this help message and exit
  --no-copy-metadata  DISABLE Copy file metadata
  --debug             debug mode
  --output OUTPUT     output directory (output)
  --no-skip-dotfiles  DISABLE Skip dot files
  --source SOURCE     source directory (source)