def __init__(self, conf, env, fname, *args): self.conf = conf self.env = env self.cname = self.__class__.__name__.lower() # common name self.name = fname self.args = args # precalculate __hash__ because we need it quite often in tree self.hv = helpers.hash( self.cname, tuple(self.args), self.version, self.priority, helpers.hash(self.uses), helpers.hash(self.conf.fetch(self.cname + '_')))
def content(self): """Returns the processed content. This one of the core functions of acrylamid: it compiles incrementally the filter chain using a tree representation and saves final output or intermediates to cache, so we can rapidly re-compile the whole content. The cache is rather dumb: Acrylamid can not determine wether it differs only in a single character. Thus, to minimize the overhead the cache object is zlib-compressed.""" # previous value pv = None # this is our cache filename path = hex(hash(self))[2:] # remove *all* intermediates when entry has been modified if self.lastmodified > cache.getmtime(path): cache.remove(path) # growing dependencies of the filter chain deps = [] for fxs in self.filters.iter(context=self.context): # extend dependencies deps.extend(fxs) # key where we save this filter chain key = hash(*deps) try: rv = cache.get(path, key) if rv is None: res = self.source if pv is None else pv for f in fxs: res = f.transform(res, self, *f.args) pv = cache.set(path, key, res) else: pv = rv except (IndexError, AttributeError): # jinja2 will ignore these Exceptions, better to catch them before traceback.print_exc(file=sys.stdout) return pv
def __init__(self, conf, env, fname, *args): self.conf = conf self.env = env self.name = fname self.args = args # precalculate __hash__ because we need it quite often in tree self.hv = helpers.hash(self.__class__.__name__, tuple(self.args), self.version, self.priority)
def generate(self, conf, env, data): tt = env.engine.fromfile(env, self.template) keyfunc = lambda k: () if '/:year' in self.path: keyfunc = lambda k: (k.year, ) if '/:month' in self.path: keyfunc = lambda k: (k.year, k.imonth) if '/:day' in self.path: keyfunc = lambda k: (k.year, k.imonth, k.iday) for next, curr, prev in neighborhood( groupby(data['entrylist'], keyfunc)): salt, group = '-'.join(str(i) for i in curr[0]), list(curr[1]) modified = memoize('archive-' + salt, hash(*group)) or any( e.modified for e in group) if prev: prev = link(u'/'.join('%02i' % i for i in prev[0]), expand(self.path, prev[1][0])) if next: next = link(u'/'.join('%02i' % i for i in next[0]), expand(self.path, next[1][0])) route = expand(self.path, group[0]) path = joinurl(conf['output_dir'], route) # an object storing year, zero-padded month and day as attributes (may be None) key = type( 'Archive', (object, ), dict( zip(('year', 'month', 'day'), map(lambda x: '%02i' % x if x else None, keyfunc(group[0])))))() if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip('archive', path) continue html = tt.render(conf=conf, env=union(env, entrylist=group, type='archive', prev=prev, curr=link(route), next=next, num_entries=len(group), route=route, archive=key)) yield html, path
def content(self): """Returns the processed content. This one of the core functions of acrylamid: it compiles incrementally the filter chain using a tree representation and saves final output or intermediates to cache, so we can rapidly re-compile the whole content. The cache is rather dumb: Acrylamid can not determine wether it differs only in a single character. Thus, to minimize the overhead the cache object is zlib-compressed.""" # previous value pv = None # this is our cache filename path = self.cachefilename # remove *all* intermediates when entry has been modified if cache.getmtime(path) > 0.0 and self.modified: cache.remove(path) if self.hasproperty('copy'): res = self.resources if res: # use ascii record separator between paths, ignore empty list cache.set(path, 'resources', '\x1e'.join(res)) # growing dependencies of the filter chain deps = [] for fxs in self.filters.iter(context=self.context): # extend dependencies deps.extend(fxs) # key where we save this filter chain key = hash(*deps) try: rv = cache.get(path, key) if rv is None: res = self.source if pv is None else pv for f in fxs: res = f.transform(res, self, *f.args) pv = cache.set(path, key, res) else: pv = rv except (IndexError, AttributeError): # jinja2 will ignore these Exceptions, better to catch them before traceback.print_exc(file=sys.stdout) return pv
def __init__(self, conf, meta): self.props = Metadata((k, v) for k, v in iteritems(conf) if k in ['author', 'lang', 'email', 'date_format', 'entry_permalink', 'page_permalink']) self.props.update(meta) self.type = meta.get('type', 'entry') # redirect singular -> plural for key, to in [('tag', 'tags'), ('filter', 'filters'), ('template', 'layout')]: if key in self.props: self.props.redirect(key, to) self.filters = self.props.get('filters', []) self.hashvalue = hash(self.filename, self.title, self.date.ctime())
def generate(self, conf, env, data): tt = env.engine.fromfile(env, self.template) keyfunc = lambda k: ( ) if '/:year' in self.path: keyfunc = lambda k: (k.year, ) if '/:month' in self.path: keyfunc = lambda k: (k.year, k.imonth) if '/:day' in self.path: keyfunc = lambda k: (k.year, k.imonth, k.iday) for next, curr, prev in neighborhood(groupby(data['entrylist'], keyfunc)): salt, group = '-'.join(str(i) for i in curr[0]), list(curr[1]) modified = memoize('archive-' + salt, hash(*group)) or any(e.modified for e in group) if prev: prev = link(u'/'.join('%02i' % i for i in prev[0]), expand(self.path, prev[1][0])) if next: next = link(u'/'.join('%02i' % i for i in next[0]), expand(self.path, next[1][0])) route = expand(self.path, group[0]) path = joinurl(conf['output_dir'], route) # an object storing year, zero-padded month and day as attributes (may be None) key = type('Archive', (object, ), dict(zip(('year', 'month', 'day'), map(lambda x: '%02i' % x if x else None, keyfunc(group[0])) )))() if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip('archive', path) continue html = tt.render(conf=conf, env=union(env, entrylist=group, type='archive', prev=prev, curr=link(route), next=next, num_entries=len(group), route=route, archive=key)) yield html, path
def __hash__(self): return hash(*self.lst)
def modified(self): return self.lastmodified > cache.getmtime(hex(hash(self))[2:])
def __hash__(self): return helpers.hash(self.name, self.path)