Some example fabfiles

Paste in fabfiles you use.

One I use for an s5 presentation

- Morgan Goose

   1 #!/usr/bin/env python
   2 
   3 from fabric.api import *
   4 
   5 env.roledefs = {
   6     'production': ["morgangoose.com"],
   7     'test': ['morgan.dyn-o-saur.com'],
   8     }
   9 
  10 presentation = "gnu_tools"
  11 presentation_archive = "%s.tar.gz" % presentation
  12 presentation_dir = "/var/www/html/p/"
  13 rst_source = "%s.rst" % presentation
  14 pdf = "%s.pdf" % presentation
  15 
  16 @roles('production')
  17 def upload():
  18     env.user = "my_user_name"
  19     package()
  20     put(presentation_archive, presentation_dir)
  21     with cd(presentation_dir):
  22         run("rm -rf %s/" % presentation)
  23         run("tar zxvf %s" % presentation_archive)
  24         run("cp %s %s/files/" % (presentation_archive, presentation))
  25 
  26 @roles('test')
  27 def test():
  28     package()
  29     local("sudo cp %s /var/www/lighttpd/p/" % presentation_archive)
  30     with cd("/var/www/lighttpd/p/"):
  31         #I use local() here instead of sudo() because of localhost issues.
  32         local("sudo rm -rf %s/" % presentation)
  33         local("sudo tar zxvf %s" % presentation_archive)
  34         local("sudo cp %s %s/files/" % (presentation_archive, presentation))
  35         local("sudo chown lighttpd. -R /var/www/lighttpd/p/")
  36 
  37 def package():
  38     make_presentation()
  39     local("tar zcvf %s %s" % (presentation_archive, presentation))
  40 
  41 def make_presentation():
  42     #PDF first
  43     local("rst2pdf %s/%s -o %s/%s" % (
  44         presentation,
  45         rst_source,
  46         presentation,
  47         pdf,
  48         ))
  49 
  50     #Then s5 html presentation
  51     local("python rst-directive.py \
  52             --stylesheet=pygments.css \
  53             --theme=small-black \
  54             %s/%s > %s/index.html" % (
  55                 presentation,
  56                 rst_source,
  57                 presentation,
  58                 )
  59             )

How I upload a wordpress theme after changes

- Morgan Goose

   1 from fabric.api import *
   2 
   3 env.user = 'webmaster_username'
   4 env.hosts = ['gamedev.hostname']
   5 
   6 def pack():
   7     local('tar czf /tmp/gamedev_theme.tgz gamedev_theme/', capture=False)
   8 
   9 def deploy_theme():
  10     pack()
  11     put('/tmp/gamedev_theme.tgz', '/tmp/')
  12     with cd('/var/www/gcc/html/wp-content/themes/'):
  13         run('tar xzf /tmp/gamedev_theme.tgz')

fabfiles (last edited 2010-02-03 16:59:42 by Morgan Goose)