NReal Utilities

Provides additional system functions and logging functions

class nr_utils.ClickableLineEdit(value)
clicked
mousePressEvent(self, QMouseEvent)
class nr_utils.ComboBox(value)
showPopup(self)
showPopupRequested
class nr_utils.FileDialog(title=None, parent=None, *args, **kwargs)

A custom Qt File dialog supports picking muliple files and folders

accept(self)
closeEvent(self, QCloseEvent)
keyPressEvent(self, QKeyEvent)
class nr_utils.Info_Dialog(parent, title='Seneferu Notification...', msg='', buttons=['Confirm'], icon='Information', default_button=None, stay_on_top=False)
append_message(message)

Appends a new row the message table widget

Parameters:message
Returns:
button_clicked()
closeEvent(self, QCloseEvent)
exception nr_utils.InterpreterError
class nr_utils.TrackedTableWidget(*args, **kwargs)
initUI()
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
class nr_utils.bcolors
BOLD = '\x1b[1m'
ERROR = '\x1b[91m'
HEADER = '\x1b[95m'
INFO = '\x1b[92m'
OKBLUE = '\x1b[94m'
RESET = '\x1b[0m'
UNDERLINE = '\x1b[4m'
WARNING = '\x1b[93m'
nr_utils.bs_exec(cmd, bs_globals=None, bs_locals=None, description='source string', log_as='print')

python exec command with support of reporting stack trace information about the error codes and line numbers in respect to the given cmd or script

Parameters:
  • cmd – the script/cmd to be executed
  • bs_globals – usually globals()
  • bs_locals – usually locals()
  • description – describe the being executed command or the name of the script being executed
  • log_as – report error logs as ‘print’ by default, other alternatives are ‘bs_log’, ‘raise’ ‘raise’ will raise and interpreter error, while ‘print’ will do normal printing and ‘bs_log’ will print with colors (useful for terminal logging)
Returns:

success status, in addition to the printed error log

nr_utils.confirmDialog(parent, title, msg, buttons=['Confirm'], icon='Information', defaultTheme=False, as_modal=True)

Global Qt dialog supports adding any number of buttons

Parameters:
  • parent – the Parent Qt widget the dialog is called from
  • title
  • msg
  • buttons
  • icon
Returns:

text of the clicked button

nr_utils.copy(src, dst, symlinks=True, ignore=None, dst_isdir=True)

Similar to the system cp command where cp -r dir dst_dir -results->> dst_dir/dir

Parameters:
  • src
  • dst
  • symlinks
  • ignore
Returns:

nr_utils.fileDialog(title=None, parent=None)
nr_utils.gen_versioned_path(asset_path, context, version)

Returns the versioned path for the given asset_path/(sk, context, nreal_brain)

nr_utils.get_back_date(from_date, days_back, weekend_days=[5, 6])

Get the date before days_back of working days by ignoring the weekend days

Parameters:
  • from_date
  • days_back – number of days to add to from_date
  • weekend_days – 4: Fri, 5: Sat, 6: Sun
Returns:

datetime(to_date)

nr_utils.get_end_date(from_date, duration, weekend_days=[5, 6])

Get the end date after adding a given duration of working days by ignoring the weekend days

Parameters:
  • from_date
  • duration – number of days to add to from_date
  • weekend_days – 4: Fri, 5: Sat, 6: Sun
Returns:

datetime(to_date)

nr_utils.get_first_working_day(from_date, weekend_days=[5, 6])

Get the first working day, if the given date withing a weekend, the first working day will be returned, otherwise, the same given date

Parameters:
  • from_date
  • weekend_days – 4: Fri, 5: Sat, 6: Sun
Returns:

datetime(first_working_day)

nr_utils.get_project_config(config_type, project_code=None)

Parse any json config file under $NREAL_SENEFERU/config, and returns the dict of data ready

Parameters:
  • config_type – Any config file basename (like pipeline|workflow|applications|mime…etc)
  • project_code – if project code given, the config file basename will be reformatted as <config_type>_<project_code>.conf
Returns:

dict of the json.loads of <config_type>_<project_code>.conf, if not exists or project_code was not given,

then return the dict from the default <config_type>.conf (like workflow.conf|pipeline.conf)

nr_utils.get_version_from_filepath(filepath)

Returns the version of given asset filepath

Parameters:filepath
Returns:int(version) or 0 for versionless assets
nr_utils.get_versionless_path(asset_path)

Returns the versionless path for the given asset path using quick re substitution assuming the versioned path in one of the following formats

nr_utils.infoDialog(parent, title, msg, buttons=['Confirm'], icon='Information')

An advanced dialog supports adding any numbers of buttons and appending rows to a table widget as the text area

Parameters:
  • parent – widget parent
  • title – dialog title
  • msg – dialog message to append
  • buttons – list of buttons texts
  • icon – Information|Warning|Critical/Error
Returns:

the clicked button text

nr_utils.inputDialog(parent, title, msg, buttons=['OK', 'Cancel'], icon='Information', defaultTheme=False)

Global Qt dialog supports adding any number of buttons

Parameters:
  • parent – the Parent Qt widget the dialog is called from
  • title
  • msg
  • buttons – must be a list of two button texts
  • icon
  • input_title – optional title for the lineEdit input field
Returns:

text of the clicked button

nr_utils.jobSpooler(**kwargs)
nr_utils.list_dir_sequences(dirname, ext='.ext')

Collapse the files/sequences in the given director/ext as single hashed files if sequence, or the filename if not a sequence Supported sequence numbering format is currently restricted to be surrounded by dots .<pads>.

Parameters:
  • dirname – direname to scan
  • ext – extension WITH the DOT
Returns:

list of basename strings (collapsed) - (without the given dirname)

nr_utils.log(msg, to='print', type='info', log_file='')

prints/stdout colored log to terminal or writes log to given file

Parameters:
  • msg
  • to
  • type
  • log_file
Returns:

nr_utils.move(src, dst, merge_existing=False)

similar to system ‘mv -r’, note that the given src and dst should be a full_path-to->full_path when merge_existing is On, since in this case we will mv/rename on destination

Parameters:
  • src
  • dst
  • merge_existing – if dst dir doesn’t exist, it will be created, while if the dst dir exists then this operation will merge/overwrite from the files under src dir to the files inside the given existing dst dir instead of copying the whole src dir inside the dst dir
Returns:

this os.readlink() but also works for python 2 on windows in respect to unix symlinks

Parameters:link_path
Returns:actual file path
nr_utils.samefile(a, b)

on unix, this returns the result of os.path.samefile(), but since windows doesn’t have such method that respects unix symlinks on windows side, we simulate os.path.samefile() here

Parameters:
  • a – file path (can be a symlink path)
  • b – file path (can be a symlink path)
Returns:

bool

Creates unix symlinks on all platforms including windows

Parameters:
  • src – source file or folder
  • dst – destination file or folder
  • force – force overwriting destination links if exists
Returns:

None

nr_utils.working_days_count(from_date, to_date, weekend_days=[5, 6])

Takes two date (from and to) and returns the count of working days

Parameters:
  • from_date
  • to_date
  • weekend_days
Returns:

int count of working days between the two from/to datetime