python-virtualenv-execute-shell-commands

Example:

# Execute 'db' migrate commands in a virtualenv.
- python-virtualenv-execute-shell-commands:
    commands:
    - flask db init
    - flask db migrate
    - flask db upgrade
    virtualenv_path: /home/freckles/.pyenv/versions/webapp

Description

Execute a list of commands inside a virtualenv, each of the 'commands' needs to be available in the virtualenv (/bin/) or system-wide.

You can easily use the 'execute-shell' frecklet instead of this, because for now with this you need to know the path to the virtualenv. If you used the 'python-virtualenv' frecklet and the 'python_type' 'pyenv', your virtualenv will be located under /.pyenv/versions/. In the future this will take the same vars that the 'python-virtualenv' frecklet takes, and auto-calculate the path to the virtualenv.

For now, only absolute virtualenv paths are supported, '~' won't work.

Also, this frecklet does not support commands that require user input. For this, you'd have to create a frecklet similar to this, which uses 'expect'. Not hard, just not available yet.

Variables

Name Type Default Description

commands

n/a --

n/a Required

virtualenv_path

string --

The (absolute) virtualenv (base) path. Required

chdir

string --

The working directory.

environment

dict --

A dictionary of environment variables to add/set.

ignore_error

boolean False

Whether to ignore any potential errors.

no_log

boolean False

Whether to hide the log of this command (because for example the command contains sensitive information).

user

string --

The user to execute this command as.

Examples

Example 1

Execute 'db' migrate commands in a virtualenv.

Code
- python-virtualenv-execute-shell-commands:
    commands:
    - flask db init
    - flask db migrate
    - flask db upgrade
    virtualenv_path: /home/freckles/.pyenv/versions/webapp
Description

This assumes you installed a Python flask application in an virtualenv named 'webapp' before (for example using the 'python_virtualenv' frecklet), using 'pyenv'.

Code

doc:
  short_help: Executes a list of commands inside a virtualenv.
  help: |
    Execute a list of commands inside a virtualenv, each of the 'commands' needs to be available in the virtualenv (<venv>/bin/<command>) or system-wide.

    You can easily use the 'execute-shell' frecklet instead of this, because for now with this you need to know the path to the virtualenv. If you used the 'python-virtualenv' frecklet and the 'python_type' 'pyenv',
    your virtualenv will be located under <user_home>/.pyenv/versions/<venv_name>.
    In the future this will take the same vars that the 'python-virtualenv' frecklet takes, and auto-calculate the
    path to the virtualenv.

    For now, only absolute virtualenv paths are supported, '~' won't work.

    Also, this frecklet does not support commands that require user input. For this, you'd have to create a frecklet
    similar to this, which uses 'expect'. Not hard, just not available yet.
  examples:
  - title: Execute 'db' migrate commands in a virtualenv.
    desc: |
      This assumes you installed a Python flask application in an virtualenv named 'webapp' before (for example using the 'python_virtualenv' frecklet), using 'pyenv'.
    vars:
      commands:
      - flask db init
      - flask db migrate
      - flask db upgrade
      virtualenv_path: /home/freckles/.pyenv/versions/webapp

args:
  _import: execute-shell
  virtualenv_path:
    doc:
      short_help: The (absolute) virtualenv (base) path.
    type: string
    required: true
  command:
    doc:
      short_help: The command to execute.
      help: |
        This needs to be an executable that is located in the ``virtualenv_path``/bin/ folder.
  user:
    doc:
      short_help: The user to execute this command as.
    type: string
    empty: false
    required: false
  ignore_error:
    doc:
      short_help: Whether to ignore any potential errors.
    type: boolean
    required: false
    default: false
  no_log:
    doc:
      short_help: Whether to hide the log of this command (because for example the
        command contains sensitive information).
    type: boolean
    default: false
    required: false
    cli:
      param_decls:
      - --no-log
  environment:
    doc:
      short_help: A dictionary of environment variables to add/set.
    type: dict
    required: false
    keyschema:
      type: string


frecklets:
- execute-shell:
    frecklet::desc:
      short: "execute commands in venv: {{:: commands | join(' && ') ::}}"
    command: "source {{:: virtualenv_path ::}}/bin/activate && {{:: commands | join('\
      \ && ') ::}}"
    chdir: '{{:: chdir ::}}'
    become_user: '{{:: user ::}}'
    ignore_error: '{{:: ignore_error ::}}'
    no_log: '{{:: no_log ::}}'
    environment: '{{:: environment ::}}'
    shell_executable: /bin/bash
frecklecute python-virtualenv-execute-shell-commands --help

Usage: frecklecute python-virtualenv-execute-shell-commands 
           [OPTIONS]

  Execute a list of commands inside a virtualenv, each of the 'commands'
  needs to be available in the virtualenv (<venv>/bin/<command>) or system-
  wide.

  You can easily use the 'execute-shell' frecklet instead of this, because
  for now with this you need to know the path to the virtualenv. If you used
  the 'python-virtualenv' frecklet and the 'python_type' 'pyenv', your
  virtualenv will be located under <user_home>/.pyenv/versions/<venv_name>.
  In the future this will take the same vars that the 'python-virtualenv'
  frecklet takes, and auto-calculate the path to the virtualenv.

  For now, only absolute virtualenv paths are supported, '~' won't work.

  Also, this frecklet does not support commands that require user input. For
  this, you'd have to create a frecklet similar to this, which uses
  'expect'. Not hard, just not available yet.

