Embedded Python Real-Time FrameWork : API  Build 20250616.1
 All Classes Namespaces Files Functions Variables Pages
pyRT.gatea.sys.GLcommon Namespace Reference

Commonly used routines. More...

Classes

class  Binding
 A collection of event handler functions and methods to Bind() and Unbind() the handlers to a particular event. More...
 
class  DSTCalendar
 DST Calendar as list of [ UnixTime, gmt_offset ] tuples. More...
 
class  GLelapsed
 Calculates the time elapsed in millis. More...
 

Functions

def AddDict
 Add dict d2 to d1. More...
 
def CallStack
 Debugging : Dump Call Stack to list using traceback. More...
 
def CallStack2
 Debugging : Dump Call Stack to list using inspect. More...
 
def CpuTime
 Return amount of CPU time used by process. More...
 
def CurrentThreadID
 Return current thread ID. More...
 
def DateTime
 Return string-ified time as YYYY-MM-DD HH:MM:SS. More...
 
def DateTimeMs
 Return string-ified time as YYYY-MM-DD HH:MM:SS.mmm. More...
 
def DateTimeUs
 Return string-ified time as YYYY-MM-DD HH:MM:SS.uuuuuu. More...
 
def FmtIntToSize
 Formats integer quantities to user-defined lengths, appending K, G, T. More...
 
def FmtQty
 Formats quantities into readable comma-separated thousands, hundreds, etc. More...
 
def GetIdx
 Return a process-wide unique index. More...
 
def HexDump
 Return hexDump of binary message. More...
 
def InRange
 Return True if b is in the closed interval between a and c inclusive. More...
 
def IsNone
 Return True if 'v' is None. More...
 
def IsPY3
 Return True if Python 3.x. More...
 
def LOG
 Log a message Log a message in log file and optionally Console. More...
 
def MicroTime
 Returns time.clock() if WIN32 and _bWin32Clock is True; time.time() if not. More...
 
def ProgressBar
 
def PyClock
 PyVer-agnostic time.clock() More...
 
def ReadFile
 Open and read file as ASCII. More...
 
def RollLogFile
 Roll the log file. More...
 
def SetDriftPerHr
 Set drift / hour to MicroTime() clock to compenstate for drifting time.clock() More...
 
def SetLog
 Initialize Global Log File. More...
 
def Str2HMS
 Break HH:MM:SS string into [ h, m, s ]. More...
 
def Str2Time
 Convert string-ified YYYY-MM-DD HH:MM:SS.mmm to Unix Time. More...
 
def Str2Time_OBSOLETE
 
def SubDict
 Subtract dict d2 from d1. More...
 
def Time
 Return string-ified time as HH:MM:SS. More...
 
def Time2Mark
 Return millis to user-supplied HH:MM:SS. More...
 
def TimeMs
 Return string-ified time as HH:MM:SS.mmm. More...
 
def TimeUs
 Return string-ified time as HH:MM:SS.uuuuuu. More...
 
def tStart
 Returns ntp-anchroed time used for basis of MicroTime() clock. More...
 
def uDrift
 Returns current calculated drift in MicroTime() clock. More...
 
def uDriftPerSec
 Returns current calculated drift / sec from MicroTime() clock. More...
 
def WithinRange
 Ensure b is in the closed interval between a and c inclusive. More...
 
def Xdefaults
 Parse .Xdefaults type config file. More...
 

Detailed Description

Commonly used routines.

Function Documentation

def pyRT.gatea.sys.GLcommon.AddDict (   d1,
  d2,
  bInclZero = True 
)

Add dict d2 to d1.

Parameters
d1- Operand dict 1
d2- Operand dict 2
bInclZero- Allow zero values; Default is True
Returns
d1 + d2
def pyRT.gatea.sys.GLcommon.CallStack ( )

Debugging : Dump Call Stack to list using traceback.

Returns
Call stack as list
def pyRT.gatea.sys.GLcommon.CallStack2 ( )

Debugging : Dump Call Stack to list using inspect.

Returns
Call stack as list
def pyRT.gatea.sys.GLcommon.CpuTime ( )

Return amount of CPU time used by process.

Returns
Amount of CPU time used by process
def pyRT.gatea.sys.GLcommon.CurrentThreadID ( )

