def mameRomListFromListinfo(mame_cmd): # This method of running xmame --listinfo and parsing the output was # borrowed from pyrecade - http://pyrecade.sf.net. try: listinfo = os.popen(mame_cmd + ' --listinfo', 'r') except: print 'Unable to get mame listinfo.' return FALSE newRom = mame_types.MameRom() cache = {} for line in listinfo.readlines(): if re.compile("^\tname").match(line): newRom.name = re.compile("^\tname (.*)").match(line).group(1) elif re.compile("^\tdescription").match(line): newRom.description = re.compile("^\tdescription (.*)").match( line).group(1)[1:-1] elif re.compile("^\tyear").match(line): newRom.year = re.compile("^\tyear (.*)").match(line).group(1) elif re.compile("^\tmanufacturer").match(line): newRom.manufacturer = re.compile("^\tmanufacturer (.*)").match( line).group(1)[1:-1] elif re.compile("^\tcloneof").match(line): newRom.cloneof = re.compile("^\tcloneof (.*)").match(line).group(1) elif re.compile("^\tromof").match(line): newRom.romof = re.compile("^\tromof (.*)").match(line).group(1) elif re.compile("^game \(").match(line): # We've reached a new game so dump everthing we have so far if newRom.name: # add the new rom to the cache. cache[newRom.name] = newRom # make a new mameRom newRom = mame_types.MameRom() listinfo.close() mameRomList = mame_types.MameRomList() mameRomList.setMameRoms(cache) return mameRomList
def startElement(self, name, attrs): self.currentName = name if (name == "game"): if attrs.has_key("runnable") and self.convert_text( attrs.get("runnable")) == "no": self.newRom = None else: self.newRom = mame_types.MameRom() self.newRom.name = self.convert_text(attrs.get("name")) if attrs.has_key("cloneof"): self.newRom.cloneof = self.convert_text( attrs.get("cloneof")) if attrs.has_key("romof"): self.newRom.romof = self.convert_text(attrs.get("romof")) self.newRom.description = '' self.newRom.manufacturer = ''
def __init__(self): self.newRom = mame_types.MameRom() self.cache = {} self.encoding = "ascii"