Git Product home page Git Product logo

fabpowertasks's Introduction

fabpowertasks

Offers an alternative to the standard way of generating Fabric tasks. Instead of random functions or Task declarations, instead create Commands classes that use a simple configuration flow and allow for dependency injection to share functionality between Tasks.

Additionally, some simple tasks are auto-generated and act as examples of how to write Commands.

Examples

Here's a simple fabfile.py:

import fabpowertasks
project_dir = os.path.dirname(__file__)
fabpowertasks.initialize(globals(), project_dir)

This automatically generates the Fabric tasks that come with fabpowertasks. They can be run as standard using Fabric with fab <command>

But that's not all - here's a more complex example fabfile/__init__.py that includes custom tasks:

import os
import fabpowertasks
from fabfile.config import ProjectPaths
from fabfile.tasks import CustomCommands

fabfile_dir = os.path.dirname(__file__)
project_dir = os.path.dirname(fabfile_dir)
properties = fabpowertasks.Properties.load_from_file(
    os.path.join(fabfile_dir, 'project.json')
)
properties.base_dir = project_dir
local_project_paths = ProjectPaths(project_dir, properties)
injection_objs = {
    'local_project_paths': local_project_paths,
    'remote_project_paths': fabpowertasks.SystemPaths(properties.remote_base_dir,
                                                      properties),
    'custom_commands': CustomCommands()
}
fabpowertasks.initialize(globals(), os.path.dirname(fabfile_dir),
                         project_properties=properties,
                         project_inject_objs=injection_objs)

Some explanation of this example is needed:

  • CustomCommands is a class that extends the utility class fabpowertasks.commands.BaseCommands. This class comes with some additional functions that are used to generate Fabric tasks from itself.
  • An instance of the Properties class is used extensively throughout the library and contains all project properties. At the very least, it requires a project directory location, which is why this is a required option to initialize(). But the default instance may be overridden, as shown here.
  • fabpowertasks inspects the variables for each Commands instance and attempts to inject any matching values as described in injection_objs. Any variables that don't start with _ and are None as treated as potential injection points. By default, an attempt to inject local_project_paths into every Commands instance is made but more injections can be added using the project_injection_objs argument.

Commands

The concept of Commands is simple - they are an advanced form of a Fabric Task. Instead of being limited to the run() function, multiple functions of the Command instance can be treated as Tasks.

Implementation

  • Extend fabpowertasks.commands.BaseCommands
  • Write the functions for your resulting Task
  • __init__(): Update self._task_functions with the functions
  • __init__(): Optionally, set instance variables for injection
  • Import your new class into fabfile/__init__.py and pass into the project_injection_objs dict where the resulting Tasks are auto-generated

Note that arguments to the function mirror what a standard Fabric task expects.

fabpowertasks's People

Contributors

sbreatnach avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.