pyyaks.context

Classes

class pyyaks.context.ContextValue(val=None, name=None, format=None, ext=None, parent=None)

Bases: object

Value with context that has a name and modification time.

Parameters:
  • val – initial value (optional)
  • name – context value name
  • basedir – root directory for a file context value
  • format – optional format specifier when rendering value
  • ext – extension to be added when rendering a file context value
abs

File context value as an absolute path or self._val if not a file

Basedir can have multiple base paths separated by ‘:’ like the linux PATH. The first base path for which the content file path exists is returned, or if none exist then the last absolute path will be returned.

clear()

Clear the value, modification time, and format (set to None)

mtime

Modification time

rel

File context value as a relative path or self._val if not a file.

Basedir can have multiple base paths separated by ‘:’ like the linux PATH. The first base path for which the content file path exists is returned, or if none exist then the last relative path will be returned.

val

Set or get with the val attribute

class pyyaks.context.ContextDict(*args, **kwargs)

Bases: dict

Dictionary class that automatically registers the dict in the module CONTEXT and overrides __setitem__ to create an appropriate ContextValue when assigning to a dict key. If no name is supplied then the ContextDict is not registered in the global CONTEXT.

Parameters:
  • name – name by which dictionary is registered in context.
  • basedir – base directory for file context
cache(func)

Decorator to cache this ContextDict object

clear()

Clear all values in dictionary. The keys are not deleted so that ContextValue references in task decorators maintain validity.

Functions

pyyaks.context.render(val)

Render val using the template engine and the current context.

Parameters:val – input value
Returns:rendered value
pyyaks.context.render_args(*argids)

Decorate a function so that the specified arguments are rendered via context.render() before being passed to function. Keyword arguments are unaffected.

Examples:

# Apply render() to all 3 args
@context.render_args()
def func(arg1, arg2, arg3):
    return arg1, arg2, arg3

# Render just arg1
@context.render_args(1)
def func(arg1, arg2, arg3):
    return arg1, arg2, arg3

# Render arg1 and arg3
@context.render_args(1, 3)
def func(arg1, arg2, arg3):
    return arg1, arg2, arg3
pyyaks.context.store_context(filename, keys=None)

Store the current context to filename.

Parameters:
  • filename – name of file for storing context
  • keys – list of keys in CONTEXT to store (default=None => all)
Return type:

None

pyyaks.context.update_context(filename, keys=None)

Update the current context from filename. This file should be created with store_context().

Parameters:
  • filename – name of file containing context
  • keys – list of keys in CONTEXT to update (default=None => all)
Return type:

None

Table Of Contents

Previous topic

Pyyaks

Next topic

pyyaks.fileutil

This Page