先看一下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開發(fā)的擴展工具,封裝了一些功能,但是總體還是很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