synccompress.py 2 KB
Newer Older
1
from django.core.management.base import NoArgsCommand
2 3 4 5
from optparse import make_option

from django.conf import settings

6 7
class Command(NoArgsCommand):
    option_list = NoArgsCommand.option_list + (
8 9
        make_option('--force', action='store_true', default=False, help='Force update of all files, even if the source files are older than the current compressed file.'),
    )
10
    help = 'Updates and compresses CSS and JavsScript on-demand, without restarting Django'
11 12
    args = ''

13
    def handle_noargs(self, **options):
14 15 16 17 18 19 20
        
        force = options.get('force', False)
        verbosity = int(options.get('verbosity', 1))

        from compress.utils import needs_update, filter_css, filter_js

        for name, css in settings.COMPRESS_CSS.items():
21
            u, version = needs_update(css['output_filename'], css['source_filenames'])
22

23 24 25 26 27
            if (force or u) or verbosity >= 2:
                msg = 'CSS Group \'%s\'' % name
                print msg
                print len(msg) * '-'
                print "Version: %s" % version
28

29 30
            if force or u:
                filter_css(css, verbosity)
31

32 33
            if (force or u) or verbosity >= 2:
                print
34 35

        for name, js in settings.COMPRESS_JS.items():
36
            u, version = needs_update(js['output_filename'], js['source_filenames'])
37

38 39 40 41 42
            if (force or u) or verbosity >= 2:
                msg = 'JavaScript Group \'%s\'' % name
                print msg
                print len(msg) * '-'
                print "Version: %s" % version
43

44 45
            if force or u:
                filter_js(js, verbosity)
46

47
            if (force or u) or verbosity >= 2:
48 49 50 51 52 53 54 55 56
                print

# Backwards compatibility for Django r9110
if not [opt for opt in Command.option_list if opt.dest=='verbosity']:
    Command.option_list += (
    make_option('--verbosity', '-v', action="store", dest="verbosity",
        default='1', type='choice', choices=['0', '1', '2'],
        help="Verbosity level; 0=minimal output, 1=normal output, 2=all output"),
    )