fabric的擴展使用

先看一下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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,978評論 25 709
  • # Python 資源大全中文版 我想很多程序員應該記得 GitHub 上有一個 Awesome - XXX 系列...
    aimaile閱讀 26,832評論 6 427
  • 環(huán)境管理管理Python版本和環(huán)境的工具。p–非常簡單的交互式python版本管理工具。pyenv–簡單的Pyth...
    MrHamster閱讀 3,952評論 1 61
  • 暖色打底 一邊冷色調 一邊暖色調 還有紙飛機 我想起了許飛的《許愿樹》 一棵樹在野草的邊上 不再東張西望 秋風葉落...
    谷喵兒閱讀 869評論 0 1
  • 候鳥鉆進琥珀似的天空 魚兒潛入水晶似的池塘 漣漪沒有溶化 永遠停在那里 搖椅呈45度的斜角 水杯余40度的溫和 不...
    行走的卓瑪閱讀 165評論 0 0

友情鏈接更多精彩內容