Return current thread ID.

Returns
current thread ID
def pyRT.gatea.sys.GLcommon.DateTime (   t = None,
  bGMT = False,
  bToday = False 
)

Return string-ified time as YYYY-MM-DD HH:MM:SS.

bToday t Description
True Today TODAY HH:MM:SS
True Not Today YYYY-MM-DD HH:MM:SS
False Any YYYY-MM-DD HH:MM:SS
Parameters
t- Unix Time; Use now if None (default)
bGMT- True for GMT; False (default) for localtime
bToday- 'TODAY' if True and t is today; YYYY-MM-DD if False (default)
Returns
string-ified time as YYYY-MM-DD HH:MM:SS
def pyRT.gatea.sys.GLcommon.DateTimeMs (   t = None,
  bGMT = False 
)

Return string-ified time as YYYY-MM-DD HH:MM:SS.mmm.

Parameters
t- Unix Time; Use now if None (default)
bGMT- True for GMT; False (default) for localtime
Returns
string-ified time as YYYY-MM-DD HH:MM:SS.mmm
def pyRT.gatea.sys.GLcommon.DateTimeUs (   t = None,
  bGMT = False 
)

Return string-ified time as YYYY-MM-DD HH:MM:SS.uuuuuu.

Parameters
t- Unix Time; Use now if None (default)
bGMT- True for GMT; False (default) for localtime
Returns
string-ified time as YYYY-MM-DD HH:MM:SS.uuuuuu
def pyRT.gatea.sys.GLcommon.FmtIntToSize (   iVal,
  sz 
)

Formats integer quantities to user-defined lengths, appending K, G, T.

Parameters
iVal- Value to format
sz- Max formatted string len
Returns
string-ified formatted quantity
def pyRT.gatea.sys.GLcommon.FmtQty (   fmt,
  dQty 
)

Formats quantities into readable comma-separated thousands, hundreds, etc.

Parameters
fmt- printf-like format w/ requested Sigf=Fig
dQty- Quantity
Returns
string-ified formatted quantity
def pyRT.gatea.sys.GLcommon.GetIdx ( )

Return a process-wide unique index.

Returns
Process-wide unique index
def pyRT.gatea.sys.GLcommon.HexDump (   binMsg)

Return hexDump of binary message.

Parameters
binMsg: Binary (or string) message
Returns
Proper hexDump
def pyRT.gatea.sys.GLcommon.InRange (   a,
  b,
  c 
)

Return True if b is in the closed interval between a and c inclusive.

Parameters
a- Lower Bound
b- Value to check
c- Upper Bound
Returns
True if a <= b and b <= c
def pyRT.gatea.sys.GLcommon.IsNone (   v)

Return True if 'v' is None.

Parameters
v- Variable to Check
Returns
True if 'v' is None
def pyRT.gatea.sys.GLcommon.IsPY3 ( )

Return True if Python 3.x.

Returns
True if Python 3.x
def pyRT.gatea.sys.GLcommon.LOG (   msg,
  bCons = True 
)

Log a message Log a message in log file and optionally Console.

Parameters
msg- Message to log
bCons- True to log to console if set; Default is True
def pyRT.gatea.sys.GLcommon.MicroTime ( )

Returns time.clock() if WIN32 and _bWin32Clock is True; time.time() if not.

Returns
time.clock() if WIN32 and _bWin32Clock is True; time.time() if not
def pyRT.gatea.sys.GLcommon.ProgressBar (   i,
  tck = 1000 
)
def pyRT.gatea.sys.GLcommon.PyClock ( )

PyVer-agnostic time.clock()

Returns
PyVer-agnostic time.clock()
def pyRT.gatea.sys.GLcommon.ReadFile (   pFile)

Open and read file as ASCII.

Parameters
pFile: Filename
Returns
[ line1, line2, ... ]
def pyRT.gatea.sys.GLcommon.RollLogFile (   pLog,
  numRoll 
)

Roll the log file.

Parameters
pLog- Log file name
numRoll- Number to roll
def pyRT.gatea.sys.GLcommon.SetDriftPerHr (   dDriftPerHr)

Set drift / hour to MicroTime() clock to compenstate for drifting time.clock()

