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
clean_symlinks
(path=None, delete=False)[source]¶ 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: Returns: Number of cleaned/deleted link(s)
Return type: 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 –
-
static
get_broken_links
(path=None)[source]¶ 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: Returns: Directory name
Return type:
-
static
get_deepest_dirs
(path=None, full=False, limit=0)[source]¶ Get the last directories from a path
Parameters: Returns: List of directories
Return type: 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 usingUtils.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()
andtimer_stop()
for a newelapsed_time()
count
-
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: Returns: Formatted time to date
Return type:
-
static
uprint
(msg, to=<open file '<stdout>', mode 'w'>)[source]¶ Redefined print function to support python 2 and 3
Parameters: Returns: Message to print
Return type:
-
static
user
()[source]¶ Returns the current user running or using the script. Given by getpass.getuser()
Returns: User name Return type: str
-