Welcome to BioMAJ Manager’s documentation!

Contents:

decorators API reference

Global decorators for BioMAJ Manager

biomajmanager.decorators.bank_required(func)[source]

Decorator function that checks a bank name is set

Parameters:func (Function) – Decorated function
Returns:Result of function called
Return type:func
Raises:SystemExit – If no bank set
biomajmanager.decorators.deprecated(func)[source]

This is a decorator which can be used to mark functions as deprecated.

It will result in a warning being emitted when the functionis used.

Parameters:func (Function) – Decorated function
Returns:Result of functio called
Return type:func
biomajmanager.decorators.user_granted(func)[source]

Decorator function that checks a user has enough right to perform action

Parameters:func (Function) – Decorated function
Returns:Result of function called
Return type:func
Raises:SystemExit – If no owner found either in bank nor in config file

manager API reference

Manager.SAVE_BANK_LINE_PATTERN: Print pattern (str), %-20s\t%-30s\t%-20s\t%-20s\t%-20s\n
Manager.simulate: Simulate mode (bool), False
Manager.verbose: Verbose mode (bool), False

news API reference

News.MAX_NEWS: Maximum number of news returned while reading news directory (int), 5

plugins API reference

Plugins mechanism to load user defined method

class biomajmanager.plugins.BMPlugin[source]

Base plugin class for BioMAJ manager

get_config()[source]

Get the BioMAJ manager config as object

