Пример #1
0
 def creatitem(self, linenum, numlines, key, content, istext):
     # Create new item
     newitem = fileitem(linenum,numlines,key,content,istext)
     # Insert as new first element?
     if (self.firstel.getlinenum >= linenum + numlines):
         newitem.nextitem = self.firstel
         self.firstel = newitem
     else:
         # Insert in between
         lastitem = []
         curritem = self.firstel
         found = 0
         while not (curritem == [] or found):
             # Check if ne item needs to be inserted before current item
             if (curritem.getlinenum >= linenum):
                 newitem.nextitem = curritem
                 newitem.previtem = curritem.previtem
                 curritem.previtem.nextitem = newitem
                 curritem.previtem = newitem
                 found = 1
             # Append
             if (curritem.nextitem == []):
                 curritem.nextitem = newitem
                 newitem.previtem = curritem
             curritem = curritem.nextitem                    
     # Check if lines need to be shifted
     curritem = self.firstel
     lastline = 0
     while not (curritem.nextitem == []):
         if curritem.getlinenum <= lastline:
             curritem.moveposition(self, lastline - curritem.getlinenum + 1)
         lastline = curritem.getlinenum + curritem.numlines
         curritem = curritem.nextitem                
Пример #2
0
 def createstructure(self, content):
     """
     This is the helper function to fill the file content into the class at initialisation time
     """
     lineidx = 0
     tempstr = []
     tempkey = []
     numlines = 1
     tempprevel = []
     #print self.filename
     for lines in content:
         lineidx = lineidx + 1
         if not (len(lines.strip()) < 1):
         # Exclude empty lines
             if lines[0] is "#" or (lines[0] is "/" and lines[1] is "/"):
                 tempitem = fileitem(lineidx,1,'',lines,1)
                 self.list.append(tempitem)
                 self.numitems = self.numitems + 1
                 if self.version == []:
                     if lines.strip().endswith("$"):
                         self.version = self.tm.getversion(lines)
                 #if self.Debugkey:
                 #    print str(str(lineidx) + ": " + "Textstring: " + lines)
             else:
                 #errorflag = 0
                 if tempstr == []:
                     temp = lines.split("=",1)
                     if len(temp) == 1:
                         raise Property_File_Error(self.fullfilename, str(lineidx),  temp[0])
                     else:
                         tempkey = temp[0].strip()
                         tempstr.append(temp[1].strip())
                 else:
                     tempstr.append(str(lines.strip()))
                     numlines = numlines + 1
                     #if self.Debugkey:
                     #    print str(str(lineidx) + ": " + "Addon line " + str(numlines) + ": " + lines)
                 if not (lines.strip().endswith("\\")):
                     if numlines is 1:
                         tempitem = fileitem(lineidx,1,tempkey,tempstr[0],0)
                         #if self.Debugkey:
                         #    print str(str(lineidx) + ": " + "Singleline Key: " + tempkey)
                     else:
                         tempitem = fileitem(lineidx + 1 - numlines,numlines,tempkey,tempstr,0)
                         #if self.Debugkey:
                         #    print str(str(lineidx) + ": " + "Multiline Key: " + tempkey + str(numlines) + " lines")
                     self.list.append(tempitem)
                     self.numitems = self.numitems + 1
                     self.numkeys = self.numkeys + 1
                     tempstr = []
                     tempkey = []
                     numlines = 1
             if not tempprevel == []:
                 tempprevel.nextitem = tempitem
                 tempitem.previtem = tempprevel
                 tempprevel = tempitem
             else:
                 tempprevel = tempitem
                 self.firstel = tempitem
     if numlines > 1:
         raise Property_File_Error(self.fullfilename, str(lineidx + 1 - numlines),  tempkey)