Previous topic

Source code documentation

This Page

epicsdf: EPICS diskfree, in python

The epicsdf module watches a disk partition and periodically reports information to EPICS PVs. The epicsdf.run() function is used to run the background job. The epicsdf.df_demo() function gives a demonstration of one possible, alternative use.

EPICS client diskfree, in python

class epicsdf.epicsdf(prefix)[source]

Connect to a support database of epicsdf and watch the indicated disk partition. Report the values to EPICS and watch for an alarm. Send an email when the alarm calcout PV changes.

Parameters:prefix (str) – prefix of EPICS support database instance (will not be changed after constructor)
Note :Some PV values in the support database are needed to construct the text of the email or the mailing list. Since it is not allowed to call caget during a camonitor callback, we need to monitor them and cache the values for use in the callback.

Usage:

There are only three methods in this class that should be called from the outside. All others methods are used internally.

run() for routine use:

from epicsdf import epicsdf
df = epicsdf('prj:p300:df:')  # construct it
df.run()                      # run forever

demo() for code development:

from epicsdf import epicsdf
df = epicsdf('prj:p300:df:')  # construct it
df.demo()                     # display a list of partitions

df2epics() could be called for one-off use:

from epicsdf import epicsdf
df = epicsdf('prj:p300:df:')  # construct it
df.df2epics()                 # update once
caget(item)[source]
Parameters:item (str) – name of item in support database
Returns:value of EPICS PV within our support database
caput(item, value)[source]
Parameters:
  • item (str) – name of item in support database
  • value – new value of item
demo()[source]

demonstrate one possible use of this code, to replicate the UNIX df command:

[jemian@gov,402,src]$ ./epicsdf.py
       total         free    available    use%
214748364800  42878369792  42878369792   80.0% .
 20803424256  10699845632   9626038272   53.7% /
   103512064     68733952     63389696   38.8% /boot
  1936355328   1936334848   1936334848    0.0% /dev/shm
215406047232 184723456000 173604937728   19.4% /local
 20803424256  10699845632   9626038272   53.7% /tmp
df(newdisk=None)[source]

Determine the available space of a (disk) partition, Report the results in a dictionary.

Parameters:newdisk (str) – name of disk to examine (will replace self.disk if not None)
Returns:dictionary or None if partition does not exist or zero values
Return type:dict
index units description
total bytes total space on the partition
free bytes free space
avail bytes available space
used bytes total - avail
%free %
%avail %
%used %
df2epics()[source]

Examine a disk partition and if possible, push its info to EPICS. Get the partition name from the EPICS database.

Returns:dictionary from df() or None
Return type:dict
doPeriodicUpdate()[source]

Do the work of the periodic update, getting the results of df() (with self.disk as the argument) and pushing the values up to the EPICS PVs. Then, set the time of the next update.

Note :Several PV changes can force an update to happen. See the on... methods (callback handlers) for details.
getDisk()[source]
Returns:name of disk partition to be watched
Return type:str
isValidPeriod(value)[source]

check that the given value is valid to be used as a period

Parameters:value (int or float) – candidate value of period, must be 1.0 or greater AND an int or a float
Return type:bool
logger(message)[source]

log a report from this class.

Parameters:message (str) – words to be logged
onAlarmPvChange(pvname=None, value=None, host=None, **kws)[source]

callback handler: Respond to camonitor on the alarm PV. Trigger to send an email message.

Parameters:
  • pvname (str) – monitored EPICS process variable name
  • value – value of EPICS process variable
  • host (str) – computer host name where the IOC resides
  • kws (dict) – PyEPICS keyword dictionary for callback functions
onDiskPvChange(pvname=None, value=None, host=None, **kws)[source]

callback handler: Respond to camonitor on the disk PV.

Parameters:
  • pvname (str) – monitored EPICS process variable name
  • value – value of EPICS process variable
  • host (str) – computer host name where the IOC resides
  • kws (dict) – PyEPICS keyword dictionary for callback functions
Note :

An acceptable change of disk partition forces an update.

onEmailsPvChange(pvname=None, value=None, host=None, **kws)[source]

callback handler: Respond to camonitor on the email_list PV.

Parameters:
  • pvname (str) – monitored EPICS process variable name
  • value – value of EPICS process variable
  • host (str) – computer host name where the IOC resides
  • kws (dict) – PyEPICS keyword dictionary for callback functions
onMessagePvChange(pvname=None, value=None, host=None, **kws)[source]

callback handler: Respond to camonitor on the message PV.

Parameters:
  • pvname (str) – monitored EPICS process variable name
  • value – value of EPICS process variable
  • host (str) – computer host name where the IOC resides
  • kws (dict) – PyEPICS keyword dictionary for callback functions
onPeriodPvChange(pvname=None, value=None, host=None, **kws)[source]

callback handler: Respond to camonitor on the period PV.

Parameters:
  • pvname (str) – monitored EPICS process variable name
  • value – value of EPICS process variable
  • host (str) – computer host name where the IOC resides
  • kws (dict) – PyEPICS keyword dictionary for callback functions
Note :

An acceptable change of period forces an update.

run()[source]

Run the job periodically – forever.

sendMail()[source]

send an email message when called

setPeriod(value=10.0)[source]

define the waiting period between updates (units = seconds)

Parameters:value (int or float) – candidate value of period (default = 10.0), must be 1.0 or greater AND an int or a float
wf2str(arr)[source]

converts an array of char from an EPICS waveform record to a python string

Parameters:arr (numpy.ndarray) – NumPy array of char from EPICS waveform record
Returns:string as represented by arr
Return type:str