This commit is contained in:
Michael Davidsaver
2013-03-24 22:10:53 -04:00
parent f58ba8dccb
commit 0f4b62e45d
8 changed files with 150 additions and 10 deletions

View File

@@ -0,0 +1,8 @@
try:
import _dbapi
except ImportError:
import _nullapi as _dbapi
__all__ = ['verinfo']
from _dbapi import verinfo

69
python/devsup/_nullapi.py Normal file
View File

@@ -0,0 +1,69 @@
def verinfo():
"""(VER, REV, MOD, PATH, "site") = verinfo()
Query EPICS version information
"""
return (0,0,0,0.'invalid')
class Record(object):
"""Handle for record operations
r = Record("rec:name")
"""
def __init__(self, rec):
pass
def name(self):
"""Record name
"""
def info(self, key):
"""info(key)
info(key, default)
Lookup record info tag. If no default
is provided then an exception is raised
if the info key does not exist.
"""
def infos(self):
"""Return a dictionary of all info tags
for this record
"""
def scan(self, sync=False):
"""scan(sync=False)
Scan this record. If sync is False then a
scan request is queued. If sync is True then the record
is scannined immidately on the current thread.
"""
def Field(object):
"""Handle for field operations
f = Field("rec:name.HOPR")
"""
def __init__(self, fld):
pass
def name(self):
"""("rec", "FLD") = name()
"""
def fieldinfo(self):
"""(type, size, #elements) = fieldinfo()
Type is DBF type code
size is number of bytes to start a single element
#elements is the maximum number of elements the field can hold
"""
def getval(self):
"""Fetch the current field value as a scalar.
Returns Int, Float, or str
"""
def putval(self, val):
"""Update the field value
Must be an Int, Float or str
"""

54
python/devsup/db.py Normal file
View File

@@ -0,0 +1,54 @@
try:
import _dbapi
except ImportError:
import _nullapi as _dbapi
from _dbapi import _Field, _Record
_rec_cache = {}
__all__ = [
'Record',
'Field',
]
def getRecord(name):
try:
return _rec_cache[name]
except KeyError:
rec = Record(name)
_rec_cache[name] = rec
return rec
class Record(_Record):
def __init__(self, *args, **kws):
super(Record, self).__init__(*args, **kws)
self._fld_cache = {}
def field(self, name):
"""Lookup field in this record
fld = rec.field('HOPR')
"""
try:
return self._fld_cache[name]
except KeyError:
fld = Field("%s.%s"%(self.name(), name))
self._fld_cache[name] = fld
return fld
def __repr__(self):
return 'Record("%s")'%self.name()
class Field(_Field):
@property
def record(self):
"""Fetch the record associated with this field
"""
try:
return self._record
except AttributeError:
rec, _ = self.name()
self._record = getRecord(rec)
return self._record
def __repr__(self):
return 'Field("%s.%s")'%self.name()

View File

@@ -1,4 +1,7 @@
try:
import _dbapi
except ImportError:
import _nullapi as _dbapi
from _dbapi import _hooks, _hooktable
__all__ = [