先看一下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)
平時(shí)用的最多的就是fabric.api中的方法橡疼,比如:from fabric.api import run
。
但是fabric除了api 模塊欣除,還有其他一些有用的模塊住拭。
雖然有些可能比較“雞肋”历帚。 一條簡(jiǎn)單的 shell 命令就可以搞定,非要重新學(xué)習(xí)那么多方法挽牢。
但是各有所愛谱煤,有些人就愿意用封裝好的方法禽拔,否則ORM也不會(huì)那么流行。(用ORM的原因很多睹栖,但是說(shuō)“用ORM, 可以不用關(guān)心SQL”就大錯(cuò)特錯(cuò)了。試想野来,如果不懂SQL, 能寫出高質(zhì)量的查詢語(yǔ)句嗎?)
這是fabric.contrib 模塊中對(duì)對(duì)project的相關(guān)方法梁只。
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進(jìn)行擴(kuò)展的工具埃脏,比如 fabric_components。
簡(jiǎn)介來(lái)說(shuō)彩掐,很多基于fabric開發(fā)的擴(kuò)展工具,封裝了一些功能堵幽,但是總體還是很low。不容易擴(kuò)展朴下。
fabric_components 0.1.1
https://pypi.python.org/pypi/fabric_components/0.1.1
簡(jiǎn)介:
pypi 上的介紹。
shuoli84/fabric-components
https://github.com/shuoli84/fabric-components
簡(jiǎn)介:
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