flatfiledb::MUXFlatfileDB Class Reference


Public Member Functions

def __init__
def readdb
def readobject
def attr_search

Data Fields

 db
 dbtop
 player_record
 version
 attrnames
 fp
 nextattr

Detailed Description

Definition at line 202 of file flatfiledb.py.


Member Function Documentation

def flatfiledb::MUXFlatfileDB::__init__ (   self,
  fp = None 
)

Definition at line 203 of file flatfiledb.py.

00203                                :
00204         self.db = {}
00205         self.dbtop = 0
00206         self.player_record = 0
00207         self.version = 0
00208         self.attrnames = builtin_attrnames.copy()
00209         if fp:
00210             self.readdb(fp)
00211 
    def readdb(self, fp):

def flatfiledb::MUXFlatfileDB::attr_search (   self,
  str 
)

Definition at line 344 of file flatfiledb.py.

00344                               :
00345         res = []
00346         for obj in self.db.values():
00347             res.extend(obj.attr_search(str))
00348         return res
00349 
class MUXDBObject:

def flatfiledb::MUXFlatfileDB::readdb (   self,
  fp 
)

Definition at line 212 of file flatfiledb.py.

00212                         :
00213         self.fp = fp
00214         version = self.fp.readline()
00215         if not version or version[:2] <> "+X":
00216             # Version starts with +X
00217             raise MUXDBLoadError, \
00218                   "Not a valid DB file (no first line or it doesn't start with '+X')"
00219         if version[2:-1] <> "992001":
00220             sys.stderr.write("flatfiledb: Warning: possibly wrong flatfile version"
00221                              "(%d insteas of %s)\n"%( version[2:-1], "992001"))
00222         self.version = int(version[2:-1])
00223         nextline = self.fp.readline()
00224 
00225         if nextline and nextline[:2] == "+S":
00226             self.dbtop = int(nextline[2:-1])
00227             nextline = self.fp.readline()
00228 
00229         if nextline and nextline[:2] == "+N":
00230             self.nextattr = int(nextline[2:-1])
00231             nextline = self.fp.readline()
00232 
00233         if nextline and nextline[:2] == "-R":
00234             self.player_record = int(nextline[2:-1])
00235             nextline = self.fp.readline()
00236 
00237         while nextline and nextline[:2] == "+A":
00238             # Attribute defn, next line is the attribute name
00239             attr = self.fp.readline()
00240             if attr[0] <> '"' or attr[-2] <> '"':
00241                 sys.stderr.write("Warning: broken +A lines:\n%s%s"%(nextline, attr))
00242                 nextline = self.fp.readline()
00243                 continue
00244             # The attribute name is really "flags:name", but we don't care about flags yet
00245             attrname = string.split(attr[1:-2], ":", maxsplit=1)[1]
00246 #            sys.stderr.write("debug: adding attr num %s (%s)\n"%(nextline[2:-1], nextline))
00247             self.attrnames[nextline[2:-1]] = attrname
00248             nextline = self.fp.readline()
00249 
00250         while nextline and nextline[0] == "!":
00251             # Next object.
00252             nextline = self.readobject(int(nextline[1:-1]))
00253 
00254         if not nextline or nextline <> "***END OF DUMP***\n":
00255             sys.stderr.write("Didn't find ***END OF DUMP***\n")
00256             if nextline:
00257                 sys.stderr.write("The line read was: %s"%nextline)
00258         return
00259 
    def _readint(self):

def flatfiledb::MUXFlatfileDB::readobject (   self,
  objnum 
)

Definition at line 281 of file flatfiledb.py.

00281                                 :
00282         obj = MUXDBObject(objnum)
00283         self.db[objnum] = obj
00284 
00285         # if not vlags & V_ATRNAME
00286         obj.name = self._readstr()
00287         obj.attrs["NAME"] = obj.name
00288 
00289         obj.location = self._readint()
00290 
00291         # if flags & V_ZONE)
00292         obj.zone = self._readint()
00293         
00294         obj.contents = self._readint()
00295         obj.exits = self._readint()
00296 
00297         # if flags & V_LINK)
00298         obj.link = self._readint()
00299 
00300         obj.next = self._readint()
00301 
00302         # if not flags & V_ATRKEY
00303         # Lock attribute... treat as string, even though it should be specially handled
00304         obj.lock = self._readstr()
00305         obj.attrs["LOCK"] = obj.lock
00306         # Ugly hack to work around silly db restriction
00307         nextline = self.fp.readline()
00308         if string.strip(nextline):
00309             obj.owner = int(nextline[:-1])
00310         else:
00311             obj.owner = self._readint()
00312 
00313         # if flags & V_PARENT
00314         obj.parent = self._readint()
00315         # if not flags & V_ATRMONEY
00316         obj.money = self._readint()
00317 
00318         obj.flags = self._readint()
00319 
00320         # if flags & V_XFLAGS
00321         obj.flags2 = self._readint()
00322 
00323         # if flags & V_3FLAGS
00324         obj.flags3 = self._readint()
00325 
00326         # if flags & V_POWERS
00327         obj.powers = self._readint()
00328         obj.powers2 = self._readint()
00329 
00330         # Read the attributes
00331         # This is really 'if not flags & V_GDBM' but we don't do GDBM db's (yet?)
00332 
00333         nextline = self.fp.readline()
00334         while nextline and nextline[0] == ">":
00335             attrnum = nextline[1:-1]
00336             obj.attrs[self.attrnames[attrnum]] = self._readattr()
00337             nextline = self.fp.readline()
00338 
00339         if nextline <> "<\n":
00340             sys.stderr.write("flatfiledb: Warning: attrlist ended with: %s"%nextline)
00341 
00342         return self.fp.readline()
00343 
    def attr_search(self, str):


Field Documentation

flatfiledb::MUXFlatfileDB::attrnames

Definition at line 208 of file flatfiledb.py.

flatfiledb::MUXFlatfileDB::db

Definition at line 204 of file flatfiledb.py.

flatfiledb::MUXFlatfileDB::dbtop

Definition at line 205 of file flatfiledb.py.

flatfiledb::MUXFlatfileDB::fp

Definition at line 213 of file flatfiledb.py.

flatfiledb::MUXFlatfileDB::nextattr

Definition at line 230 of file flatfiledb.py.

flatfiledb::MUXFlatfileDB::player_record

Definition at line 206 of file flatfiledb.py.

flatfiledb::MUXFlatfileDB::version

Definition at line 207 of file flatfiledb.py.


The documentation for this class was generated from the following file:
Generated on Mon May 28 04:25:49 2007 for BattletechMUX by  doxygen 1.4.7