def getSource(self, file_name): from fs.dependency import changed_since, newer_group src = join(structure.CSS_DIR,file_name) if not isdir(src): raise tornado.web.HTTPError(404) target = join(self.application.site["target_path"],"css",file_name) text = None srcs = [] srcs = fs.listdir(structure.CSS_DIR,recursed=True,full_path=True) #TODO record dependency with target if newer_group(srcs,target) or self.request.headers.get("force",False): lines = combine_asset_sources(src,structure.CSS_DIR,source_node=CssSourceNode) import codecs with codecs.open(target,"w",encoding="utf-8") as f: text = u''.join(lines) f.write(text) f.flush() if not text: with open(target,"r") as f: text = f.read() return text
def newer_assets(src,target,source_node=SourceNode): """ Are files needed to produce target path, found in the directory src path, newer in src path than target path.""" sources = source_node.list_dependencies(src) return newer_group(sources,target)