Returns:configparser instance
Return type::class:’configparser`
get_manager()[source]

Get the BioMAJ manager instance

Returns:Manager
Return type:biomaj.manager.Manager
get_name()[source]

Get the name of the plugin. Based on the class name

set_config(config)[source]

Set BioMAJ manager config object

set_manager(manager)[source]

Set BioMAJ manager config object

class biomajmanager.plugins.Plugins(manager=None, name=None)[source]

Plugin class for BioMAJ Manager

__init__(manager=None, name=None)[source]

Create the plugin object

Parameters:
  • manager (biomajmanager.manager.Manager) – Manager instance
  • name (String) – Name of the plugin to load. [DEFAULT: load all plugins]
Raises:
  • SystemExit – If ‘manager’ arg is not given
  • SystemExit – If ‘PLUGINS’ section not found in manager.properties
  • SystemExit – If ‘plugins.dir’ not set in manager.properties
  • SystemExit – If ‘plugins.list’ not set in manager.properties
  • SystemExit – If ‘plugins.dir’ does not exist
__weakref__

list of weak references to the object (if defined)

utils API reference

Utils.DATE_FMT: date format pattern (str), %Y-%m-%d %H:%M:%S
Utils.show_warn: show warnings mesasge (bool), True
Utils.show_debug: show debug message (bool), True
Utils.show_verbose: show verbose message (bool), True
Utils.timer_start: Start timer value (float), 0.0
Utils.timer_stop: Stop timer value (float), 0.0

Utilities class for BioMAJ Manager

class biomajmanager.utils.Utils[source]

Utility class

__weakref__

list of weak references to the object (if defined)

static _print(msg, to=<open file '<stdout>', mode 'w'>)[source]

Redefined print function to support python 2 and 3

Parameters:
  • msg (str) – Message to print
  • to (file) – File handle
Returns:

Message to print

Return type:

str

Search for broken symlinks.

Given a path, it search for all symlinks ‘path’ directory and remove broken symlinks. If delete is True, remove broken symlink(s), otherwise lists broken symlinks.

Parameters:
  • path (str) – Path to search symlinks from
  • delete (bool) – Wether to delete or not broken symlink(s)
Returns:

Number of cleaned/deleted link(s)

Return type:

int

Raises:
  • SystemExit – If path not found, or not given
  • SystemExit – If remove of symlink(s) failed
static elapsed_time()[source]

Get the elapsed time between start and stop timer.

Stop timer call is not required. If not set, it is automatically called as soon as the method is called

Returns:Elapsed time
Return type:float
Raises:SystemExit – If Utils.timer_start is not defined
static error(msg)[source]

Prints error message on STDERR and exits with exit code 1

Parameters:msg (str) – Message to print
Returns:Error message
Return type:str
Raises:SystemExit

Search for broken symlinks from a particular path.

If path is not given or None, then it search from the production directory.

Parameters:path (str) – Path to search broken links from
Returns:Number of found broekn links
Return type:int
Raises:SystemExit – If path does not exist
static get_deepest_dir(path=None, full=False)[source]

Return only one deepest dir from the path

Parameters:
  • path (str) – Path
  • full (bool) – Returns complete path or not
Returns:

Directory name

Return type:

str

static get_deepest_dirs(path=None, full=False)[source]

Get the last directories from a path

Parameters:
  • path (str) – Path to start from
  • full (bool) – Get the full path otherwise the directory only
Returns:

List of directories

Return type:

list

Raises:

SystemExit – If ‘path’ not given or does not exist

static get_files(path=None)[source]

Return the list of file(s) found for a given path

Parameters:path (str) – Path to search from
Returns:List of file(s) found
Return type:list
Raises:SystemExit – If path does not exist
static get_now()[source]

Get current time from time.time formatted using Utils.DATE_FMT

Returns:Current time formatted using Utils.DATE_FMT
Return type:time.time
static get_subtree(path=None)[source]

Get the subtree structure from a root path

E.g.: File system is /t/a1/a2/a3, get_subtree(path=’/t’) -> /a1/a2/a3 :param path: Root path to get subtree structure from :type path: str :return: List of found subtree :rtype: list

static ok(msg)[source]

Prints a [OK] msg

Parameters:msg (str) – Message to print
Returns:Message to print
Return type:str
static reset_timer()[source]

Reset to 0.0 timer_start() and timer_stop() for a new elapsed_time() count

static start_timer()[source]

Set current time at function call

static stop_timer()[source]

Set current time at function call

static time2date(otime)[source]

Convert a timestamp into a datetime object

Parameters:otime (time) – Timestamp to convert
Returns:Formatted time to date
Return type:datetime.datetime
static time2datefmt(otime, fmt='%Y-%m-%d %H:%M:%S')[source]

Converts a timestamp into a date following the format fmt, default to Utils.DATE_FMT

Parameters:
  • otime (time) – Timestamp to convert
  • fmt (str) – Date format to follow for conversion
Returns:

Formatted time to date

Return type:

datetime.datetime

static user()[source]

Returns the current user running or using the script. Taken from os.env

Returns:User name
Return type:str
static verbose(msg)[source]

Prints verbose message. Requires Manager.verbose to be True

Parameters:msg (str) – Verbose message to print
Returns:Verbose message
Return type:str
static warn(msg)[source]

Prints warning message. Required Utils.show_warn to be set to True

Parameters:msg (str) – Warning message to print
Returns:Warning message
Return type:str

writer API reference

Writer class to be used with Jinja2 templates

class biomajmanager.writer.Writer(template_dir=None, config=None, output=None)[source]

Writer class for BioMAJ manager to create what’s desired as output

__init__(template_dir=None, config=None, output=None)[source]

Create Writer object

Parameters:
  • template_dir (str) – Root directory where to find templates
  • config (configparser) – Global configuration file from BiomajConfig
  • output (str) – Output file. Default STDOUT
Raises:
  • SystemExit – If ‘template_dir’ is not given
  • SystemExit – If ‘MANAGER’ section not found in manager.properties
  • SystemExit – If ‘template.dir’ not set in manager.properties
__weakref__

list of weak references to the object (if defined)

write(template=None, data=None)[source]

Print template ‘data’ to stdout using template file ‘template’.

‘data’ arg can be left None, this way method can be used to render file from scratch

Parameters:
  • template (str) – Template file name
  • data (dict) – Template data
Returns:

True, throws on error

Return type:

bool

Raises:
  • SystemExit – If ‘template’ is None
  • SystemExit – If ‘template’ is not found
  • SystemExit – If ‘template’ has a syntax error in it
  • SystemExit – If ‘output’ file cannot be opened

Indices and tables