def parseDemoFile(self, src_path):

        demo_type = None
        
        f = open(src_path, 'r')
        for line in f.readlines():

            if line.find("[INFO")  >= 0 or \
                   line.find("[START") >= 0:
                demo_type = 'old'
                break

            elif line.find("<Demo") >= 0 or \
                     line.find("<Panel") >= 0:
                demo_type = 'new'
                break
        else:
            raise DemoError("Couldn't identify Demo source format")

        if demo_type == 'old':
            from format2065 import DemoParser2065
            demo_parser = DemoParser2065(src_path, self)
            #self.parseOldDemo(src_path)
        else:
            ## demo type is new
            #self.parseNewDemo(src_path)
            demo_parser = DemoParserNew(src_path, self)

        demo_parser.parseDemo()
        f.close()
    def parseDemo(self):
         m = Multiloader()
         m.load( self.src_path, [XMLDemo])
         objs = m.getObjects()
         #print objs
         demoObjs  = objs['Demo']
         #panelObjs = objs['Panel'] 
         demoObj = demoObjs[0]

         if not demoObj.panels:
             raise DemoError("Couldn't find valid panel description in source file. "
                             "Demo must have at least one step.")

         if hasattr(demoObj, 'title'):
             self.demo.title = str(demoObj.title)
         else:
             self.demo.title = "Chimera Demo"

         if hasattr(demoObj, 'autodelay')  :   self.demo.auto_delay = int(demoObj.autodelay)
         if hasattr(demoObj, 'image')      :   self.demo.img_src   = str(demoObj.image)
         if hasattr(demoObj, 'bg_color')   :   self.demo.img_bg_color = str(demoObj.bg_color)
         if hasattr(demoObj, 'autorun_on') :   self.demo.autorun_on_start = True
         if hasattr(demoObj, 'description'):   self.demo.description = str(demoObj.description)
         if hasattr(demoObj, 'datadir')    :   self.demo.datadir = str(demoObj.datadir)
         
         if isinstance(demoObj.panels, XMLPanel):
             demoObj.panels = [demoObj.panels]
         
         for panel in demoObj.panels:
             p = self.parsePanel(panel)
             self.demo.demoPanels[p.getId()] = p
Пример #3
0
    def parseDemoHeaders(self, f):
        import string

        while 1:
            line = f.readline()
            if not line:
                break

            if (line.strip())[0:9] == 'AUTODELAY':
                self.demo.auto_delay = int(line.split()[1])
            elif (line.strip())[0:5] == 'TITLE':
                self.demo.title = string.join(line.split()[1:])
            elif (line.strip())[0:5] == 'IMAGE':
                self.demo.img_src = string.join(line.split()[1:])
            elif (line.strip())[0:8] == 'BG_COLOR':
                self.demo.img_bg_color = string.join(line.split()[1:])
            elif (line.strip())[0:10] == 'AUTORUN_ON':
                self.demo.autorun_on_start = True
            elif (line.strip())[0:4] == 'DESC':
                desc = string.join(line.split()[1:])
                self.demo.description += " " + desc.strip()
            elif line == '' or line.strip()[0:6] == '[START':
                raise DemoError("couldn't find \"[END INFO]\" tag.")
            elif line.strip() == '[END INFO]':
                break
Пример #4
0
    def parseDemo(self):

        f = open(self.src_path, 'r')

        step_num = 0

        while 1:
            line = f.readline()

            if not line:
                break

            if line.strip() == '[INFO]':
                self.parseDemoHeaders(f)

            elif line.strip()[0:6] == '[START':
                step_num += 1
                p = self.parsePanel(f, step_num, line)
                self.demo.demoPanels[step_num] = p

        f.close()

        if step_num == 0:
            raise DemoError(
                "Couldn't find valid panel description in source file. "
                "Demo must have at least one step.")
Пример #5
0
    def parseUndo(self, f):
        undos = []

        while 1:
            line = f.readline()

            if line.strip() == '[END UNDO]':
                break
            elif line == '' or line.strip() == '[END]':
                raise DemoError("couldn't find \"[END UNDO]\" tag.")
            else:
                undos.append((True, line.strip()))

        return undos
Пример #6
0
    def parseCommands(self, f):
        cmds = []

        while 1:
            line = f.readline()

            if line.strip() == '[END COMMANDS]':
                break
            elif line == '' or line.strip() == '[END]':
                raise DemoError("couldn't find \"[END COMMANDS]\" tag.")
            else:
                cmds.append((True, line.strip()))

        return cmds
Пример #7
0
    def parseText(self, f):
        text = ''

        while 1:
            line = f.readline()
            if not line:
                break

            if line.strip() == '[END TEXT]':
                break
            elif line.strip() == '[END]':
                raise DemoError("couldn't find \"[END TEXT]\" tag.")
            else:
                #if line.strip() == '':
                #    text += "\n\n"
                #else:
                text += (" " + line)  ## was line.strip()

        return text