Update of /cvsroot/freevo/freevo/src/games
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27171
Modified Files:
Tag: rel-1-5
mame_cache.py
Log Message:
commit listxml mamaecache update
Index: mame_cache.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/games/mame_cache.py,v
retrieving revision 1.19
retrieving revision 1.19.2.1
diff -C2 -d -r1.19 -r1.19.2.1
*** mame_cache.py 10 Jul 2004 12:33:38 -0000 1.19
--- mame_cache.py 1 Nov 2004 23:59:49 -0000 1.19.2.1
***************
*** 10,13 ****
--- 10,16 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.19.2.1 2004/11/01 23:59:49 mikeruelle
+ # commit listxml mamaecache update
+ #
# Revision 1.19 2004/07/10 12:33:38 dischi
# header cleanup
***************
*** 40,43 ****
--- 43,59 ----
import sys
import random
+ # modifications made 21 Jul 2004 by vputz
+ #
+ # xmame version 0.84 made --listinfo obsolete; all rom list information
+ # is obtained by --listxml, which produces an XML feed of rom information.
+ # This current file switches based on the xmame version number; for 0.83 and
+ # above, it parses --listxml using a SAX content handler. Run time is
+ # essentially the same and it also picks up an additional game that the
+ # original version missed (--listinfo version saved a rom when a new rom
+ # started, so the last rom in the list was dropped, not that anyone noticed).
+ # included are some small functions I used to test compatibility of the romsets
+ # generated by either method. Both appear to be identical save that "Alien3"
+ # in the XML version tried to encode the "3" as a superscript and so it comes
+ # out as "Alien\xb3"; otherwise, it's fine.
import time, os, string
***************
*** 109,113 ****
# the cache has any relevant information.
#
! def updateMameRomList(mame_cmd):
# This method of running xmame --listinfo and parsing the output was
# borrowed from pyrecade - http://pyrecade.sf.net.
--- 125,129 ----
# the cache has any relevant information.
#
! def mameRomListFromListinfo(mame_cmd):
# This method of running xmame --listinfo and parsing the output was
# borrowed from pyrecade - http://pyrecade.sf.net.
***************
*** 147,152 ****
mameRomList = mame_types.MameRomList()
mameRomList.setMameRoms(cache)
! saveMameRomList(mameRomList)
return TRUE
--- 163,296 ----
mameRomList = mame_types.MameRomList()
mameRomList.setMameRoms(cache)
! return mameRomList
!
! from xml.sax.handler import ContentHandler
! from xml.sax import make_parser
!
!
! class romHandler( ContentHandler ):
! def __init__( self ) :
! self.newRom = mame_types.MameRom()
! self.cache = {}
! self.encoding = "ascii"
!
! def convert_text( self, chrs ) :
! return chrs.encode( self.encoding, 'replace' )
!
! 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 endElement( self, name ) :
! self.currentName = None
! if ( name == "game" and self.newRom != None ) :
! self.cache[ self.newRom.name ] = self.newRom
!
! def characters( self, chrs ) :
! if self.newRom != None :
! if ( self.currentName == "description" ) :
! self.newRom.description = self.newRom.description +
self.convert_text( chrs )
! elif ( self.currentName == "year" ) :
! if "year" not in dir( self.newRom ) :
! self.newRom.year = ''
! self.newRom.year = self.newRom.year + self.convert_text( chrs )
! elif ( self.currentName == "manufacturer" ) :
! self.newRom.manufacturer = self.newRom.manufacturer +
self.convert_text( chrs )
!
! def mameRomListFromListxml( mame_cmd ) :
! try:
! listinfo = os.popen( mame_cmd + ' --listxml', 'r' )
! except:
! print 'Unable to get mame listinfo.'
! return FALSE
!
! handler = romHandler()
! parser = make_parser()
! parser.setContentHandler( handler )
!
! parser.parse( listinfo )
!
! listinfo.close()
!
! mameRomList = mame_types.MameRomList()
! mameRomList.setMameRoms(handler.cache)
! return mameRomList
!
! def roms_equal( lhs, rhs ) :
! return ( ( lhs.name == rhs.name ) and
! ( lhs.description == rhs.description ) and
! ( lhs.year == rhs.year ) and
! ( lhs.manufacturer == rhs.manufacturer ) and
! (lhs.cloneof == rhs.cloneof ) and
! (lhs.romof == rhs.romof ) )
!
! def roms_compare( lhs, rhs ) :
! if not roms_equal( lhs, rhs ) :
! print "%s not equal to %s" % ( lhs.name, rhs.name )
! if ( lhs.name != rhs.name ) :
! print( "Names: '%s' vs '%s'" % (lhs.name, rhs.name) )
! if ( lhs.manufacturer != rhs.manufacturer ) :
! print( "Manufacturers: '%s' vs '%s'" % (lhs.manufacturer,
rhs.manufacturer) )
! if ( lhs.description != rhs.description ) :
! print( "Descriptions: '%s' vs '%s'" % (lhs.description, rhs.description)
)
! if ( lhs.year != rhs.year ) :
! print( "Years: '%s' vs '%s'" % (lhs.year, rhs.year) )
! if ( lhs.cloneof != rhs.cloneof ) :
! print( "Cloneofs: '%s' vs '%s'" % (lhs.cloneof, rhs.cloneof) )
! if ( lhs.romof != rhs.romof ) :
! print( "Romofs: '%s' vs '%s'" % (lhs.romof, rhs.romof) )
!
! def romsets_compare( lhs, rhs ) :
! lkeys = lhs.mameRoms.keys()
! rkeys = rhs.mameRoms.keys()
! lkeys_not_in_rkeys = [ x for x in lkeys if x not in rkeys ]
! rkeys_not_in_lkeys = [ x for x in rkeys if x not in lkeys ]
! print "lhs keys not in rhs keys: %s" % lkeys_not_in_rkeys
! print "rhs keys not in lhs keys: %s" % rkeys_not_in_lkeys
! for key in lkeys :
! if key in rkeys :
! roms_compare( lhs.mameRoms[ key ], rhs.mameRoms[ key ] )
+ def xmame_semimajor_version( mame_cmd ) :
+ try:
+ verinfo = os.popen(mame_cmd + ' --version', 'r')
+ except:
+ print 'Unable to get mame version.'
+ return FALSE
+
+ this_re = re.compile( ".*version\s+(\d+)\.(\d+)\.(\d+)\s+" )
+
+ for line in verinfo.readlines() :
+ if this_re.match( line ) :
+ result = int( this_re.match( line ).group( 2 ) )
+
+ verinfo.close()
+ return result
+
+
+
+ def updateMameRomList( mame_cmd ) :
+ if xmame_semimajor_version( mame_cmd ) == FALSE :
+ return FALSE
+ if xmame_semimajor_version(mame_cmd) >= 83 :
+ if DEBUG:
+ print "updating via listxml"
+ mameRomList = mameRomListFromListxml( mame_cmd )
+ else :
+ if DEBUG:
+ print "updating via listinfo"
+ mameRomList = mameRomListFromListinfo( mame_cmd )
+ saveMameRomList(mameRomList)
return TRUE
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog