From: dsc Date: Tue, 8 May 2012 22:29:45 +0000 (-0700) Subject: Moves fabfile to a directory; adds utils; implements collapse_trees() X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=41a33e1ce9b03e2cabd15f5b060a5f0839e32182;p=limn-bak.git Moves fabfile to a directory; adds utils; implements collapse_trees() --- diff --git a/fabfile.py b/fabfile/__init__.py similarity index 50% rename from fabfile.py rename to fabfile/__init__.py index 5a0cd2f..0c24425 100644 --- a/fabfile.py +++ b/fabfile/__init__.py @@ -1,8 +1,27 @@ -#!/usr/bin/env python +#!/usr/bin/env fab # -*- coding: utf-8 -*- +""" GraphKit Fabric File +""" + +# Deal with the fact that we aren't *really* a Python project, +# so we haven't declared python dependencies. +import sys +try: + import fabric + from path import path +except ImportError: + print "ERROR: You're missing a dependency! " + "To build this project using fabric, you'll need to install fabric (and some other stuff):" + "\n\n" + "pip install -U fabric path.py" + sys.exit(1) + + + from fabric.api import * from fabric.colors import white, blue, cyan, green, yellow, red, magenta +from fabric.contrib.project import rsync_project env.project_name = 'kraken-ui' env.use_ssh_config = True # this is not working for me! @@ -12,9 +31,9 @@ env.colors = True # defaults # Hm. -env.local_dist_directory = 'tmp/dist' -env.dist_directory = 'dist' - +env.local_dist_directory = path('tmp/dist') +env.dist_directory = path('dist') +env.dev_server = 'localhost:8081' # There should be a way to do this using stages. # See: http://tav.espians.com/fabric-python-with-cleaner-api-and-parallel-deployment-support.html @@ -39,42 +58,46 @@ def staging(): env.owner = 'wmf' env.group = 'www' + +### Build Deploy Bundle + @task def update_version(): - """ Updates `lib/version.js`. + """ Ensure `lib/version.js` has up to date git revision. """ local('coke update_version') @task def collapse_trees(): - """ - # Ensure gitrev is up to date - coke update_version - - # Ensure clean dist directory - [ -e "tmp/dist" ] && rm -rf tmp/dist - mkdir -p tmp/dist - - ### Collapse the serve trees into one directory - log "Collapsing serve trees..." - - # Copy the static files, derived files, and the whole data directory (bc lack of trailing /) - # into dist. Note that you will need to load all the site pages in your browser to populate var - # with the derived files. - rsync -Ca static/ var/ data tmp/dist/ - - # We copy lib (which contains .co source files) to src to make it easy to link source content - # to each other. Finding it in gitweb is a pain. Finding it in gerrit is almost impossible. - # But this could go away when we move to github. - rsync -Ca lib/ tmp/dist/src/ - - # For some reason, the shell tool does not generate a file identical to the middleware. So whatever. - # We curl here because we know that version works. - curl --silent --fail --url http://$DEV_HOST/vendor/browserify.js > tmp/dist/vendor/browserify.js - # browserify -o tmp/dist/vendor/browserify.js -r events -r seq + """ Collapse the serve trees into one directory. """ + dist = env.local_dist_directory + + # Update version (derf) update_version() + # Ensure clean dist directory + dist.rmtree(ignore_errors=True) + dist.makedirs() + + # XXX: Unfortunately, we can't use rsync_project() for local-to-local copies, as it insists on + # inserting a : before the remote path, which indicates a local-to-remote copy. :( + + # Copy the static files, derived files, and the whole data directory (bc lack of trailing /) + # into dist. Note that you will need to load all the site pages in your browser to populate var + # with the derived files. + local('rsync -Ca static/ var/ data %s/' % dist) + + # We copy lib (which contains .co source files) to src to make it easy to link source content + # to each other. Finding it in gitweb is a pain. Finding it in gerrit is almost impossible. + # But this could go away when we move to github. + local('rsync -Ca lib/ %s/src/' % dist) + + # For some reason, the shell tool does not generate a file identical to the middleware. So whatever. + # We curl here because we know that version works. + # local('browserify -o %s/vendor/browserify.js -r events -r seq' % dist) + with open('%s/vendor/browserify.js' % dist, 'w') as f: + f.write( local('curl --silent --fail --url http://%s/vendor/browserify.js', capture=True) ) @task def bundle(): diff --git a/fabfile/util.py b/fabfile/util.py new file mode 100644 index 0000000..bcffa5f --- /dev/null +++ b/fabfile/util.py @@ -0,0 +1,19 @@ +#!/usr/bin/env fab +# -*- coding: utf-8 -*- + +# Liberated from fabric source: +# https://github.com/fabric/fabric/blob/master/fabfile/utils.py + +from __future__ import with_statement +from contextlib import contextmanager +from fabric.api import hide, puts + +__all__ = ('msg',) + + +@contextmanager +def msg(txt): + puts(txt + "...", end='', flush=True) + with hide('everything'): + yield + puts("done.", show_prefix=False, flush=True)