Staticky Environment

class staticky.StaticFiles(input, workdir=None, pathvar=None, manifest=None, index='index.html', meta_class='staticky.meta.sqlite:MetaData')

Create a StaticFiles object, which defines a staticky environment.

The location of source files indicated by input, and may either be a path, or a list of a paths. If a list is given, priority increases with later paths.

The staging area is specified by workdir, and if it is omitted or None, a temporary directory will be used that will be cleaned up on destruction of the object.

If manifest is provided, it controls what files are visible via open(), as_wsgi(), as_view() or install(), although install() can override the manifest specified here. For information on the expected format, see the Manifest documentation.

The index keyword, which defaults to “index.html” may be used to indicate which file should be used if a directory (with a trailing slash) is requested when using as_wsgi() or as_view().

as_view(request, path=None)

Call as a view, expecting a WebOb Request object request and returning a WebOb Response object.

as_wsgi(environ, start_response)

Call as a wsgi application.

The bound method may be passed to anything expecting a wsgi application, eg make_server('', 8080, staticfiles.as_wsgi).

cleanup()

Clean up any temporary files and closes any opened resources.

This method is automatically called on object destruction.

install(destdir, gzip=False, clean=False, include_post=True, manifest=None)

Copy the built tree of files to destdir. If a manifest provided here, or when the StaticFiles object was constructed, it will be used to control what files are actually copied over.

If the gzip flag is provided, then each files generated will also be gzip compressed with .gz appended to each filename.

If the clean flag is provided, then the destination directory will be wiped before installation occurs.

Any post-processing rules will be called, unless include_post is provided with a false value.

open(path, mode='r', force=False, include_post=False, job=None)

Opens a built file for reading or writing.

If the contents of a file are overwritten, changes are likely to be lost the next time the file is built, such as if modifications are detected in a source file.

register(rule, args={}, input=None, output=None)

Register a rule, where rule is either a callable or a string in form of MODULE:CLASS.

If rule is a string representing a class, then args will be passed to it when instantiated as keyword arguments, allowing for rule-specific configuration. It is expected that this class is itself callable, and will be called to build files the rule is register for.

If rule is already a callable, it will be used directly as the callable for building files. For more information about existing rules and the construction of new rules see the Rules documentation.

input and output are strings that describe what filenames the rule matches. The wildcard parts of the url are indicated using curly brackets (e.g. "{filename}.ext") and the matchable text can be changed by appending a colon and a regular expression (e.g. "{filename:[a-z]}.ext"). Wildcard names must be included in both the input and the output strings, as this determines how names are mapped. For example, if input is "{filename}.in" and output is "{filename}.out", a file named hello.out would be generated if a filename called hello.in is found.

register_post(rule, args={}, name='{f}', priority=0)

Register a post-processing rule, where rule follows the same form as used with register().

Unlike the register() method, the input and output are implicitly the same, and are specified via name, and the built file is a transformation of an existing file.

priority determines what order post-processing rules are evaluated in, so that multiple post-processing rules can be chained on files in a consistent order.