Public Methods
The primary public method is the load
method which loads the
attribute definitions from YAML file located in the directory tree.
Other methods are exported, and are documented here, but it is expected
that these methods are only used by the management commands.
add_attributes
Function
- django_yamlconf.add_attributes(settings, attributes, source)
Add a set of name value pairs to the set of attributes, e.g., attributes defined on the command line for management commands. Since this occurs after Django has loaded the settings, this function does not, in general, change behaviour of Django. It is used to add attribute definitions from management command lines. While this does not impact the behaviour of Django, it does make the attributes available for use in templates for the
ycsysfiles
command.- Parameters:
settings – the Django settings module
attributes – the dictionary of name/values pairs to add
source – the name for the source (displayed by
ycexplain
)
- Returns:
None
defined_attributes
Function
- django_yamlconf.defined_attributes(settings=None, template_use=False)
Return a dictionary giving attribute names and associated values. This dictionary can be used as the variables when rendering templates. This is the set attributed used used as the variables when rendering templates for the
ycsysfiles
command.- Parameters:
settings – the Django settings module (this is optional, defaults to the settings modules used when loading)
template_use – If the the set of attributes return needs to be used to process a template, in the dictionary returned, attribute keys are added for dictionary parents e.g., “DATABASES”, if “DATABASES.default…” is a YAMLCONF defined attribute. The usage without this option support the yclist management command.
- Returns:
a dictionary giving attribute names and associated values.
- Return type:
dict
explain
Function
- django_yamlconf.explain(name, settings=None, stream=None)
Explain the source for an attribute definition including sources that were eclipsed by higher level YAML definition files. If the attribute has associated documentation, it is also printed.
This routine is only used by the YAMLCONF management command
ycexplain
.- Parameters:
name – the YAMLCONF controlled setting name
settings – the Django settings module
stream – the stream to write the explanation text (defaults to
sys.stdout
)
- Returns:
None
list_attrs
Function
- django_yamlconf.list_attrs(settings=None, stream=None)
Write a list of attributes managed by YAMLCONF to the given stream (defaults to
sys.stdout
). Additional information can be printed using theexplain
routine.This routine is only used by the YAMLCONF management command
yclist
.- Parameters:
settings – the Django settings module
stream – the stream to write the list text
- Returns:
None
load
Function
- django_yamlconf.load(syntax='yaml', settings=None, base_dir=None, project=None)
Load the set of YAML files for a Django project. The simplest usage is to call this at the end of a settings file. In this context, no arguments are needed.
- Parameters:
syntax – The “syntax” parameter should name a Python module with a “load” method, e.g., the default is “yaml.load”. Other possibiliities could be “json” to use JSON formatted file or, even, “pickle” but that would be strange. The “syntax” name is also used as the file extension for the YAMLCONF files.
settings – The “settings” should be module containing the Django settings. This is determined from the call stack if no module is given.
base_dir – The “base_dir” defines the starting directory for YAMLCONF files and defaults to the directory containing the settings module.
project – The “project” is the name of the Django project and defaults to the name of the directory containing the settings modules.
- Returns:
None
sysfiles
Function
- django_yamlconf.sysfiles(create, noop, settings, rootdir='', render=None)
Traverse the sys templates directory expanding files to the destination directory.
- Parameters:
create – the template files should be created, normally will only update files that already exist on the system and are writable.
noop – no-op mode, print what would be done.
settings – the Django settings module
rootdir – the directory to create the system files, defaults to
/
, i.e., the root file system.render – the rendering engine, if not given, defaults to Django’s
render_to_string
- Returns:
None