fabric的扩展使用
2017-08-05 本文已影响22人
jiaxiaolei
先看一下fabri的帮助文档:
>>> import fabric
>>> help(fabric)
Help on package fabric:
NAME
fabric - See `fabric.api` for the publically importable API.
FILE
/usr/lib64/python2.7/site-packages/fabric/__init__.py
PACKAGE CONTENTS
__main__
api
auth
colors
context_managers
contrib (package)
decorators
docs
exceptions
io
job_queue
main
network
operations
sftp
state
task_utils
tasks
thread_handling
utils
version
(END)
平时用的最多的就是fabric.api中的方法,比如:from fabric.api import run
。
但是fabric除了api 模块,还有其他一些有用的模块。
虽然有些可能比较“鸡肋”。 一条简单的 shell 命令就可以搞定,非要重新学习那么多方法。
但是各有所爱,有些人就愿意用封装好的方法,否则ORM也不会那么流行。(用ORM的原因很多,但是说“用ORM, 可以不用关心SQL”就大错特错了。试想,如果不懂SQL, 能写出高质量的查询语句吗?)
这是fabric.contrib 模块中对对project的相关方法。
In [11]: from fabric.contrib import project
In [12]: help(project)
NAME
fabric.contrib.project - Useful non-core functionality, e.g. functions composing multiple operations.
FILE
/usr/lib64/python2.7/site-packages/fabric/contrib/project.py
FUNCTIONS
rsync_project(*args, **kwargs)
Synchronize a remote directory with the current project directory via rsync.
Where ``upload_project()`` makes use of ``scp`` to copy one's entire
project every time it is invoked, ``rsync_project()`` uses the ``rsync``
command-line utility, which only transfers files newer than those on the
remote end.
``rsync_project()`` is thus a simple wrapper around ``rsync``; for
details on how ``rsync`` works, please see its manpage. ``rsync`` must be
installed on both your local and remote systems in order for this operation
to work correctly.
This function makes use of Fabric's ``local()`` operation, and returns the
output of that function call; thus it will return the stdout, if any, of
the resultant ``rsync`` call.
还有很多基于fabric进行扩展的工具,比如 fabric_components。
简介来说,很多基于fabric开发的扩展工具,封装了一些功能,但是总体还是很low。不容易扩展。
fabric_components 0.1.1
https://pypi.python.org/pypi/fabric_components/0.1.1
简介:
pypi 上的介绍。
shuoli84/fabric-components
https://github.com/shuoli84/fabric-components
简介:
github 上的介绍的。
看着 fabric_components 中提供的这些方法,看着都比较low.
from fabric_components.folder import create_folder
from fabric_components.mysql import install_mysql, db_env, create_database, create_user, apt_get