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开发的扩展工具,封装了一些功能,但是总体还是很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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,663评论 25 708
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    aimaile阅读 26,597评论 6 427
  • 环境管理管理Python版本和环境的工具。p–非常简单的交互式python版本管理工具。pyenv–简单的Pyth...
    MrHamster阅读 3,856评论 1 61
  • 暖色打底 一边冷色调 一边暖色调 还有纸飞机 我想起了许飞的《许愿树》 一棵树在野草的边上 不再东张西望 秋风叶落...
    谷喵儿阅读 782评论 0 1
  • 候鸟钻进琥珀似的天空 鱼儿潜入水晶似的池塘 涟漪没有溶化 永远停在那里 摇椅呈45度的斜角 水杯余40度的温和 不...
    行走的卓玛阅读 155评论 0 0