pavement.py
author Daniel Hans <Daniel.M.Hans@gmail.com>
Tue, 10 Nov 2009 18:18:06 +0100
changeset 3085 ded7a67e7e0a
parent 2599 22e1ec7bd02a
permissions -rw-r--r--
Some functions which applies to scoped tags in general moved from TaskTag to Task model. Also, some stylish and whitespace changes and docstrings added.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2457
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     2
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     3
"""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     4
Example Usage
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     5
=============
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     6
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     7
The following commands can be run from the root directory of the Mercurial
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     8
repo. To run ``paver``, however, you'll need to do ``easy_install Paver``.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
     9
Most of the following commands accept other arguments; see ``command --help``
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    10
for more information, or ``paver help`` for a list of all the valid commands.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    11
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    12
    ``paver build``
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    13
        Builds the project. This essentially just runs a bunch of other tasks,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    14
        like ``pylint``, ``django_zip`` and ``tinymce_zip``, etc.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    15
    ``paver pylint``
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    16
        Runs PyLint on the project.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    17
    ``paver django_zip``
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    18
        Builds the Django zip file.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    19
    ``paver tinymce_zip``
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    20
        Builds the TinyMCE zip file.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    21
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    22
If you specify ``--dry-run`` before a task, then the action of that task will
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    23
not actually be carried out, although logging output will be displayed as if
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    24
it were. For example, you could run ``paver --dry-run django_zip`` to see what
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    25
files would be added to the ``django.zip`` file, etc.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    26
"""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    27
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    28
from cStringIO import StringIO
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    29
import sys
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    30
import zipfile
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    31
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    32
import paver
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    33
import paver.easy
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    34
import paver.tasks
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    35
from paver.easy import *
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    36
from paver.path import path
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    37
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    38
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    39
# Paver comes with Jason Orendorff's 'path' module; this makes path
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    40
# manipulation easy and far more readable.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    41
PROJECT_DIR = path(__file__).dirname()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    42
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    43
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    44
# Set some default options. Having the options at the top of the file cleans
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    45
# the whole thing up and makes the behaviour a lot more configurable.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    46
options(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    47
    build = Bunch(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    48
        project_dir = PROJECT_DIR,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    49
        app_build = PROJECT_DIR / 'build',
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    50
        app_folder = PROJECT_DIR / 'app',
2599
22e1ec7bd02a Add queue.yaml to build scripts.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2457
diff changeset
    51
        app_files = ['app.yaml', 'cron.yaml', 'index.yaml', 'queue.yaml',
22e1ec7bd02a Add queue.yaml to build scripts.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2457
diff changeset
    52
		     'main.py', 'settings.py', 'shell.py', 'urls.py', 
22e1ec7bd02a Add queue.yaml to build scripts.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2457
diff changeset
    53
		     'gae_django.py'],
2457
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    54
        app_dirs =  ['soc', 'ghop', 'gsoc', 'feedparser', 'python25src',
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    55
                     'reflistprop', 'jquery', 'ranklist', 'shell', 'json',
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    56
                     'htmlsanitizer', 'taggable-mixin', 'gviz'],
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    57
        zip_files = ['tiny_mce.zip'],
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    58
        skip_pylint = False,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    59
    )
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    60
)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    61
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    62
# The second call to options allows us to re-use some of the constants defined
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    63
# in the first call.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    64
options(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    65
    clean_build = options.build,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    66
    tinymce_zip = options.build,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    67
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    68
    django_zip = Bunch(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    69
        prune_dirs = ['.svn', 'gis', 'admin', 'localflavor', 'mysql',
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    70
                      'mysql_old', 'oracle', 'postgresql',
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    71
                      'postgresql_psycopg2', 'sqlite3', 'test'],
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    72
        **options.build
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    73
    ),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    74
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    75
    pylint = Bunch(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    76
        check_modules = ['soc', 'reflistprop', 'settings.py', 'urls.py',
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    77
                         'main.py'],
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    78
        quiet = False,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    79
        quiet_args = ['--disable-msg=W0511,R0401', '--reports=no',
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    80
                      '--disable-checker=similarities'],
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    81
        pylint_args = [],
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    82
        ignore = False,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    83
        **options.build
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    84
    )
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    85
)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    86
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    87
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    88
# Utility functions
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    89
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    90
def django_zip_files(django_src_dir):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    91
    """Yields each filename which should go into ``django.zip``."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    92
    for filename in django_src_dir.walkfiles():
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    93
        # The following seems unnecessarily unreadable, but unfortunately
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    94
        # it seems it cannot be unobfuscated any more (if someone finds a
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    95
        # nicer way of writing it, please tell me).
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    96
        if not (filename.ext in ['.pyc', '.pyo', '.po', '.mo'] or
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    97
                any(name in filename.splitall()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    98
                    for name in options.django_zip.prune_dirs)):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
    99
            # The filename is suitable to be added to the archive. In this
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   100
            # case, we yield the filename and the name it should be given in
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   101
            # the Zip archive.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   102
            paver.tasks.environment.info(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   103
                '%-4sdjango.zip <- %s', '', filename)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   104
            arcname = path('django') / django_src_dir.relpathto(filename)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   105
            yield filename, arcname
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   106
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   107
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   108
def tinymce_zip_files(tiny_mce_dir):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   109
    """Yields each filename which should go into ``tiny_mce.zip``."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   110
    for filename in tiny_mce_dir.walkfiles():
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   111
        if '.svn' not in filename.splitall():
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   112
            # In this case, `tiny_mce/*` is in the root of the zip file, so
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   113
            # we do not need to prefix `arcname` with 'tinymce/' (like we did
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   114
            # with `django.zip`).
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   115
            paver.tasks.environment.info(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   116
                '%-4stiny_mce.zip <- %s', '', filename)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   117
            arcname = tiny_mce_dir.relpathto(filename)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   118
            yield filename, arcname
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   119
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   120
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   121
def write_zip_file(zip_file_handle, files):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   122
    if paver.tasks.environment.dry_run:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   123
        for args in files:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   124
            pass
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   125
        return
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   126
    zip_file = zipfile.ZipFile(zip_file_handle, mode='w')
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   127
    for args in files:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   128
        zip_file.write(*args)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   129
    zip_file.close()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   130
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   131
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   132
def symlink(target, link_name):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   133
    if hasattr(target, 'symlink'):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   134
        target.symlink(link_name)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   135
    else:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   136
        # If we are on a platform where symlinks are not supported (such as
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   137
        # Windows), simply copy the files across.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   138
        target.copy(link_name)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   139
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   140
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   141
# Tasks
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   142
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   143
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   144
@task
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   145
@cmdopts([
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   146
    ('app-folder=', 'a', 'App folder directory (default /app)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   147
    ('pylint-command=', 'c', 'Specify a custom pylint executable'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   148
    ('quiet', 'q', 'Disables a lot of the pylint output'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   149
    ('ignore', 'i', 'Ignore PyLint errors')
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   150
])
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   151
def pylint(options):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   152
    """Check the source code using PyLint."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   153
    from pylint import lint
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   154
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   155
    # Initial command.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   156
    arguments = []
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   157
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   158
    if options.quiet:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   159
        arguments.extend(options.quiet_args)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   160
    if 'pylint_args' in options:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   161
        arguments.extend(list(options.pylint_args))
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   162
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   163
    # Add the list of paths containing the modules to check using PyLint.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   164
    arguments.extend(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   165
        str(options.app_folder / module) for module in options.check_modules)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   166
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   167
    # By placing run_pylint into its own function, it allows us to do dry runs
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   168
    # without actually running PyLint.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   169
    def run_pylint():
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   170
        # Add app folder to path.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   171
        sys.path.insert(0, options.app_folder.abspath())
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   172
        # Add google_appengine directory to path.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   173
        sys.path.insert(0,
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   174
            options.project_dir.abspath() /
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   175
                'thirdparty' / 'google_appengine')
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   176
        
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   177
        # Specify PyLint RC file.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   178
        arguments.append('--rcfile=' +
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   179
            options.project_dir.abspath() /
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   180
                'scripts' / 'pylint' / 'pylintrc')
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   181
        
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   182
        # `lint.Run.__init__` runs the PyLint command.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   183
        try:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   184
            lint.Run(arguments)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   185
        # PyLint will `sys.exit()` when it has finished, so we need to catch
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   186
        # the exception and process it accordingly.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   187
        except SystemExit, exc:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   188
            return_code = exc.args[0]
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   189
            if return_code != 0 and (not options.pylint.ignore):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   190
                raise paver.tasks.BuildFailure(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   191
                    'PyLint finished with a non-zero exit code')
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   192
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   193
    return dry('pylint ' + ' '.join(arguments), run_pylint)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   194
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   195
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   196
@task
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   197
@cmdopts([
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   198
    ('app-build=', 'b', 'App build directory (default /build)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   199
    ('app-folder=', 'a', 'App folder directory (default /app)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   200
    ('skip-pylint', 's', 'Skip PyLint checker'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   201
    ('ignore-pylint', 'i', 'Ignore results of PyLint (but run it anyway)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   202
    ('quiet-pylint', 'q', 'Make PyLint run quietly'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   203
])
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   204
def build(options):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   205
    """Build the project."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   206
    # If `--skip-pylint` is not provided, run PyLint.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   207
    if not options.skip_pylint:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   208
        # If `--ignore-pylint` is provided, act as if `paver pylint --ignore`
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   209
        # was run. Likewise for `--quiet-pylint`.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   210
        if options.get('ignore_pylint', False):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   211
            options.pylint.ignore = True
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   212
        if options.get('quiet_pylint', False):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   213
            options.pylint.quiet = True
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   214
        pylint(options)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   215
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   216
    # Clean old generated zip files from the app folder.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   217
    clean_zip(options)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   218
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   219
    # Clean the App build directory by removing and re-creating it.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   220
    clean_build(options)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   221
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   222
    # Build the django.zip file.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   223
    django_zip(options)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   224
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   225
    # Build the tiny_mce.zip file.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   226
    tinymce_zip(options)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   227
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   228
    # Make the necessary symlinks between the app and build directories.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   229
    build_symlinks(options)
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   230
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   231
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   232
@task
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   233
@cmdopts([
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   234
    ('app-build=', 'b', 'App build directory (default /build)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   235
    ('app-folder=', 'a', 'App folder directory (default /app)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   236
])
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   237
def build_symlinks(options):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   238
    """Build symlinks between the app and build folders."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   239
    # Create the symbolic links from the app folder to the build folder.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   240
    for filename in options.app_files + options.app_dirs + options.zip_files:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   241
        # The `symlink()` function handles discrepancies between platforms.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   242
        target = path(options.app_folder) / filename
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   243
        link = path(options.app_build) / filename
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   244
        dry(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   245
            '%-4s%-20s <- %s' % ('', target, link),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   246
            lambda: symlink(target, link))
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   247
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   248
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   249
@task
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   250
@cmdopts([
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   251
    ('app-build=', 'b', 'App build directory (default /build)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   252
])
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   253
def clean_build(options):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   254
    """Clean the build folder."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   255
    # Not checking this could cause an error when trying to remove a
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   256
    # non-existent file.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   257
    if path(options.app_build).exists():
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   258
        path(options.app_build).rmtree()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   259
    path(options.app_build).makedirs()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   260
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   261
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   262
@task
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   263
@cmdopts([
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   264
    ('app-folder=', 'a', 'App folder directory (default /app)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   265
])
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   266
def clean_zip(options):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   267
    """Remove all the generated zip files from the app folder."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   268
    for zip_file in options.zip_files + ['django.zip']:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   269
        zip_path = path(options.app_folder) / zip_file
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   270
        if zip_path.exists():
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   271
            zip_path.remove()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   272
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   273
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   274
@task
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   275
@cmdopts([
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   276
    ('app-build=', 'b', 'App build directory (default /build)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   277
    ('app-folder=', 'a', 'App folder directory (default /app)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   278
])
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   279
def django_zip(options):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   280
    """Create the zip file containing Django (minus unwanted stuff)."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   281
    # Write the `django.zip` file. This requires finding all of the necessary
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   282
    # files and writing them to a `zipfile.ZipFile` instance. Python's
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   283
    # stdlib `zipfile` module is written in C, so it's fast and doesn't incur
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   284
    # much overhead.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   285
    django_src_dir = path(options.app_folder) / 'django'
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   286
    django_zip_filename = path(options.app_build) / 'django.zip'
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   287
    if paver.tasks.environment.dry_run:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   288
        django_zip_fp = StringIO()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   289
    else:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   290
        # Ensure the parent directories exist.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   291
        django_zip_filename.dirname().makedirs()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   292
        django_zip_fp = open(django_zip_filename, mode='w')
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   293
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   294
    # Write the zip file to disk; this uses the `write_zip_file()` function
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   295
    # defined above. The try/except/finally makes sure the `django.zip` file
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   296
    # handle is properly closed no matter what happens.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   297
    try:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   298
        write_zip_file(django_zip_fp, django_zip_files(django_src_dir))
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   299
    except Exception, exc:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   300
        # Close and delete the (possibly corrupted) `django.zip` file.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   301
        django_zip_fp.close()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   302
        django_zip_filename.remove()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   303
        # Raise the error, causing Paver to exit with a non-zero exit code.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   304
        raise paver.tasks.BuildFailure(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   305
            'Error occurred creating django.zip: %r' % (exc,))
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   306
    finally:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   307
        # Close the file handle if it isn't already.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   308
        if not django_zip_fp.closed:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   309
            django_zip_fp.close()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   310
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   311
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   312
@task
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   313
@cmdopts([
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   314
    ('app-folder=', 'a', 'App folder directory (default /app)'),
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   315
])
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   316
def tinymce_zip(options):
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   317
    """Create the zip file containing TinyMCE."""
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   318
    # This is very similar to django_zip; see the comments there for
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   319
    # explanations.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   320
    tinymce_dir = path(options.app_folder) / 'tiny_mce'
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   321
    tinymce_zip_filename = path(options.app_folder) / 'tiny_mce.zip'
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   322
    if paver.tasks.environment.dry_run:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   323
        tinymce_zip_fp = StringIO()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   324
    else:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   325
        # Ensure the parent directories exist.
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   326
        tinymce_zip_filename.dirname().makedirs()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   327
        tinymce_zip_fp = open(tinymce_zip_filename, mode='w')
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   328
    
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   329
    try:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   330
        write_zip_file(tinymce_zip_fp, tinymce_zip_files(tinymce_dir))
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   331
    except Exception, exc:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   332
        tinymce_zip_fp.close()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   333
        tinymce_zip_filename.remove()
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   334
        raise paver.tasks.BuildFailure(
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   335
            'Error occurred creating tinymce.zip: %r' % (exc,))
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   336
    finally:
eebf0c4ace3d Add paver script that will replace our current build.sh from scripts folder.
Zachary Voase <disturbyte@googlemail.com>
parents:
diff changeset
   337
        if not tinymce_zip_fp.closed:
2599
22e1ec7bd02a Add queue.yaml to build scripts.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2457
diff changeset
   338
            tinymce_zip_fp.close()