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)

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, limit=0)[source]

Return only one deepest dir from the path

Parameters:
  • path (str) – Path
  • full (bool) – Returns complete path or not
  • limit (int) – Limit deepest search to limit depth, default 0, no limit
Returns:

Directory name

Return type:

str

static get_deepest_dirs(path=None, full=False, limit=0)[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
  • limit (int) – Limit deepest search to limit depth, default 0, no limit
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, limit=0)[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 :param limit: Limit deepest search to limit depth, default 0, no limit :type limit: int :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 uprint(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

static user()[source]

Returns the current user running or using the script. Given by getpass.getuser()

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