API Reference

spreads.plugin

class spreads.plugin.PluginOption(value, docstring=None, selectable=False)

A configuration option.

Attr value:The default value for the option or a list of available options if :attr selectable: is True
Attr docstring:A string explaining the configuration option
Attr selectable:
 Make the PluginOption a selectable, i.e. value contains a list or tuple of acceptable values for this option, with the first member being the default selection.
__init__(value, docstring=None, selectable=False)
class spreads.plugin.SpreadsPlugin(config)

Plugin base class.

classmethod configuration_template()

Allows a plugin to define its configuration keys.

The returned dictionary has to be flat (i.e. no nested dicts) and contain a PluginOption object for each key.

Example:

{
 'a_setting': PluginOption(value='default_value'),
 'another_setting': PluginOption(value=[1, 2, 3],
                                 docstring="A list of things"),
 # In this case, 'full-fat' would be the default value
 'milk': PluginOption(value=('full-fat', 'skim'),
                      docstring="Type of milk",
                      selectable=True),
}
Returns:dict with unicode: PluginOption(value, docstring, selection)
__init__(config)

Initialize the plugin.

Parameters:config (confit.ConfigView) – The global configuration object, by default only the section with plugin-specific values gets stored in the config attribute, if the plugin has a __name__ attribute.
class spreads.plugin.DevicePlugin(config, device)

Base class for devices.

Subclass to implement support for different devices.

features = ()

Tuple of DeviceFeatures constants that designate the features the device offers.

__init__(config, device)

Set connection information and other properties.

Parameters:
  • config (spreads.confit.ConfigView) – spreads configuration
  • device (usb.core.Device) – USB device to use for the object
set_target_page(target_page)

Set the device target page, if applicable.

Parameters:target_page (unicode in (u”odd”, u”even”)) – The target page
prepare_capture(path)

Prepare device for scanning.

What this means exactly is up to the implementation and the type, of device, usually it involves things like switching into record mode, path and applying all relevant settings.

Parameters:path (pathlib.Path) – Project base path
capture(path)

Capture a single image with the device.

Parameters:path (pathlib.Path) – Path for the image
class spreads.plugin.HookPlugin(config)

Add functionality to any of spreads’ commands by implementing one or more of the available hooks.

classmethod add_command_parser(rootparser)
Allows a plugin to register a new command with the command-line
parser. The subparser that is added to :param rootparser: should set the class’ __call__ method as the func (via set_defaults) that is executed when the subcommand is specified on the CLI.
Parameters:rootparser (argparse.ArgumentParser) – The root parser that this plugin should add a subparser to.
prepare_capture(devices, path)

Perform some action before capturing begins.

Parameters:
  • devices (list(DevicePlugin)) – The devices used for capturing
  • path (pathlib.Path) – Project path
capture(devices, path)

Perform some action after each successful capture.

Parameters:
  • devices (list(DevicePlugin)) – The devices used for capturing
  • path (pathlib.Path) – Project path
finish_capture(devices, path)

Perform some action after capturing has finished.

Parameters:
  • devices (list(DevicePlugin)) – The devices used for capturing
  • path (pathlib.Path) – Project path
process(path)
Perform one or more actions that either modify the captured images
or generate a different output.
Parameters:path (pathlib.Path) – Project path
output(path)

Assemble an output file from the postprocessed images.

Parameters:path (pathlib.Path) – Project path
__init__(config)

Initialize the plugin.

Parameters:config (confit.ConfigView) – The global configuration object, by default only the section with plugin-specific values gets stored in the config attribute, if the plugin has a __name__ attribute.
classmethod configuration_template()

Allows a plugin to define its configuration keys.

The returned dictionary has to be flat (i.e. no nested dicts) and contain a PluginOption object for each key.

Example:

{
 'a_setting': PluginOption(value='default_value'),
 'another_setting': PluginOption(value=[1, 2, 3],
                                 docstring="A list of things"),
 # In this case, 'full-fat' would be the default value
 'milk': PluginOption(value=('full-fat', 'skim'),
                      docstring="Type of milk",
                      selectable=True),
}
Returns:dict with unicode: PluginOption(value, docstring, selection)
spreads.plugin.get_devices(config)

Initialize configured devices.

spreads.plugin.get_relevant_extensions(plugin_manager, hooks)

Find all extensions that implement certain hooks.

Parameters:hooks (list(unicode)) – A list of hook method names
Returns:A generator that yields relevant extensions
Return type:generator(Extension)

spreads.util

Various utility functions.

spreads.util.find_in_path(name)

Find executable in $PATH.

Parameters:name (unicode) – name of the executable
Returns:bool – True if name is found or False
class spreads.util.abstractclassmethod(func)

New decorator class that implements the @abstractclassmethod decorator added in Python 3.3 for Python 2.7.

Kudos to http://stackoverflow.com/a/13640018/487903

__init__(func)
class spreads.util.ColourStreamHandler(stream=None)

A colorized output SteamHandler Kudos to Leigh MacDonald: http://leigh.cudd.li/article/Cross_Platform_Colorized_Logger_Output_Using_Pythons_logging_Module_And_Colorama

is_tty

Check if we are using a “real” TTY. If we are not using a TTY it means that the colour output should be disabled.

Returns:Using a TTY status
Return type:bool
Fork me on GitHub