Source documentation

Warning

Python API is far from being “frozen”, use it with zero backwards-compatibility in mind. You are welcome to report suggestions to bug tracker.

mrbob – Main package

mrbob.configurator – Machinery to figure out configuration

exception mrbob.configurator.ConfigurationError[source]

Bases: mrbob.configurator.MrBobError

Raised during configuration phase

class mrbob.configurator.Configurator(template, target_directory, bobconfig=None, variables=None, defaults=None)[source]

Bases: object

Controller that figures out settings, asks questions and renders the directory structure.

Parameters:
  • template – Template name
  • target_directory – Filesystem path to a output directory
  • bobconfig – Configuration for mr.bob behaviour
  • variables – Given variables to questions
  • defaults – Overriden defaults of the questions

Additional to above settings, Configurator exposes following attributes:

  • template_dir is root directory of the template
  • is_tempdir if template directory is temporary (when using zipfile)
  • templateconfig dictionary parsed from template section
  • questions ordered list of `Question instances to be asked
  • bobconfig dictionary parsed from mrbob section of the config
ask_questions()[source]

Loops through questions and asks for input if variable is not yet set.

render()[source]

Render file structure given instance configuration. Basically calls mrbob.rendering.render_structure().

exception mrbob.configurator.MrBobError[source]

Bases: exceptions.Exception

Base class for errors

class mrbob.configurator.Question(name, question, default=None, required=False, command_prompt=<built-in function raw_input>, pre_ask_question='', post_ask_question='', help='', **extra)[source]

Bases: object

Question configuration. Parameters are used to configure questioning and possible validation of the answer.

Parameters:
  • name – Unique, namespaced name of the question
  • question – Question to be asked
  • default – Default value of the question
  • required (bool) – Is question required?
  • command_prompt – Function to executed to ask the question given question text
  • help – Optional help message
  • pre_ask_question – Space limited functions in dotted notation to ask before the question is asked
  • post_ask_question – Space limited functions in dotted notation to ask aster the question is asked
  • **extra

    Any extra parameters stored for possible extending of Question functionality

Any of above parameters can be accessed as an attribute of Question instance.

ask(configurator)[source]

Eventually, ask the question.

Parameters:configuratormrbob.configurator.Configurator instance
exception mrbob.configurator.SkipQuestion[source]

Bases: mrbob.configurator.MrBobError

Raised during pre_ask_question if we should skip it

exception mrbob.configurator.TemplateConfigurationError[source]

Bases: mrbob.configurator.ConfigurationError

Raised reading template configuration

exception mrbob.configurator.ValidationError[source]

Bases: mrbob.configurator.MrBobError

Raised during question validation

mrbob.configurator.parse_template(template_name)[source]

Resolve template name into absolute path to the template and boolean if absolute path is temporary directory.

mrbob.cli – Command line interface

Command line interface to mr.bob

mrbob.cli.main(args=['-E', '-b', 'html', '.', '_build/html'])[source]

Main function called by mrbob command.

mrbob.parsing – Parsing .ini files

mrbob.rendering – Everything related to rendering templates and directory structure

mrbob.rendering.render_structure(fs_source_root, fs_target_root, variables, verbose, renderer)[source]

Recursively copies the given filesystem path fs_source_root_ to a target directory `fs_target_root.

Any files ending in .bob are rendered as templates using the given renderer using the variables dictionary, thereby losing the .bob suffix.

strings wrapped in + signs in file- or directory names will be replaced with values from the variables, i.e. a file named +name+.py.bob given a dictionary {‘name’: ‘bar’} would be rendered as bar.py.

mrbob.hooks – Included hooks

Use any of hooks below or write your own. You are welcome to contribute them!

mrbob.hooks.show_message(configurator)[source]

If you want to display a message to the user when rendering is complete, you can use this function as Post render hook:

[template]
post_render = mrbob.hooks:show_message
message = Well done, %(author.name)s, your code is ready!

As shown above, you can use standard Python formatting in post_render_msg.

mrbob.hooks.to_boolean(configurator, question, answer)[source]

If you want to convert an answer to Python boolean, you can use this function as Post question hook:

[questions]
idiot.question = Are you young?
idiot.post_ask_question = mrbob.hooks:to_boolean

Following variables can be converted to a boolean: y, n, yes, no, true, false, 1, 0