Fabric is a tool written in Python that lets you defind tasks and execute them by running fab taskname. Fabfiles are pure Python, so you can build larger tasks out of smaller ones very easily and do just about anything you want. It’s similar to ant, but without the excessive over-engineering.
from fabric.api import *
import os
import fabric.contrib.project as project
PROD = 'sjl.webfactional.com'
DEST_PATH = '/home/sjl/webapps/slc/'
ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
DEPLOY_PATH = os.path.join(ROOT_PATH, 'deploy')
def clean():
local('rm -rf ./deploy')
def regen():
clean()
local('hyde -g -s .')
def serve():
local('hyde -w -s .')
def reserve():
regen()
serve()
def smush():
local('smusher ./media/images')
@hosts(PROD)
def publish():
regen()
project.rsync_project(
remote_dir=DEST_PATH,
local_dir=DEPLOY_PATH.rstrip('/') + '/',
delete=True
)
The task I use most often while developing is fab reserve, which regenerates the site and then starts serving it so I can view the result in a browser.
I use fab smush whenever I add new images. This runs smusher on all of the images to optimize them without reducing quality.
When I’m ready to publish changes to the live site I run fab publish, which will regenerate my local version and copy it up to the WebFaction server.
References:
YOU MIGHT ALSO LIKE
- 09 Sep 2026 » 本博客使用手册:GitHub Pages、写作规范与站点能力
- 09 Sep 2026 » AI 平台工程(08):可观测、成本与 FinOps
- 08 Sep 2026 » AI 平台工程(07):模型网关与多租户——路由、配额与灰度
OUTLINE
没有匹配的标题
COMMENTS
评论存放在 GitHub Discussions, 用 GitHub 账号登录即可发表,支持 Markdown。 想针对正文某句话说?选中那段文字,点浮出的「评论」即可划线评论;觉得哪里写错了,发表时勾上「同时提交 Issue」。 有人回复你时 GitHub 会按你的通知设置发邮件,不用守在这里。