| | |
- Device
- DevicePool
- Dmesg
- ErrorCollection
- Group
- Kld
- Serializer
- Sysctl
class Device |
| |
-> Device
DESCRIPTION
Class that describes a device object, characterized by the attributes
name (e.g. 'bktr') and node (e.g. 0). The attribute errors is a
accumulated list of error messages that occured when manipulating the
Device object.
CONSTRUCTOR
Device(str name='dummy', int node=0)
ATTRIBUTES
list errors
bool exists
str name
str namenode
int node
str path
bool root
METHODS
(str, str) config()
bool setup(own, perm)
bool restart()
CONSTANTS
CONFIGFILE = '/etc/devfs.conf'
Configuration file for devfs.
DEVFS_RESTART = '/etc/rc.d/devfs restart'
Command to restart devfs, creates devices with set ownership and
permissions.
EXAMPLES
d = Device('bktr', 0)
own, perm = d.config()
success = setup('root:operator', '0660')
success = d.restart() |
| |
Methods defined here:
- __init__(self, name='dummy', node=0)
- -> Device
DESCRIPTION
Creates a Device object, characterized by the attributes name (e.g.
'bktr') and node (e.g. 0). The attribute errors is a accumulated
list of error messages that occured when manipulating the Device
object.
EXAMPLES
d1 = Device() # dummy0 device (does not exist)
d2 = Device('bktr') # bktr0 device
d3 = Device('saa', 1) # saa1 device
- config(self)
- -> (str, str)
DESCRIPTION
Reads CONFIGFILE if any, and returns the last valid occurence of
the 'own' and 'perm' settings for this device if any. The format is
a tuple like ('root:operator', '0660'). If CONFIGFILE cannot be
read, an error message is appended to the errors attribute.
EXAMPLES
d0, d1 = Device('bktr', 0), Device('bktr', 1)
d0.config(), d1.config()
-> ('root:operator', '0660'), ('', '')
- restart(self)
- -> bool
DESCRIPTION
If UID 0 devfs will be restarted using the current CONFIGFILE.
Returns True on success, False if not root, or if ruuning
DEVFS_RESTART failed. In those cases, an error message
is appended to the errors attribute.
EXAMPLES
d0 = Device('bktr', 0)
d0.root
-> True
d0.restart()
-> True
- setup(self, own, perm)
- -> bool
DESCRIPTION
If UID 0 and if appending to CONFIGFILE is permitted, the own and perm
strings are appended to CONFIGFILE writing rules of the format
own bktr0 root:operator
perm bktr0 0660
for this device. The own and perm strings should be of the standard
UNIX notation of 'root:operator' and '0660' respectively. They are
the user and group owner of this device and the permissions in the
octal mrwx form where rwx means the readable-writeable-executable
bits and m any modifying permission bit (such as sticky or setuid).
If not UID 0 or CONFIGFILE cannot be appended to, an error message
is appended to the errors attribute and False is returned. Note
that devfs needs to be restarted to make any setup changes
effective at runtime.
EXAMPLES
d0 = Device('bktr', 0)
d0.root
-> True
d0.setup('root:operator', '0660')
-> True
Data and other attributes defined here:
- CONFIGFILE = '/etc/devfs.conf'
- DEVDIR = '/dev/'
- DEVFS_OWN = 'own'
- DEVFS_PERM = 'perm'
- DEVFS_RESTART = '/etc/rc.d/devfs restart'
|
class DevicePool |
| |
-> DevicePool
DESCRIPTION
Class that describes a list of Device objects, each characterized by
their attributes name (e.g. 'bktr') and node (e.g. 0). The attribute
errors is a accumulated list of error messages that occured when
manipulating any of the Device objects. This class is meant to be used
as a somewhat higher level representation of all considered devices.
Because of this, any individual Device object's errors that may occur
are concatenated into one single errors attribute of the DevicePool.
CONSTRUCTOR
DevicePool()
ATTRIBUTES
list devices
list errors
METHODS
add(str name='dummy', int nodes=1)
dict config()
bool restart()
bool setup(own, perm)
CONSTANTS
MAXNODES = 16
Maximimum number of nodes for a given device, e.g. bktr15.
EXAMPLES
p = DevicePool()
# bktr0 and bktr1 (bktr1 and tuner1 do not yet exist)
p.add('bktr', 2)
p.add('tuner', 2)
# saa0, sau0, iic0
p.add('saa', 1)
p.add('sau', 1)
p.add('iic')
exist = []
for item in p.devices:
exist.append(p.devices.exists)
exist
-> (True, False, True, False, True, True, True)
p.devices[-1].root
-> True
p.config()
-> [('bktr0', 'root:operator', '0660'),
('bktr1', '', ''),
('tuner0', 'root:operator', '0660'),
('tuner1', '', ''),
('saa0', 'root:operator', '0660'),
('sau0', 'root:operator', '0660'),
('iic0', 'root:operator', '0660')]
p.setup('root:operator', '0660')
-> True
p.config()
-> [('bktr0', 'root:operator', '0660'),
('bktr1', 'root:operator', '0660'),
('tuner0', 'root:operator', '0660'),
('tuner1', 'root:operator', '0660'),
('saa0', 'root:operator', '0660'),
('sau0', 'root:operator', '0660'),
('iic0', 'root:operator', '0660')]
p.restart()
-> True |
| |
Methods defined here:
- __init__(self)
- -> DevicePool
DESCRIPTION
Creates a DevicePool object which is a list of Device objects, each
characterized by their attributes name (e.g. 'bktr') and node
(e.g. 0). The attribute errors is a accumulated list of error
messages that occured when manipulating any of the Device objects.
Any individual Device object's errors that may occur are
concatenated into one single errors attribute of this object.
EXAMPLES
p = DevicePool()
- add(self, name='dummy', nodes=1)
- -> void
DESCRIPTION
Adds devices of name and the number of nodes as given by the args.
Nodes=1 means that device0 is added, nodes=2 means that device0 and
device1 are added, etc. Capped by MAXNODES.
EXAMPLES
p = DevicePool()
p.add('bktr', 1)
p.add('tuner', 1)
- config(self)
- -> dict
DESCRIPTION
Reads CONFIGFILE if any, and returns the last valid occurence of
the 'own' and 'perm' settings for all added devices. Returns a
dictionary of the format {'bktr0': ('root:operator', '0660')}. If
CONFIGFILE cannot be read, an error message is appended to the
errors attribute (for every device).
EXAMPLES
p = DevicePool()
p.add('bktr', 1)
p.add('tuner', 1)
print p.config()
-> {'tuner0': ('root:operator', '0660'), 'bktr0': ('root:operator', '0660')}
- restart(self)
- -> bool
DESCRIPTION
If UID 0 devfs will be restarted using the current CONFIGFILE.
Returns True on success, False if not root, or if ruuning
DEVFS_RESTART failed, or if the DevicePool contains no devices.
In those cases, an error message is appended to the errors
attribute. This method runs the restart() method of the first
device in the devices attribute.
EXAMPLES
p = DevicePool()
p.add('bktr', 1)
p.add('tuner', 1)
p.setup('root:operator', '0660')
-> True
p.restart()
-> True
- setup(self, own, perm)
- -> bool
DESCRIPTION
If UID 0 and if appending to CONFIGFILE is permitted, the own and perm
strings are appended to CONFIGFILE writing rules of the format
own bktr0 root:operator
perm bktr0 0660
for every device added. The own and perm strings should be of the
standard UNIX notation of 'root:operator' and '0660' respectively.
They are the user and group owner of this device and the permissions
in the octal mrwx form where rwx means the readable-writeable-executable
bits and m any modifying permission bit (such as sticky or setuid).
If not UID 0 or CONFIGFILE cannot be appended to, an error message
is appended to the errors attribute and False is returned. Note
that devfs needs to be restarted to make any setup changes
effective at runtime.
EXAMPLES
p = DevicePool()
p.add('bktr', 1)
p.add('tuner', 1)
p.setup('root:operator', '0660')
-> True
Data and other attributes defined here:
- MAXNODES = 16
|
class Dmesg |
| |
-> Dmesg
Class that describes a Dmesg object. It can run the dmesg command and
with the grep() method you can grep for an arbitrary list or tuple of
terms (strings). If nothing results from grepping the dmesg output,
the output of DMESG_BOOT will be tried, as it is possible that a device
was detected fine at boot time but by now dmesg has grown and the msgbuf
has been flushed since. If the DMESG or DMESG_BOOT commands fail, an
error string is appended to the errors attribute. Use this class only if
Sysctl provides insufficient information (as with bktr), crawling through
dmesg isn't very elegant.
CONSTRUCTOR
d = Dmesg()
METHODS
list grep(list terms)
ATTRIBUTES
list errors
CONSTANTS
DMESG = 'dmesg '
DMESG_BOOT = 'cat /var/run/dmesg.boot '
Shell commands used to get the dmesg info.
PIPE_GREP = '| grep '
Convenience constant, used in combined dmesg | grep shell commands.
EXAMPLES
d = Dmesg()
# One way to get seperate bktr card, tuner type and norm info
d.grep(['bktr0', 'tuner'])
-> ['bktr0: Pinnacle/Miro TV, Temic PAL tuner.']
card, tuner = d.grep(['bktr0', 'tuner'])[-1].split('bktr0: ')[1].split(', ')
tuner = tuner.split(' tuner.')[0]
tuner, norm = tuner.split()
card, tuner, norm
-> ('Pinnacle/Miro TV', 'Temic', 'PAL') |
| |
Methods defined here:
- __init__(self)
- -> Dmesg
DESCRIPTION
Creates a Dmesg object, which refers to the output of the commands
DMESG and if needed DMESG_BOOT. The method grep() can be used to
grep the output for an arbitray number of terms. If any error
occurs when issuing the dmesg | grep shell command it gets appended
to the errors attribute.
EXAMPLES
d = Dmesg()
- grep(self, terms)
- -> list
DESCRIPTION
Returns a list of strings containing lines from DMESG or DMESG_BOOT
that contain all the terms grepped on. Does not remove dupes,
retains line order.
EXAMPLES
d = Dmesg()
d.grep(['bktr0', 'tuner'])
-> ['bktr0: Pinnacle/Miro TV, Temic PAL tuner.']
Data and other attributes defined here:
- DMESG = 'dmesg'
- DMESG_BOOT = 'cat /var/run/dmesg.boot'
- PIPE_GREP = ' | grep '
|
class ErrorCollection |
| |
-> ErrorCollection
DESCRIPTION
Class that holds a dictionary of the obj.errors attribute for every
key object obj. It has an attribute objectpool (list) and the dict
errorpool. It also has a boolean attribute newerrors which is set to
True if any new errors have been recorded by one of the objects during
the add() or update() methods.
CONSTRUCTOR
ErrorCollection()
ATTRIBUTES
dictionary errorpool = {}
boolean newerrors = False
METHODS
add(object)
update()
EXAMPLES
# create objects that have a errors list attribute
k = Kld('bktr')
p = DevicePool()
p.add('bktr', 1)
p.add('tuner', 1)
e = ErrorCollection()
e.add(k)
e.add(p)
... do stuff with k and p ...
e.update()
e.newerrors
-> True # errors were added for k and/or p |
| |
Methods defined here:
- __init__(self)
- -> ErrorCollection
DESCRIPTION
Creates an ErrorCollection object that holds a dictionary of the
obj.errors attribute for every key object obj. It has an attribute
errorpool, which is a dictionary. It also has a boolean
attribute newerrors which is set to True if any new errors have
been recorded by one of the objects during the add() or update()
methods.
EXAMPLES
e = ErrorCollection()
- add(self, obj)
- -> void
DESCRIPTION
Adds object obj to the objectpool. If obj.errors is not empty,
the newerrors attribute is set to True, else to False.
EXAMPLES
e = ErrorCollection()
k = Kld('bktr')
e.add(k)
- update(self)
- -> void
DESCRIPTION
Updates the errorpool for every object key. If any of the objects
have new obj.errors entries these are added to the errorpool and
the newerrors attribute is set to True. If none of them has any
new errors the newerrors attribute is set to False.
EXAMPLES
e = ErrorCollection()
k = Kld('bktr')
e.add(k)
# do things with k that may cause errors
e.update()
|
class Group |
| |
-> Group
DESCRIPTION
Class that represents a UNIX group, using CONFIGFILE, and PW_GROUPMOD
command to add users to the group (setup() method).
CONSTRUCTOR
g = Group(int gid)
g = Group(str gid)
ATTRIBUTES
list errors
int gid
str name
list lines
bool root
METHODS
list config()
bool setup(str uid)
CONSTANTS
CONFIGFILE = "/etc/groups"
The groups configuration file.
PASSWD = '/etc/passwd'
(Shadowed) password file, useful to look up usernames.
PW_GROUPMOD = "pw groupmod operator -m "
Command used to add a user to a group.
EXAMPLES
g = Group('operator')
g.gid
-> 5
g.config()
-> ['root', 'danny']
g.setup('beastie')
-> True
g.config()
-> ['root', 'danny', 'beastie'] |
| |
Methods defined here:
- __init__(self, gid)
- -> Group
Creates a Group object which represents a UNIX group. Gid can be a valid
group name (string) or number (int). If one is given the other is looked
up in CONFIGFILE. If this can't be read or if there's no match, None is
returned and an error is appened to the errors attribute. The methods
config() and setup() return a list of group members and add a user to
the group respectively. The attribute root signifies whether you are
UID 0 or not, which is needed for running setup().
EXAMPLES
g = Group('wheel')
g.config()
-> ['root', 'danny']
g.setup('beastie')
-> True
- config(self)
- -> list
DESCRIPTION
Returns a list of user names that are members of this group.
Inquires CONFIGFILE for this information.
EXAMPLES
g = Group('operator')
g.config()
-> ['root', 'danny']
- setup(self, uid)
- -> bool
DESCRIPTION
Will attempt to add the user with name uid (string) to the group.
Returns False if not root, if PASSWD cannot be read (to verify user
existance), or if PW_GROUPMOD fails. Returns True on success. This
includes if the user was already a member of the group. On error,
an appropriate error message is added to the errors attribute.
This can be 'must be root', 'could not read', 'failed', 'no such
user'.
EXAMPLES
g = Group('operator')
g.config()
-> ['root', 'danny']
g.setup('beastie')
-> False
g.errors[-1]
-> 'Group.setup(): no such user, beastie'
# Oops, OK, now I have created my user on the system
g.setup('beastie')
-> True
g.config()
-> ['root', 'danny', 'beastie']
Data and other attributes defined here:
- CONFIGFILE = '/etc/group'
- PASSWD = '/etc/passwd'
- PW_GROUPMOD = 'pw groupmod operator -m '
|
class Kld |
| |
-> Kld
DESCRIPTION
Class that describes a Kld object, representing a kernel loadable module
characterized by attributes such as root (are we UID 0), exists, loaded,
and name (e.g. 'bktr'), and methods load(), unload(), config() and
setup(). The atribute errors is a accumulated list of error messages
that occured when using the Kld object.
CONSTRUCTOR
Kld(str name='dummy', list klddirs=['/boot/kernel', '/boot/modules'])
ATTRIBUTES
list errors
bool exists
str filename
bool loaded
str name
str path
bool root
METHODS
bool config()
bool load()
bool setup()
bool unload()
CONSTANTS
CONFIGFILE = '/boot/loader.conf'
Configuration file for klds.
DOTKO = '.ko'
Suffix for kld module filenames.
RCFILE = '/etc/rc.conf'
Configuration file for cxm kld (must be loaded post-boot).
KLDSTAT = 'kldstat '
KLDLOAD = 'kldload '
KLDUNLOAD = 'kldunload '
The kldstat, kldload, kldunload commands.
PIPE_AWK5 = " | awk '{ print $5 }' | grep "
Shell pipe used with kldstat command.
EXAMPLES
pwcmod = Kld('pwc')
pwcmod.exists
-> True
pwcmod.path
-> '/boot/modules/pwc.ko'
pwcmod.loaded
-> False
pwcmod.load()
-> True
pwcmod.loaded
-> True
pwcmod.config()
-> False
pwcmod.setup()
-> True |
| |
Methods defined here:
- __init__(self, name='dummy', klddirs=['/boot/kernel', '/boot/modules'])
- -> Kld
DESCRIPTION
Creates a Kld object, representing a kernel loadable module
characterized by attributes such as root (are we UID 0), exists,
loaded, and name (e.g. 'bktr'), and methods load(), unload(),
config() and setup(). The atribute errors is a accumulated list
of error messages that occured when using the Kld object.
If nonstandard kld directories are to be used they should be added
to the klddirs list when the object is created.
EXAMPLES
btmod = Kld('bktr')
foomod = Kld('foo', ['/path/to/the/foo/kmod/directory'])
- config(self)
- -> bool
DESCRIPTION
Looks if the module is listed in CONFIGFILE or RCFILE (cxm). Returns
True if this is the case, False if not or on read failure. In the
latter case, a 'could not read' error is appended to errors attribute.
EXAMPLES
btmod = Kld('bktr')
btmod.config()
-> True
- load(self)
- -> bool
DESCRIPTION
Attempts to load the module, if not already loaded. Returns True on
success, False on failure. Also appends the error to the errors
attribute if kldload fails. You must have root credentials.
EXAMPLES
btmod = Kld('bktr')
foomod = Kld('foo') # Non existant
btmod.load()
-> True
btmod.load() # Already loaded
-> False
foomod.load()
-> False
foomod.errors[-1]
-> 'util.Kld.load(): kldload foo failed'
- setup(self)
- -> bool
DESCRIPTION
Attempts to append the kld load directive to CONFIGFILE or RCFILE (cxm)
so that it gets applied on/post boot time. Returns True on success,
False on failure. In the latter case, a 'could not append' error is
appended to the errors attribute. You must also have root credentials,
otherwise False is returned and a 'must be root' error is appended to
the errors attribute.
EXAMPLES
btmod = Kld('bktr')
btmod.config()
-> False
btmod.setup()
-> True
- unload(self)
- -> bool
DESCRIPTION
Attempts to unload the module, if loaded. Returns True on
success, False on failure. Also appends the error to the errors
attribute if kldunload fails. You must have root credentials.
EXAMPLES
btmod = Kld('bktr')
btmod.loaded
-> True
btmod.unload() # bktr cannot be unloaded (known bug)
-> False
foomod.errors[-1]
-> 'util.Kld.unload(): kldunload bktr failed'
Data and other attributes defined here:
- CONFIGFILE = '/boot/loader.conf'
- DOTKO = '.ko'
- KLDLOAD = 'kldload '
- KLDSTAT = 'kldstat '
- KLDUNLOAD = 'kldunload '
- PIPE_AWK5 = " | awk '{ print $5 }' | grep "
- RCFILE = '/etc/rc.conf'
|
class Serializer |
| |
-> Serializer
DESCRIPTION
Class that decribes a (de)serialization object, which can be used
to dump an object as a cPickle and load an object from a stored
cPickle.
CONSTRUCTOR
s = Serializer(str pfile)
ATTRIBUTES
list errors
object obj
str pfile
METHODS
bool load()
bool dump()
EXAMPLES
s = Serializer('~/mypickle.cp')
if s.load():
s.obj.something
-> 'foo'
s.obj.setSomething('bar')
s.dump()
-> True |
| |
Methods defined here:
- __init__(self, pfile)
- -> Serializer
Creates a Serializer object which represents a (un)pickler. Pfile
is the path to the cPickled file to be loaded or dumped (or both).
If this can't be read/written or (un)pickling fails, an error is
appened to the errors attribute.
EXAMPLES
import chanlist
s = Serializer('~/.kbtv/chanlist.cp')
s.load() and isinstance(s.obj, chanlist.ChannelList)
-> True
- dump(self)
- -> bool
DESCRIPTION
Dumps the object referred to by the attribute obj to pfile
as a cPickle. If pfile can't be opened for writing or if
pickling fails, an error message is appended to the errors
attribute and False is returned. Otherwise True is returned.
EXAMPLES
anobject = AnObject() # init an object
anobject.icon
-> 'tux'
anobject.setIcon('beastie')
s = Serializer('/tmp/myobject.cp')
s.obj = anobject
s.dump() # dump object
-> True
- load(self)
- -> bool
DESCRIPTION
Loads the cPickle from pfile. If pfile can't be opened for
reading or if unpickling fails, an error message is appended
to the errors attribute and the attribute obj is None.
Otherwise the attribute obj is (a clone of) the unpickled
object. Returns True if successful, or False if not.
EXAMPLES
anobject = AnObject() # init an object
anobject.icon
-> 'tux'
s = Serializer('/tmp/myobject.cp')
s.load() # load prepared/preset object
-> True
s.obj.icon
-> 'beastie'
s = Serializer('/tmp/myotherobject.cp')
s.load()
-> True
anotherobject = s.obj # or directly without init
|
class Sysctl |
| |
-> Sysctl
DESCRIPTION
Class that describes a Sysctl object, representing the sysctl interface
and able to get and set sysctl values. The attribute oid is the quoted
oid for the sysctl, for example 'dev.pwc.0.%desc'. The attribute
exists is set according to whether or not the oid exists at all. The
attribute root means whether or not you have root credentials, which
are needed to set() a sysctl value and to use the setup() method.
CONSTRUCTOR
s = Sysctl(str oid='dummy')
ATTRIBUTES
list errors
bool exists
str oid
bool root
METHODS
str get()
bool set(int value)
str config()
bool setup()
CONSTANTS
CONFIGFILE = '/etc/sysctl.conf'
Configuration file for sysctl.
SYSCTL_GET = 'sysctl -n '
SYSCTL = 'sysctl'
UNKNOWN_OID = 'unknown oid'
Convenience constants for sysctl command.
EXAMPLES
s = Sysctl('hw.bt848.card')
s.exists
-> True
s.get()
-> '-1'
s.set(4)
-> True |
| |
Methods defined here:
- __init__(self, oid='dummy')
- -> Sysctl
DESCRIPTION
Creates a Sysctl object, representing the sysctl interface and able
to get and set sysctl values. The attribute oid is the quoted oid
for the sysctl, for example 'dev.pwc.0.%desc'. The attribute exists
is set according to whether or not the oid exists at all. The
attribute root means whether or not you have root credentials, which
are needed to set() a sysctl value and to use the setup() method.
If errors occur, such as 'not root', 'oid does not exist', or
if get or set failed for another reason these are appended to the
errors attribute.
EXAMPLES
s1 = Sysctl('hw.bt848.card')
s2 = Sysctl('hw.bt848.tunner') # Mis-spelled
s1.exists, s2.exist
-> (True, False)
s2.errors[-1]
'Sysctl.get(): oid hw.bt848.tunner does not exist'
s2 = Sysctl('hw.bt848.tuner')
s2.exist
-> True
- config(self)
- -> str
DESCRIPTION
Looks if the sysctl set directive is listed in CONFIGFILE. Returns
its string value if this is the case, empty string if not or on
read failure. In the latter case, a 'could not read' error is
appended to the errors attribute.
EXAMPLES
s = Sysctl('hw.bt848.card')
s.config()
-> '4'
- get(self)
- -> str
DESCRIPTION
Returns the value of the sysctl defined by the oid attribute. In
case of an error it returns an empty string and appends an error
string to the errors attribute.
EXAMPLES
s1 = Sysctl('hw.bt848.card')
s2 = Sysctl('hw.bt848.tuner')
s1.exists, s2.exist
-> (True, True)
s1.get(), s2.get()
-> ('-1', '-1')
- set(self, value)
- -> bool
DESCRIPTION
Attempts to set the sysctl defined by the oid attribute to value.
In case of an error it returns False and appends an error string
to the errors attribute. Will fail if not root, or if the oid
does not exist or if the sysctl failed for another reason.
Value is converted to a string, as expected by sysctl, so you can
use either a number or a string.
EXAMPLES
s1 = Sysctl('hw.bt848.card')
s2 = Sysctl('hw.bt848.tuner')
s1.exists, s2.exist
-> (True, True)
s1.set(4), s2.set(11)
-> (True, True)
- setup(self)
- -> bool
DESCRIPTION
Attempts to append the sysctl set directive to CONFIGFILE so that
it gets applied on boot time. Will set the value to its current
(using the get() method). Returns True on success, False on
failure. In the latter case, a 'could not append' error is appended
to the errors attribute. You must also have root credentials,
otherwise False is returned and a 'must be root' error is appended
to the errors attribute.
EXAMPLES
s = Sysctl('hw.bt848.card')
s.get()
-> '-1'
s.set(4)
-> True
s.config()
-> ''
s.setup()
-> True
Data and other attributes defined here:
- CONFIGFILE = '/etc/sysctl.conf'
- SYSCTL = 'sysctl'
- SYSCTL_GET = 'sysctl -n '
- UNKNOWN_OID = 'unknown oid'
| |