mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Refactoring for compilestatic
This commit is contained in:
parent
79c769351d
commit
630fdf93a4
@ -28,45 +28,40 @@ import sass
|
|||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base 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":
|
|
||||||
to_compile.append(file)
|
|
||||||
|
|
||||||
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 compilescss(self, file):
|
||||||
|
print("compiling %s" % file)
|
||||||
|
with open(file, "r") as oldfile:
|
||||||
|
with open(file.replace('.scss', '.css'), "w") as newfile:
|
||||||
newfile.write(sass.compile(string=oldfile.read()))
|
newfile.write(sass.compile(string=oldfile.read()))
|
||||||
|
|
||||||
def removescss(self, folder):
|
def removescss(self, file):
|
||||||
to_remove = []
|
print("removing %s" % file)
|
||||||
for file in os.listdir(folder):
|
os.remove(file)
|
||||||
file = os.path.join(folder, file)
|
|
||||||
if os.path.isdir(file):
|
|
||||||
self.removescss(file)
|
|
||||||
else:
|
|
||||||
path, ext = os.path.splitext(file)
|
|
||||||
if ext == ".scss":
|
|
||||||
to_remove.append(file)
|
|
||||||
for f in to_remove:
|
|
||||||
print("removing %s" % f)
|
|
||||||
os.remove(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")
|
@ -1,7 +1,7 @@
|
|||||||
# -*- coding:utf-8 -*
|
# -*- coding:utf-8 -*
|
||||||
#
|
#
|
||||||
# Copyright 2016,2017
|
# Copyright 2016,2017
|
||||||
# - Skia <skia@libskia.so>
|
# - Sli <antoine@bartuccio.fr>
|
||||||
#
|
#
|
||||||
# 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,
|
||||||
# http://ae.utbm.fr.
|
# http://ae.utbm.fr.
|
||||||
|
Loading…
Reference in New Issue
Block a user