Back to index

python3.2  3.2.2
Classes | Functions | Variables
grp Namespace Reference

Classes

class  Group

Functions

def __get_field_sep
def __read_group_file
def getgrgid
def getgrnam
def getgrall

Variables

list __group_path = []
 group_file = None
tuple __f = open(__i, 'r')
list __field_sep = [':']

Function Documentation

def grp.__get_field_sep (   record) [private]

Definition at line 87 of file grp.py.

00087 
00088 def __get_field_sep(record):
00089     fs = None
00090     for c in __field_sep:
00091         # there should be 3 delimiter characters (for 4 fields)
00092         if record.count(c) == 3:
00093             fs = c
00094             break
00095     if fs:
00096         return fs
00097     else:
00098         raise KeyError('>> group database fields not delimited <<')
00099 
00100 # class to match the new record field name accessors.
00101 # the resulting object is intended to behave like a read-only tuple,
# with each member also accessible by a field name.

Here is the caller graph for this function:

def grp.__read_group_file ( ) [private]

Definition at line 135 of file grp.py.

00135 
00136 def __read_group_file():
00137     if group_file:
00138         group = open(group_file, 'r')
00139     else:
00140         raise KeyError('>> no group database <<')
00141     gidx = {}
00142     namx = {}
00143     sep = None
00144     while 1:
00145         entry = group.readline().strip()
00146         if len(entry) > 3:
00147             if sep is None:
00148                 sep = __get_field_sep(entry)
00149             fields = entry.split(sep)
00150             fields[2] = int(fields[2])
00151             fields[3] = [f.strip() for f in fields[3].split(',')]
00152             record = Group(*fields)
00153             if fields[2] not in gidx:
00154                 gidx[fields[2]] = record
00155             if fields[0] not in namx:
00156                 namx[fields[0]] = record
00157         elif len(entry) > 0:
00158             pass                         # skip empty or malformed records
00159         else:
00160             break
00161     group.close()
00162     if len(gidx) == 0:
00163         raise KeyError
00164     return (gidx, namx)
00165 
# return the group database entry by GID

Here is the call graph for this function:

Here is the caller graph for this function:

def grp.getgrall ( )

Definition at line 176 of file grp.py.

00176 
00177 def getgrall():
00178     g, n = __read_group_file()
00179     return g.values()
00180 
# test harness

Here is the call graph for this function:

Here is the caller graph for this function:

def grp.getgrgid (   gid)

Definition at line 166 of file grp.py.

00166 
00167 def getgrgid(gid):
00168     g, n = __read_group_file()
00169     return g[gid]
00170 
# return the group database entry by group name

Here is the call graph for this function:

Here is the caller graph for this function:

def grp.getgrnam (   name)

Definition at line 171 of file grp.py.

00171 
00172 def getgrnam(name):
00173     g, n = __read_group_file()
00174     return n[name]
00175 
# return all the group database entries

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tuple grp.__f = open(__i, 'r')

Definition at line 71 of file grp.py.

list grp.__field_sep = [':']

Definition at line 81 of file grp.py.

list grp.__group_path = []

Definition at line 60 of file grp.py.

Definition at line 68 of file grp.py.