Parameters
dDriftPerHr- Expected drift per hour
See Also
MicroTime()
def pyRT.gatea.sys.GLcommon.SetLog (   fp,
  cons = None 
)

Initialize Global Log File.

Parameters
fp- File from open()
cons- (Optional) wx Console
def pyRT.gatea.sys.GLcommon.Str2HMS (   str)

Break HH:MM:SS string into [ h, m, s ].

Parameters
str- HH:MM:SS
Returns
[ h, m, s ]
def pyRT.gatea.sys.GLcommon.Str2Time (   str,
  bGMT = False 
)

Convert string-ified YYYY-MM-DD HH:MM:SS.mmm to Unix Time.

This method handles the following conditions:

  • YYYY-MM-DD HH or
  • YYYYMMDD-HH:MM:SS.uuu
  • Today HH
  • H
  • H:MM
  • etc.
Parameters
str- YYYY-MM-DD HH:MM:SS.mmm or YYYYMMDD-HH:MM:SS.uuu
bGMT- True for GMT; False for localtime
Returns
Unix Time
def pyRT.gatea.sys.GLcommon.Str2Time_OBSOLETE (   str,
  bGMT = False 
)
def pyRT.gatea.sys.GLcommon.SubDict (   d1,
  d2,
  bInclZero = True 
)

Subtract dict d2 from d1.

Parameters
d1- Operand dict 1
d2- Operand dict 2
bInclZero- Allow zero values; Default is True
Returns
d1 - d2
def pyRT.gatea.sys.GLcommon.Time (   t = 0.0,
  bGMT = False 
)

Return string-ified time as HH:MM:SS.

Parameters
t- Unix Time; Use now if None (default)
bGMT- True for GMT; False (default) for localtime
Returns
string-ified time as HH:MM:SS
def pyRT.gatea.sys.GLcommon.Time2Mark (   hr,
  min,
  sec,
  bGMT = False 
)

Return millis to user-supplied HH:MM:SS.

This method handles rollover past Midnight, but requires user-supplied mark to be within 24 hours from current time

Parameters
hr- Hour mark
min- Minute mark
sec- Second mark
bGMT- True for GMT; False for localtime
Returns
Millis to mark
def pyRT.gatea.sys.GLcommon.TimeMs (   t = 0.0,
  bGMT = False 
)

Return string-ified time as HH:MM:SS.mmm.

Parameters
t- Unix Time; Use now if None (default)
bGMT- True for GMT; False (default) for localtime
Returns
string-ified time as HH:MM:SS.mmm
def pyRT.gatea.sys.GLcommon.TimeUs (   t = 0.0,
  bGMT = False 
)

Return string-ified time as HH:MM:SS.uuuuuu.

Parameters
t- Unix Time; Use now if None (default)
bGMT- True for GMT; False (default) for localtime
Returns
string-ified time as HH:MM:SS.uuuuuu
def pyRT.gatea.sys.GLcommon.tStart ( )

Returns ntp-anchroed time used for basis of MicroTime() clock.

tStart() also allows you to determine how long your application has been running. The following holds true:

  • Current time = time.clock() + tStart() + drift
Returns
ntp-anchroed time used for basis of MicroTime() clock
See Also
MicroTime()
def pyRT.gatea.sys.GLcommon.uDrift ( )

Returns current calculated drift in MicroTime() clock.

Drift is based on configurable SetDriftPerHr()

Returns
Current calculated drift in MicroTime() clock
See Also
MicroTime()
SetDriftPerHr()
def pyRT.gatea.sys.GLcommon.uDriftPerSec ( )

Returns current calculated drift / sec from MicroTime() clock.

Returns
current calculated drift / sec from MicroTime() clock
See Also
SetDriftPerHr()
def pyRT.gatea.sys.GLcommon.WithinRange (   a,
  b,
  c 
)

Ensure b is in the closed interval between a and c inclusive.

Parameters
a- Lower Bound
b- Value to check
c- Upper Bound
Returns
b within the interval a and c inclusive
def pyRT.gatea.sys.GLcommon.Xdefaults (   pDflt)

Parse .Xdefaults type config file.

Returns
dict of { key1 : val1, key2 : val2, ... }