Commit 630fdf93 authored by Sli's avatar Sli

Refactoring for compilestatic

parent 79c76935
...@@ -28,45 +28,40 @@ import sass ...@@ -28,45 +28,40 @@ import sass
from import BaseCommand from import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):
help = "Comile scss files from static folder" help = "Compile scss files from static folder"
def compilescss(self, folder): def is_compilable(self, file, ext_list):
to_compile = [] path, ext = os.path.splitext(file)
return ext in ext_list
def exec_on_folder(self, folder, func):
to_exec = []
for file in os.listdir(folder): for file in os.listdir(folder):
file = os.path.join(folder, file) file = os.path.join(folder, file)
if os.path.isdir(file): if os.path.isdir(file):
self.compilescss(file) self.exec_on_folder(file, func)
else: elif self.is_compilable(file, ['.scss']):
path, ext = os.path.splitext(file) to_exec.append(file)
if ext == ".scss":
for f in to_compile: for file in to_exec:
print("compilling %s" % f) func(file)
with open(f, "r") as oldfile:
with open(f.replace('.scss', '.css'), "w") as newfile:
def removescss(self, folder): def compilescss(self, file):
to_remove = [] print("compiling %s" % file)
for file in os.listdir(folder): with open(file, "r") as oldfile:
file = os.path.join(folder, file) with open(file.replace('.scss', '.css'), "w") as newfile:
if os.path.isdir(file): newfile.write(sass.compile(
else: def removescss(self, file):
path, ext = os.path.splitext(file) print("removing %s" % file)
if ext == ".scss": os.remove(file)
for f in to_remove:
print("removing %s" % f)
def handle(self, *args, **options): def handle(self, *args, **options):
if 'static' in os.listdir(): if 'static' in os.listdir():
print("---- Compilling scss files ---") print("---- Compiling scss files ---")
self.compilescss('static') self.exec_on_folder('static', self.compilescss)
print("---- Removing scss files ----") print("---- Removing scss files ----")
self.removescss('static') self.exec_on_folder('static', self.removescss)
else: else:
print("No static folder avaliable, please use collectstatic before compilling scss") print("No static folder avalaible, please use collectstatic before compiling scss")
\ No newline at end of file \ No newline at end of file
# -*- coding:utf-8 -* # -*- coding:utf-8 -*
# #
# Copyright 2016,2017 # Copyright 2016,2017
# - Skia <> # - Sli <>
# #
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, # Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# #
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment