Python Fabrik で、試す
もう少し、弄ってみたので、亡備録。
まず、リモートで動かすのは、runとかでやる。
env.use_ssh_config = True env.hosts = ['xxxxxxxx'] env.shell = "/usr/local/bin/bash -l -c " def hello(): run("echo `hostname`")
ssh/config を使う様にしたので、そいつを有効にした。
次に、ローカルで、あれこれやってみる。
丁度、init.elを、gitに上げているので、それを、自動化してみた。
def git_log(): with lcd("~/git/initel.git"): local("git log") def git_commit(): local("cp ~/.emacs.d/init.el ~/git/initel.git/") with lcd("~/git/initel.git"): # Err があっても、Abortしないようにする with settings(warn_only=True): result = local("git add . && git commit -m 'commi'") if result.failed and not console.confirm("Tests failed. Continue anyway?"): abort("Aborting at user request.") git_push() def git_push(): with lcd("~/git/initel.git"): local("git push")
commitは、何も、commitするものがないと、エラーになるので
settings(warn_only=True): で、エラーでアボートしないようにして
人が、Y/nを入力する様にしてみた。
def rsync_howm(): project.rsync_project('~/.howm', '~/.howm')
舐めてんのか、くらい、簡単な例ですみません。。
全文を、のっけときます。
# -*- coding: utf-8 -*- from fabric.api import env,run,local,lcd,settings,abort from fabric.contrib import console,project env.use_ssh_config = True env.hosts = ['xxxxxxxx'] env.shell = "/usr/local/bin/bash -l -c " def hello(): run("echo `hostname`") def local_date(): local("date") def git_log(): with lcd("~/git/initel.git"): local("git log") def git_commit(): local("cp ~/.emacs.d/init.el ~/git/initel.git/") with lcd("~/git/initel.git"): # Err があっても、Abortしないようにする with settings(warn_only=True): result = local("git add . && git commit -m 'commi'") if result.failed and not console.confirm("Tests failed. Continue anyway?"): abort("Aborting at user request.") git_push() def git_push(): with lcd("~/git/initel.git"): local("git push") def rsync_howm(): project.rsync_project('~/.howm', '~/.howm')
ちなみに、鍵認証のパスワード無しで、sshは、つないでます。
あと、Pythonは、書いた事無いです。。 (´・ω・`)