• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

/home/mark/model/software/ScrumPy/ScrumPy/Bioinf/PyoCyc/Annotate.py

00001 import types, os
00002 import Base, Tags
00003 from Util import SvnClient
00004 
00005 DefaultFile="annotations.dat"
00006 DefaultDir= "Annotations"
00007 
00008 class Record(Base.Record):
00009 
00010     RecordClass="Annotations"
00011 
00012     def ModifyField(self, id, contents):
00013 
00014         id = id.upper()
00015         if id == Tags.UID:
00016             print "not modifying ", id, "!!"
00017         elif id not in self.keys():
00018             print "the id ", id, " cannot be found"
00019         elif contents == "":
00020             print "no contents specified to modify ", id
00021         else:
00022             if type(contents) != types.ListType:
00023                 contents = [contents]
00024             self[id] = contents
00025             
00026     def AddToField(self, id, contents):
00027 
00028         id = id.upper()
00029         if type(contents) != types.ListType:
00030                 contents = [contents]
00031 
00032         self[id].extend(contents)
00033         
00034 
00035     def AddNewField(self, id, contents):
00036 
00037         id = id.upper()
00038 
00039         if self.has_key(id):
00040             print "not adding duplicate UID ", id, "to", self.UID
00041         else:
00042             if type(contents) != types.ListType:
00043                 contents = [contents]
00044 
00045             self[id] = contents
00046 
00047     def SaveStr(self):
00048         return str(self) + Tags.RecEnd + "\n"
00049         
00050 
00051     def DelField(self, id):
00052         if id == Tags.UID:
00053             print "not removing UID ", id ,"!!"
00054         else:
00055             del self[id]
00056 
00057    
00058   
00059 class DB(Base.DB):
00060 
00061     def __init__(self, path=Base.DefaultPath, file=DefaultFile, RecClass=Record, **kwargs):
00062         Base.DB.__init__(self,  path, file, RecClass=Record,**kwargs)
00063         
00064         self.path = path
00065         self.file = os.sep.join((path, file))
00066         self.svn = SvnClient.SvnClient(path)
00067 
00068     def SaveDBToFile(self, file):
00069 
00070         if  type(file) == types.StringType:
00071             file = open(file, "w")
00072 
00073         for rec in self:
00074             file.write(self[rec].SaveStr())
00075 
00076     def Save(self, message):
00077 
00078         self.SaveDBToFile(self.file)
00079         # Commiting to the database
00080         rv = self.svn.Commit(message)
00081         return rv
00082 

Generated on Tue Sep 4 2012 15:38:01 for ScrumPy by  doxygen 1.7.1