def generate_css_file(self, force, name, input_file, output_file, **kwargs): # check that the sass input file actually exists. if not os.path.exists(input_file): raise SassConfigException('The input \'%s\' does not exist.\n' %input_file) output_path = output_file.rsplit('/', 1)[0] if not os.path.exists(output_path): # try to create path try: os.mkdirs(output_path, 0o644) except os.error as e: raise SassConfigException(e.message) except AttributeError as e: # we have an older version of python that doesn't support os.mkdirs - fail gracefully. raise SassConfigException("Output path does not exist - please create manually: %s\n" % output_path) try: sass_obj = SassModel.objects.get(name=name) was_created = False except SassModel.DoesNotExist: sass_obj = SassModel(name=name) was_created = True sass_obj.sass_path = input_file sass_obj.css_path = output_file needs_update = was_created or force or update_needed(sass_obj) if needs_update: sass_dict = { 'bin' : self.bin, 'sass_style' : self.sass_style, 'input' : input_file, 'output' : output_file } cmd = "%(bin)s -t %(sass_style)s -C %(input)s > %(output)s" %sass_dict p = subprocess.Popen([self.bin, "-t", self.sass_style, "--no-cache", input_file, output_file]) stdout, stderr = p.communicate() if p.returncode != 0: # Process failed (nonzero exit code) raise SassException(stderr) sass_obj.save()
def list(self): """ We check to see if the Sass outlined in the SASS setting are different from what the databse has stored. We only care about listing those files that are in the SASS setting. Ignore the settings in the DB if the files/settings have been removed. """ # process the Sass information in the settings. sass_definitions = self.get_sass_definitions() for sass_def in sass_definitions: print "[%s]" % sass_def['name'] try: sass_obj = SassModel.objects.get(name=sass_def['name']) sass_obj.sass_path = sass_def['input_file'] sass_obj.css_path = sass_def['output_file'] was_created = False except SassModel.DoesNotExist: sass_obj = SassModel(name=sass_def['name']) was_created = True needs_update = was_created or update_needed(sass_obj) if needs_update: print "\tChanges detected."
raise SassConfigException(e.message) except AttributeError, e: # we have an older version of python that doesn't support os.mkdirs - fail gracefully. raise SassConfigException('Output path does not exist - please create manually: %s\n' %output_path) try: sass_obj = SassModel.objects.get(name=name) was_created = False except SassModel.DoesNotExist: sass_obj = SassModel(name=name) was_created = True sass_obj.sass_path = input_file sass_obj.css_path = output_file needs_update = was_created or force or update_needed(sass_obj) if needs_update: sass_dict = { 'bin' : self.bin, 'sass_style' : self.sass_style, 'input' : input_file, 'output' : output_file } cmd = "%(bin)s -t %(sass_style)s -C %(input)s > %(output)s" %sass_dict (status, output) = getstatusoutput(cmd) if not status == 0: raise SassException(output) sass_obj.save() def clean(self): for s in SassModel.objects.all(): try: print "Removing css: %s" % s.css_path os.remove(s.css_path) s.delete()