~lindsay/fabric-example

d125035a66dc2cb679cdae0da788463e9b99331b — LindsayTouho 1 year, 7 months ago 37c82a2
Fabric nameserver and submodule
4 files changed, 54 insertions(+), 2 deletions(-)

M .gitignore
A fabfile.py
A log.py
A submodule.py
M .gitignore => .gitignore +0 -2
@@ 1,4 1,3 @@
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]


@@ 137,4 136,3 @@ dmypy.json

# Cython debug symbols
cython_debug/


A fabfile.py => fabfile.py +19 -0
@@ 0,0 1,19 @@
from log import logger

from invoke import Collection
from fabric import task

from submodule import subc

ns = Collection()

@task
def test(c):
    """root task for test"""
    c.run('uname -a')
    logger.info('test task done')

ns.add_task(test)
ns.add_collection(subc)
    


A log.py => log.py +20 -0
@@ 0,0 1,20 @@
import logging


logger = logging.getLogger('Fabric')
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('fabric.log')
fh.setLevel(logging.INFO)

ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)


formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(funcName)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)


logger.addHandler(fh)
logger.addHandler(ch)


A submodule.py => submodule.py +15 -0
@@ 0,0 1,15 @@
from invoke import Collection
from fabric import task, Connection
from log import logger

subc = Collection('subc')

@task
def sub_task(c):
    """task in submodule"""
    c.run('hostname')
    logger.info('sub-task done')
    
subc.add_task(sub_task, name='subt')