Last active
August 29, 2015 14:02
-
-
Save honi/a1495a432d4d31140758 to your computer and use it in GitHub Desktop.
Hack for django-compressor to recompile less files when imported less files (not referenced in html) are changed. See: https://github.com/django-compressor/django-compressor/issues/226
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from subprocess import call | |
from os.path import join | |
from django.conf import settings | |
from django.core.management.base import BaseCommand | |
from watchdog.observers import Observer | |
from watchdog.events import PatternMatchingEventHandler | |
MAIN_LESS_FILE = join(settings.STATICFILES_DIRS[0], 'css/styles.less') | |
class EventHandler(PatternMatchingEventHandler): | |
def on_any_event(self, event): | |
print '[%s] Touching styles.less' % int(time.time()) | |
call(['touch', MAIN_LESS_FILE]) | |
class Command(BaseCommand): | |
help = 'Touch main less file when any other less file is modified.' | |
def handle(self, *args, **options): | |
self.stdout.write('Watching less file changes...') | |
event_handler = EventHandler(patterns=['*.less'], ignore_patterns=['*styles.less'], ignore_directories=True) | |
observer = Observer() | |
observer.schedule(event_handler, settings.DJANGO_ROOT, recursive=True) | |
observer.start() | |
try: | |
while True: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
observer.stop() | |
observer.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment