Home

Awesome

factory

MIT Python 2.7 gevent

Build Status Coverage Status

Description

Automate your own tasks on pure python and execute it on remote or local hosts

fact "uptime | cowsay"
frizzy@localhost in: uptime | cowsay
frizzy@localhost out:  ______________________________________
frizzy@localhost out: /  00:38:46 up 17 days, 8:39, 7 users, \
frizzy@localhost out: \ load average: 0,95, 0,95, 0,94       /
frizzy@localhost out:  --------------------------------------
frizzy@localhost out:         \   ^__^
frizzy@localhost out:          \  (oo)\_______
frizzy@localhost out:             (__)\       )\/\
frizzy@localhost out:                 ||----w |
frizzy@localhost out:                 ||     ||

original idea of example

Long Description

Factory is proof-of-concept realization of fabric with a number of differences:

Note that Factory uses pipes for communication with subprocess. So, there is no way to use popen and automatically write passwords for ssh and sudo on localhost, because "smart" programs like ssh and sudo uses tty directly. Also active tty required (needed check it) and for sudo uses "sudo -S".

Alternatives:

  1. Use paramico like fabric = no ssh sockets.

  2. Use pty.fork, waitpid, execv as pexcpect and sh = only unix, no separated stderr, hard to communicate.

  3. Use ssh-copy-id like sh module recommended = ask passwords only one first time.

  4. Use sshpass like ansible = external dependencies.

  5. Use local ssh server and run all commands through it instead of popen (we need to go deeper).

Of course, you can write your own run() function with previous decisions and use it!

Examples:

fact run 'echo "hello, world!"'
frizzy@localhost in: echo "hello, world!"
frizzy@localhost out: hello, world!
cat factfile
#!/usr/bin/env python
# coding=utf-8
from factory.api import run

def hello_fact():
    run('echo "this is factfile"')
fact hello_fact
frizzy@localhost in: echo "this is factfile"
frizzy@localhost out: this is factfile
cat fabfile 
#!/usr/bin/env python
# coding=utf-8
from fabric.api import run

def hello_fab():
    run('echo "this is fabfile"')
fact hello_fab
frizzy@localhost in: echo "this is fabfile"
frizzy@localhost out: this is fabfile
cat my_little_script.py 
#!/usr/bin/env python
# coding=utf-8
from factory.api import *

def hello():
    run('echo "hello world!"')

if __name__ == '__main__':
    # running hello on two hosts
    env.hosts = ['localhost', 'test@127.0.0.1']
    for host in env.hosts:
        with set_connect_env(host):
            hello()
            run(raw_input('type the command: '))
python my_little_script.py 
frizzy@localhost in: echo "hello world!"
frizzy@localhost out: hello world!
type the command: echo "hello, username!"
frizzy@localhost in: echo "hello, username!"
frizzy@localhost out: hello, username!
test@127.0.0.1 in: echo "hello world!"
test@127.0.0.1 out: hello world!
type the command: echo "hello, test"             
test@127.0.0.1 in: echo "hello, test"
test@127.0.0.1 out: hello, test

WiKi will be soon

Board on trello

For contributors: fetch and merge, don’t pull

Contributors