Options:
  --commands COMMANDS             n/a  [required]
  --virtualenv-path VIRTUALENV_PATH
                                  The (absolute) virtualenv (base) path.
                                  [required]
  --chdir CHDIR                   The working directory.
  --environment ENVIRONMENT       A dictionary of environment variables to
                                  add/set.
  --ignore-error / --no-ignore-error
                                  Whether to ignore any potential errors.
  --no-log                        Whether to hide the log of this command
                                  (because for example the command contains
                                  sensitive information).
  --user USER                     The user to execute this command as.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.python_virtualenv_execute_shell_commands.PythonVirtualenvExecuteShellCommands
#


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

@dataclass
class PythonVirtualenvExecuteShellCommands(AutoPycklet):
    """Execute a list of commands inside a virtualenv, each of the 'commands' needs to be available in the virtualenv (<venv>/bin/<command>) or system-wide.

     You can easily use the 'execute-shell' frecklet instead of this, because for now with this you need to know the path to the virtualenv. If you used the 'python-virtualenv' frecklet and the 'python_type' 'pyenv',
     your virtualenv will be located under <user_home>/.pyenv/versions/<venv_name>.
     In the future this will take the same vars that the 'python-virtualenv' frecklet takes, and auto-calculate the
     path to the virtualenv.

     For now, only absolute virtualenv paths are supported, '~' won't work.

     Also, this frecklet does not support commands that require user input. For this, you'd have to create a frecklet
     similar to this, which uses 'expect'. Not hard, just not available yet.

       Args:
         chdir: The working directory.
         commands: n/a
         environment: A dictionary of environment variables to add/set.
         ignore_error: Whether to ignore any potential errors.
         no_log: Whether to hide the log of this command (because for example the command contains sensitive information).
         user: The user to execute this command as.
         virtualenv_path: The (absolute) virtualenv (base) path.

    """

    FRECKLET_ID = "python-virtualenv-execute-shell-commands"

    chdir: str = None
    commands: str = None
    environment: Dict = None
    ignore_error: bool = None
    no_log: bool = None
    user: str = None
    virtualenv_path: str = None


    def __post_init__(self):
        super(PythonVirtualenvExecuteShellCommands, self).__init__(var_names=["chdir", "commands", "environment", "ignore_error", "no_log", "user", "virtualenv_path"])


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


#
# module path: pycklets.python_virtualenv_execute_shell_commands.PythonVirtualenvExecuteShellCommands
#


from pyckles import AutoPycklet

class PythonVirtualenvExecuteShellCommands(AutoPycklet):
    """Execute a list of commands inside a virtualenv, each of the 'commands' needs to be available in the virtualenv (<venv>/bin/<command>) or system-wide.

     You can easily use the 'execute-shell' frecklet instead of this, because for now with this you need to know the path to the virtualenv. If you used the 'python-virtualenv' frecklet and the 'python_type' 'pyenv',
     your virtualenv will be located under <user_home>/.pyenv/versions/<venv_name>.
     In the future this will take the same vars that the 'python-virtualenv' frecklet takes, and auto-calculate the
     path to the virtualenv.

     For now, only absolute virtualenv paths are supported, '~' won't work.

     Also, this frecklet does not support commands that require user input. For this, you'd have to create a frecklet
     similar to this, which uses 'expect'. Not hard, just not available yet.

       Args:
         chdir: The working directory.
         commands: n/a
         environment: A dictionary of environment variables to add/set.
         ignore_error: Whether to ignore any potential errors.
         no_log: Whether to hide the log of this command (because for example the command contains sensitive information).
         user: The user to execute this command as.
         virtualenv_path: The (absolute) virtualenv (base) path.

    """

    FRECKLET_ID = "python-virtualenv-execute-shell-commands"

    def __init__(self, chdir=None, commands=None, environment=None, ignore_error=None, no_log=None, user=None, virtualenv_path=None):

        super(PythonVirtualenvExecuteShellCommands, self).__init__(var_names=["chdir", "commands", "environment", "ignore_error", "no_log", "user", "virtualenv_path"])
        self._chdir = chdir
        self._commands = commands
        self._environment = environment
        self._ignore_error = ignore_error
        self._no_log = no_log
        self._user = user
        self._virtualenv_path = virtualenv_path

    @property
    def chdir(self):
        return self._chdir

    @chdir.setter
    def chdir(self, chdir):
        self._chdir = chdir

    @property
    def commands(self):
        return self._commands

    @commands.setter
    def commands(self, commands):
        self._commands = commands

    @property
    def environment(self):
        return self._environment

    @environment.setter
    def environment(self, environment):
        self._environment = environment

    @property
    def ignore_error(self):
        return self._ignore_error

    @ignore_error.setter
    def ignore_error(self, ignore_error):
        self._ignore_error = ignore_error

    @property
    def no_log(self):
        return self._no_log

    @no_log.setter
    def no_log(self, no_log):
        self._no_log = no_log

    @property
    def user(self):
        return self._user

    @user.setter
    def user(self, user):
        self._user = user

    @property
    def virtualenv_path(self):
        return self._virtualenv_path

    @virtualenv_path.setter
    def virtualenv_path(self, virtualenv_path):
        self._virtualenv_path = virtualenv_path



frecklet_class = PythonVirtualenvExecuteShellCommands