danielfm / django-flash
- Source
- Commits
- Network (4)
- Issues (0)
- Downloads (23)
- Wiki (1)
- Graphs
-
Branch:
master
django-flash / fabfile.py
| 19e91cd3 » | danielfm | 2009-06-26 | 1 | # -*- coding: utf-8 -*- | |
| 2 | |||||
| ae7a2547 » | danielfm | 2009-11-01 | 3 | """Build script used to test, build and deploy django-flash using several | |
| 28fb6278 » | danielfm | 2009-06-27 | 4 | Python versions. | |
| 5 | |||||
| d65c9809 » | danielfm | 2009-06-27 | 6 | In order to test and build django-flash in these different environments, | |
| ae7a2547 » | danielfm | 2009-11-01 | 7 | this script requires different virtualenvs, each one targeted to a specific | |
| 8 | Python version: | ||||
| 28fb6278 » | danielfm | 2009-06-27 | 9 | ||
| 10 | * django-flash-py2.6 - for Python 2.6 | ||||
| 11 | * django-flash-py2.5 - for Python 2.5 | ||||
| 12 | * django-flash-py2.4 - for Python 2.4 | ||||
| 13 | |||||
| d65c9809 » | danielfm | 2009-06-27 | 14 | Also, each one of these virtualenvs must have the following packages | |
| 28fb6278 » | danielfm | 2009-06-27 | 15 | installed: | |
| 16 | |||||
| ae7a2547 » | danielfm | 2009-11-01 | 17 | * Django (version 1.0+) | |
| 28fb6278 » | danielfm | 2009-06-27 | 18 | * Pysqlite (version recommended by the current Django version) | |
| 19 | |||||
| 20 | Finally, to use this script, you must install the packages below to your | ||||
| 21 | default Python installation: | ||||
| 22 | |||||
| ae7a2547 » | danielfm | 2009-11-01 | 23 | * Fabric 0.9+ | |
| 28fb6278 » | danielfm | 2009-06-27 | 24 | ||
| d65c9809 » | danielfm | 2009-06-27 | 25 | That's it. You can now see all available targets provided by this build | |
| 26 | script by running the command line below: | ||||
| 28fb6278 » | danielfm | 2009-06-27 | 27 | ||
| 28 | $ cd /path/to/django-flash | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 29 | $ fab -l | |
| 19e91cd3 » | danielfm | 2009-06-26 | 30 | """ | |
| 31 | |||||
| baf9f3a6 » | danielfm | 2009-09-18 | 32 | import os | |
| 33 | import re | ||||
| 34 | import sys | ||||
| 35 | |||||
| ae7a2547 » | danielfm | 2009-11-01 | 36 | from fabric.api import * | |
| 37 | |||||
| 38 | |||||
| baf9f3a6 » | danielfm | 2009-09-18 | 39 | # Adds the 'src' to the Python path | |
| ae7a2547 » | danielfm | 2009-11-01 | 40 | sys.path += ('src',) | |
| baf9f3a6 » | danielfm | 2009-09-18 | 41 | ||
| 42 | # Supported Python versions | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 43 | env.versions = ('2.6', '2.5', '2.4') | |
| 44 | env.default_version = env.versions[0] | ||||
| baf9f3a6 » | danielfm | 2009-09-18 | 45 | ||
| 19e91cd3 » | danielfm | 2009-06-26 | 46 | # Environment info | |
| ae7a2547 » | danielfm | 2009-11-01 | 47 | env.project = 'django-flash' | |
| 48 | env.virtualenv_dir = os.environ['WORKON_HOME'] or '~/.virtualenvs' | ||||
| 49 | env.default_editor = os.environ['EDITOR'] or 'vi' | ||||
| baf9f3a6 » | danielfm | 2009-09-18 | 50 | ||
| 51 | # Files that contain version information | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 52 | env.new_version_files = ( | |
| baf9f3a6 » | danielfm | 2009-09-18 | 53 | 'setup.py', | |
| 54 | 'src/djangoflash/__init__.py', | ||||
| 55 | 'doc/source/conf.py', | ||||
| 66a221bf » | danielfm | 2009-09-18 | 56 | 'doc/source/changelog.rst', | |
| baf9f3a6 » | danielfm | 2009-09-18 | 57 | ) | |
| 19e91cd3 » | danielfm | 2009-06-26 | 58 | ||
| 59 | # Information needed to build the documentation | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 60 | env.sphinx_output = 'build/sphinx' | |
| 61 | env.sphinx_latex = '%s/latex' % env.sphinx_output | ||||
| 62 | env.sphinx_html = '%s/html' % env.sphinx_output | ||||
| 63 | env.doc_output = 'djangoflash' | ||||
| 19e91cd3 » | danielfm | 2009-06-26 | 64 | ||
| 65 | # Host where the documentation website lives | ||||
| 13fb2bd5 » | danielfm | 2009-11-23 | 66 | env.hosts = ['destaquenet.com'] | |
| ae7a2547 » | danielfm | 2009-11-01 | 67 | env.doc_folder = '/home/destaquenet/public_html' | |
| 19e91cd3 » | danielfm | 2009-06-26 | 68 | ||
| 69 | |||||
| ae7a2547 » | danielfm | 2009-11-01 | 70 | def setup(command, version=env.default_version): | |
| deb84645 » | danielfm | 2009-06-26 | 71 | """Executes the given setup command with a virtual Python installation. | |
| 19e91cd3 » | danielfm | 2009-06-26 | 72 | """ | |
| 8bd8995d » | danielfm | 2009-09-18 | 73 | local('%s/%s-py%s/bin/python setup.py %s' % | |
| ae7a2547 » | danielfm | 2009-11-01 | 74 | (env.virtualenv_dir, env.project, version, command)) | |
| 19e91cd3 » | danielfm | 2009-06-26 | 75 | ||
| 76 | def test(): | ||||
| 77 | """Runs all tests in different Python versions. | ||||
| 78 | """ | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 79 | for version in env.versions: | |
| c933ccbc » | danielfm | 2009-06-26 | 80 | setup('test', version) | |
| 19e91cd3 » | danielfm | 2009-06-26 | 81 | ||
| c933ccbc » | danielfm | 2009-06-26 | 82 | def clean(): | |
| deb84645 » | danielfm | 2009-06-26 | 83 | """Removes the build directory. | |
| 19e91cd3 » | danielfm | 2009-06-26 | 84 | """ | |
| c933ccbc » | danielfm | 2009-06-26 | 85 | local('rm -fR build') | |
| 19e91cd3 » | danielfm | 2009-06-26 | 86 | ||
| 87 | def build_docs(): | ||||
| deb84645 » | danielfm | 2009-06-26 | 88 | """Builds the documentation in PDF and HTML. | |
| 19e91cd3 » | danielfm | 2009-06-26 | 89 | """ | |
| ae7a2547 » | danielfm | 2009-11-01 | 90 | clean() | |
| 19e91cd3 » | danielfm | 2009-06-26 | 91 | setup('build_sphinx') | |
| 92 | setup('build_sphinx -b latex') | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 93 | local('make -C ' + env.sphinx_latex) | |
| 19e91cd3 » | danielfm | 2009-06-26 | 94 | ||
| 95 | def zip_docs(): | ||||
| c933ccbc » | danielfm | 2009-06-26 | 96 | """Creates a zip file with the complete documentation. | |
| 19e91cd3 » | danielfm | 2009-06-26 | 97 | """ | |
| ae7a2547 » | danielfm | 2009-11-01 | 98 | build_docs() | |
| 8bd8995d » | danielfm | 2009-09-18 | 99 | local('cp %s/%s.pdf %s' % | |
| ae7a2547 » | danielfm | 2009-11-01 | 100 | (env.sphinx_latex, env.project, env.sphinx_html)) | |
| 8bd8995d » | danielfm | 2009-09-18 | 101 | local('cd %s; mv html %s; zip -r9 %s.zip %s' % | |
| ae7a2547 » | danielfm | 2009-11-01 | 102 | ((env.sphinx_output,) + (env.doc_output,)*3)) | |
| 19e91cd3 » | danielfm | 2009-06-26 | 103 | ||
| 104 | def register_pypi(): | ||||
| 105 | """Register the current version on PyPI. | ||||
| 106 | """ | ||||
| 107 | setup('register') | ||||
| 108 | |||||
| 109 | def deploy_src(): | ||||
| 110 | """Deploy the source code to PyPI. | ||||
| 111 | """ | ||||
| 112 | setup('sdist upload') | ||||
| 113 | |||||
| 114 | def deploy_eggs(): | ||||
| 115 | """Upload Python Eggs to PyPI. | ||||
| 116 | """ | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 117 | for version in env.versions: | |
| 19e91cd3 » | danielfm | 2009-06-26 | 118 | setup('bdist_egg upload', version) | |
| 119 | |||||
| 120 | def deploy_pypi(): | ||||
| c933ccbc » | danielfm | 2009-06-26 | 121 | """Deploys all artifacts to PyPI. | |
| 19e91cd3 » | danielfm | 2009-06-26 | 122 | """ | |
| ae7a2547 » | danielfm | 2009-11-01 | 123 | test() | |
| 124 | register_pypi() | ||||
| 125 | deploy_src() | ||||
| 126 | deploy_eggs() | ||||
| 19e91cd3 » | danielfm | 2009-06-26 | 127 | ||
| 128 | def deploy_website(): | ||||
| c933ccbc » | danielfm | 2009-06-26 | 129 | """Deploys the documentation website. | |
| 19e91cd3 » | danielfm | 2009-06-26 | 130 | """ | |
| ae7a2547 » | danielfm | 2009-11-01 | 131 | zip_docs() | |
| 8bd8995d » | danielfm | 2009-09-18 | 132 | put('%s/%s.zip' % | |
| ae7a2547 » | danielfm | 2009-11-01 | 133 | (env.sphinx_output, env.doc_output), env.doc_folder) | |
| 8bd8995d » | danielfm | 2009-09-18 | 134 | run('cd %s; rm -R %s; unzip %s.zip; rm %s.zip' % | |
| ae7a2547 » | danielfm | 2009-11-01 | 135 | ((env.doc_folder,) + (env.doc_output,)*3)) | |
| 19e91cd3 » | danielfm | 2009-06-26 | 136 | ||
| 137 | def deploy(): | ||||
| c933ccbc » | danielfm | 2009-06-26 | 138 | """Deploys the application to PyPI and updates the documentation website. | |
| 19e91cd3 » | danielfm | 2009-06-26 | 139 | """ | |
| ae7a2547 » | danielfm | 2009-11-01 | 140 | deploy_pypi() | |
| 141 | deploy_website() | ||||
| baf9f3a6 » | danielfm | 2009-09-18 | 142 | ||
| 143 | def tag_new_version(): | ||||
| 8bd8995d » | danielfm | 2009-09-18 | 144 | """Updates the version number, pushing the changes and tagging afterwards. | |
| baf9f3a6 » | danielfm | 2009-09-18 | 145 | """ | |
| 146 | # Checks if there are changed or untracked files | ||||
| 147 | git_status_file = 'build/git_status' | ||||
| 148 | local('git status > %s' % git_status_file, fail='ignore') | ||||
| 149 | if re.search(r'(Changed|Untracked)', file(git_status_file, 'r').read()): | ||||
| 150 | print 'There are changed or untracked files. Aborting...' | ||||
| 151 | return | ||||
| 152 | |||||
| 153 | # Brings up the text editor with the files to be changed | ||||
| ae7a2547 » | danielfm | 2009-11-01 | 154 | for f in env.new_version_files: | |
| 155 | local('%s %s' % (env.default_editor, f)) | ||||
| baf9f3a6 » | danielfm | 2009-09-18 | 156 | ||
| 157 | # Asks for confirmation | ||||
| 158 | prompt('tag_proceed', 'You are about to commit and push the version ' | ||||
| 159 | 'changes. Continue?', default='y') | ||||
| 160 | |||||
| ae7a2547 » | danielfm | 2009-11-01 | 161 | if env.tag_proceed.upper() != 'Y': | |
| baf9f3a6 » | danielfm | 2009-09-18 | 162 | print 'Aborting...' | |
| 163 | return | ||||
| 164 | |||||
| 2909567f » | danielfm | 2009-09-18 | 165 | # Commits and tags the new release | |
| baf9f3a6 » | danielfm | 2009-09-18 | 166 | from djangoflash import __version__ | |
| dfde88d7 » | danielfm | 2009-09-18 | 167 | local('git commit -am "Updated version number."; git push', fail='ignore') | |
| 8bd8995d » | danielfm | 2009-09-18 | 168 | local('git tag -am "Tagged version %s." %s; git push --tags' % | |
| 169 | ((__version__,)*2), fail='ignore') | ||||
| baf9f3a6 » | danielfm | 2009-09-18 | 170 | local('git push --tags') | |
| ae7a2547 » | danielfm | 2009-11-01 | 171 | ||
