def less(path): logger.info("processing file %s" % path) full_path, file_name, output_dir = less_paths(path) base_file_name = os.path.splitext(file_name)[0] if LESS_DEVMODE and any(map(lambda watched_dir: full_path.startswith(watched_dir), LESS_DEVMODE_WATCH_DIRS)): return os.path.join(os.path.dirname(path), "%s.css" % base_file_name) hashed_mtime = get_hashed_mtime(full_path) output_file = "%s-%s.css" % (base_file_name, hashed_mtime) output_path = os.path.join(output_dir, output_file) encoded_full_path = full_path if isinstance(full_path, unicode): filesystem_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() encoded_full_path = full_path.encode(filesystem_encoding) if not os.path.exists(output_path): compile_less(encoded_full_path, output_path, path) # Remove old files compiled_filename = os.path.split(output_path)[-1] for filename in os.listdir(output_dir): if filename.startswith(base_file_name) and filename != compiled_filename: os.remove(os.path.join(output_dir, filename)) return os.path.join(LESS_OUTPUT_DIR, os.path.dirname(path), output_file)
def less(path): logger.info("processing file %s" % path) full_path, file_name, output_dir = less_paths(path) base_file_name = os.path.splitext(file_name)[0] if LESS_DEVMODE and any( map(lambda watched_dir: full_path.startswith(watched_dir), LESS_DEVMODE_WATCH_DIRS)): return os.path.join(os.path.dirname(path), "%s.css" % base_file_name) hashed_mtime = get_hashed_mtime(full_path) output_file = "%s-%s.css" % (base_file_name, hashed_mtime) output_path = os.path.join(output_dir, output_file) encoded_full_path = full_path if isinstance(full_path, unicode): filesystem_encoding = sys.getfilesystemencoding( ) or sys.getdefaultencoding() encoded_full_path = full_path.encode(filesystem_encoding) if not os.path.exists(output_path): compile_less(encoded_full_path, output_path, path) # Remove old files compiled_filename = os.path.split(output_path)[-1] for filename in os.listdir(output_dir): if filename.startswith( base_file_name) and filename != compiled_filename: os.remove(os.path.join(output_dir, filename)) return os.path.join(LESS_OUTPUT_DIR, os.path.dirname(path), output_file)
def daemon(): while True: to_be_compiled = set() for watched_dir in LESS_DEVMODE_WATCH_DIRS: for root, dirs, files in os.walk(watched_dir): for filename in filter(lambda f: f.endswith(".less"), files): filename = os.path.join(root, filename) f = os.path.relpath(filename, STATIC_ROOT) if f in LESS_DEVMODE_EXCLUDE: continue mtime = os.path.getmtime(filename) if f not in WATCHED_FILES: WATCHED_FILES[f] = [None, set()] if WATCHED_FILES[f][0] != mtime: WATCHED_FILES[f][0] = mtime # Look for @import statements to update dependecies for line in open(filename): for imported in LESS_IMPORT_RE.findall(line): imported = os.path.relpath( os.path.join(os.path.dirname(filename), imported), STATIC_ROOT) if imported not in WATCHED_FILES: WATCHED_FILES[imported] = [None, set([f])] else: WATCHED_FILES[imported][1].add(f) to_be_compiled.add(f) importers = WATCHED_FILES[f][1] while importers: for importer in importers: to_be_compiled.add(importer) importers = WATCHED_FILES[importer][1] for less_path in to_be_compiled: full_path = os.path.join(STATIC_ROOT, less_path) base_filename = os.path.split(less_path)[-1][:-5] output_directory = os.path.join(STATIC_ROOT, LESS_OUTPUT_DIR, os.path.dirname(less_path)) output_path = os.path.join(output_directory, "%s.css" % base_filename) if isinstance(full_path, unicode): filesystem_encoding = sys.getfilesystemencoding( ) or sys.getdefaultencoding() full_path = full_path.encode(filesystem_encoding) compile_less(full_path, output_path, less_path) logger.debug("Compiled: %s" % less_path) time.sleep(1)
def daemon(): while True: to_be_compiled = set() for watched_dir in LESS_DEVMODE_WATCH_DIRS: for root, dirs, files in os.walk(watched_dir): for filename in filter(lambda f: f.endswith(".less"), files): filename = os.path.join(root, filename) f = os.path.relpath(filename, STATIC_ROOT) if f in LESS_DEVMODE_EXCLUDE: continue mtime = os.path.getmtime(filename) if f not in WATCHED_FILES: WATCHED_FILES[f] = [None, set()] if WATCHED_FILES[f][0] != mtime: WATCHED_FILES[f][0] = mtime # Look for @import statements to update dependecies for line in open(filename): for imported in LESS_IMPORT_RE.findall(line): imported = os.path.relpath(os.path.join(os.path.dirname(filename), imported), STATIC_ROOT) if imported not in WATCHED_FILES: WATCHED_FILES[imported] = [None, set([f])] else: WATCHED_FILES[imported][1].add(f) to_be_compiled.add(f) importers = WATCHED_FILES[f][1] while importers: for importer in importers: to_be_compiled.add(importer) importers = WATCHED_FILES[importer][1] for less_path in to_be_compiled: full_path = os.path.join(STATIC_ROOT, less_path) base_filename = os.path.split(less_path)[-1][:-5] output_directory = os.path.join(STATIC_ROOT, LESS_OUTPUT_DIR, os.path.dirname(less_path)) output_path = os.path.join(output_directory, "%s.css" % base_filename) if isinstance(full_path, unicode): filesystem_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() full_path = full_path.encode(filesystem_encoding) compile_less(full_path, output_path, less_path) logger.debug("Compiled: %s" % less_path) time.sleep(1)