def _generate_assets(self,**options): filenames = [] media_target_dir = os.path.join(structure.TARGET_DIR,"mediasite") makedirs(os.path.join(media_target_dir,"css")) makedirs(os.path.join(media_target_dir,"js")) for d in listdir(structure.CSS_DIR): if os.path.splitext(d)[1] == ".css" and os.path.isdir(os.path.join(structure.CSS_DIR,d)): filenames.append(d) target = os.path.join(structure.MEDIASITE_DIRS[-1],"css",d) src = os.path.join(structure.CSS_DIR,d) sources = listdir(src,full_path=True,recursed=True) lines = combine_asset_sources(sources,structure.CSS_DIR,source_node=CssSourceNode) with open(os.path.join(media_target_dir, "css", d), 'w') as handle: handle.write(''.join(lines)) handle.flush() for d in listdir(structure.JS_DIR): if os.path.splitext(d)[1] == ".js" and os.path.isdir(os.path.join(structure.JS_DIR,d)): filenames.append(d) target = os.path.join(structure.MEDIASITE_DIRS[-1],"js",d) src = os.path.join(structure.JS_DIR,d) sources = listdir(src,full_path=True,recursed=True) lines = combine_asset_sources(sources,structure.JS_DIR,source_node=JsSourceNode) with open(os.path.join(media_target_dir, "js", d), 'w') as handle: handle.write(''.join(lines)) handle.flush() print "Generating", ' '.join(filenames), '->', media_target_dir
def load_template_source(template_name, template_dirs=None): tried = [] # css sources if template_name.startswith("css/"): src = safe_join(structure.CSS_DIR,template_name[4:]) target = safe_join(structure.MEDIASITE_DIRS[-1],"css",template_name[4:]) if isdir(src): if newer_assets(src,target): lines = combine_asset_sources(src,structure.CSS_DIR,source_node=CssSourceNode) with open(target,"w") as f: f.write(''.join(lines)) try: return (open(target).read().decode(settings.FILE_CHARSET), target) except IOError: tried.append(target) elif isfile(src): try: return (open(src).read().decode(settings.FILE_CHARSET), src) except IOError: tried.append(src) # js sources if template_name.startswith("js/"): src = safe_join(structure.JS_DIR,template_name[3:]) target = safe_join(structure.MEDIASITE_DIRS[-1],"js",template_name[3:]) if isdir(src): if newer_assets(src,target): lines = combine_asset_sources(src,structure.JS_DIR,source_node=JsSourceNode) with open(target,"w") as f: f.write(''.join(lines)) try: return (open(target).read().decode(settings.FILE_CHARSET), target) except IOError: tried.append(target) elif isfile(src): print src try: return (open(src).read().decode(settings.FILE_CHARSET), src) except IOError: tried.append(src) if tried: error_msg = "Tried %s" % tried else: error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory." raise TemplateDoesNotExist, error_msg