def test_DBUpgrade_074_221(self):
        db_path = os.path.join(self.get_testdata_path(), 'database')

        # Setup data - MyGames.db is the hard-coded expected DB name
        self.assertTrue(
            os.path.isfile(os.path.join(db_path, 'MyGames-0.7.4.db')),
            "Expected to find 0.7.4 DB")
        shutil.copyfile(os.path.join(db_path, 'MyGames-0.7.4.db'),
                        os.path.join(db_path, 'MyGames.db'))

        gdb = GameDataBase(db_path)
        gdb.connect()

        util.CURRENT_DB_VERSION = '2.2.1'
        # Create db if not existent and maybe update to new version
        gdb.checkDBStructure()

        # Check backup files were created
        self.assertTrue(
            os.path.isfile(os.path.join(db_path, 'MyGames.db.backup 0.7.4')),
            "No backup database created")

        rcbSettingRows = RCBSetting(gdb).getAll()
        self.assertEquals('2.2.1', rcbSettingRows[0][RCBSetting.COL_dbVersion])
        self.assertEquals(117, Game(gdb).getCount())

        # Cleanup
        gdb.close()
        os.remove(os.path.join(db_path, 'MyGames.db'))
        os.remove(os.path.join(db_path, 'MyGames.db.backup 0.7.4'))
    def test_RetrieveGameById(self):
        ''' Validate basic retrieve works '''
        game = Game(self.gdb).getGameById(1)

        self.assertTrue(game.name == 'Adventure', 'Game with ID 1 expected to be Adventure but was %s' %game.name)
        self.assertTrue(game.publisher == 'Atari', 'Publisher of game with ID 1 expected to be Atari but was %s' %game.publisher)
        self.assertTrue(game.developer == 'Atari', 'Developer of game with ID 1 expected to be Atari but was %s' %game.developer)
        self.assertTrue(game.year == '1978', 'Year of game with ID 1 expected to be 1978 but was %s' %game.year)
        self.assertTrue(game.genre == 'Adventure', 'Genre of game with ID 1 expected to be Adventure but was %s' %game.genre)
        self.assertTrue(game.firstRom == '/path/to/roms/Atari2600/Adventure (1980) (Atari).a26', 'First rom of game with ID 1 expected to be /path/to/roms/Atari2600/Adventure (1980) (Atari).a26 but was %s' %game.firstRom)
 def test_RetrieveGameByIdMultipleGenres(self):
     
     game = Game(self.gdb).getGameById(50)
     
     self.assertTrue(game.name == 'Legend of Zelda, The - A Link to the Past (USA)', 'Game with ID 50 expected to be Legend of Zelda, The - A Link to the Past (USA) but was %s' %game.name)
     self.assertTrue(game.publisher == 'Nintendo', 'Publisher of game with ID 50 expected to be Nintendo EAD but was %s' %game.publisher)
     self.assertTrue(game.developer == 'Nintendo EAD', 'Developer of game with ID 50 expected to be Nintendo but was %s' %game.developer)
     self.assertTrue(game.year == '1992', 'Year of game with ID 50 expected to be 1992 but was %s' %game.year)
     self.assertTrue(game.genre == 'Adventure, Action, Role-Playing', 'Genre of game with ID 50 expected to be Adventure, Action, Role-Playing but was %s' %game.genre)
     self.assertTrue(game.firstRom == '/path/to/roms/SNES/ROMs/Legend of Zelda, The - A Link to the Past (USA).zip', 'First rom of game with ID 50 expected to be /path/to/roms/SNES/ROMs/Legend of Zelda, The - A Link to the Past (USA).zip but was %s' %game.firstRom)
Esempio n. 4
0
    def _update_artwork_cache_for_romcollection(self, rom_collection,
                                                file_type_id, media_dict):
        log.info('Begin _update_artwork_cache_for_romcollection')
        log.info('Update artwork cache for Rom Collection %s' %
                 str(rom_collection.id))

        continue_update = True
        media_paths_dict = {}
        try:
            media_paths_dict = media_dict[rom_collection.id]
        except KeyError:
            log.warn('No media paths dict found for rom collection %s' %
                     rom_collection.id)
            return continue_update

        games = GameView(self.gdb).getFilteredGames(rom_collection.id, 0, 0, 0,
                                                    0, 0, 0, 0, 0, '0 = 0', '',
                                                    0)
        gamecount = 1
        for game in games:
            self.progress_dialog.itemCount = len(games)
            #32955 = Scan artwork for Game
            update_message = "%s[CR]%s: %i/%i" % (
                self.dialogheader, util.localize(32955), gamecount, len(games))
            continue_update = self.progress_dialog.writeMsg(
                update_message, gamecount)
            if not continue_update:
                log.info('Update canceled')
                break
            gamecount = gamecount + 1
            for media_path in rom_collection.mediaPaths:
                #check if we should handle this file type
                if str(file_type_id
                       ) != media_path.fileType.id and file_type_id != 0:
                    continue

                roms = File(self.gdb).getRomsByGameId(game[GameView.COL_ID])
                gamename_from_file = rom_collection.getGamenameFromFilename(
                    roms[0][0])
                #check if artwork is available for this type
                file = self._find_file_in_mediadict(media_path.fileType.id,
                                                    rom_collection,
                                                    media_paths_dict,
                                                    gamename_from_file)
                #check if filename has changed
                if game[getattr(GameView, "COL_fileType%s" %
                                media_path.fileType.id)] != file:
                    #write result to db
                    # get column name from FIELDNAMES - index is the same as db column index (COL_fileTypeX)
                    column = Game.FIELDNAMES[getattr(
                        Game, "COL_fileType%s" % media_path.fileType.id)]
                    Game(self.gdb).update((column, ), (file, ),
                                          game[Game.COL_ID], True)

        return continue_update
Esempio n. 5
0
    def test_RetrieveNonExistantGameById(self):
        ''' Validate retrieve of unavailable ID returns an empty gameobj '''
        game = Game(self.gdb).getGameById(9999999)
        self.assertIsInstance(
            game, gameobj,
            u'Expected type of return object to be {0}, was {1}'.format(
                gameobj, type(game)))

        self.assertTrue(
            game.name == '',
            'Not found game with ID 9999999 expected to have empty details')
Esempio n. 6
0
    def test_RetrieveMultipleGamesByYear(self):
        ''' Validate retrieve by year works '''
        # consoleId, genreId, yearId, publisherId, isFavorite, likeStatement, maxGames
        newgames = Game(self.gdb).getGamesByFilter(0, 0, 9, 0, 0, '0 = 0', 0)

        self.assertIsInstance(
            newgames[0], gameobj,
            u'Expected type of return objects to be {0}, was {1}'.format(
                gameobj, type(newgames[0])))
        self.assertTrue(
            len(newgames) == 5,
            u'Expected 5 games found for year = 9 (1992), found {0}'.format(
                len(newgames)))
Esempio n. 7
0
    def test_update_rescrape(self):
        """test if update a rom collection works at all: all properties should have been updated"""
        config_xml_file = os.path.join(os.path.dirname(__file__), 'testdata',
                                       'config',
                                       'romcollections_importtests.xml')
        conf = Config(config_xml_file)
        conf.readXml()

        rcs = {}
        rcs[1] = conf.romCollections['1']

        self.register_responses_Amiga()

        #adjust settings
        xbmcaddon._settings[
            'rcb_nfoFolder'] = './script.games.rom.collection.browser/nfo/'
        xbmcaddon._settings['rcb_PreferNfoFileIfAvailable'] = 'false'
        xbmcaddon._settings['rcb_ignoreGamesWithoutDesc'] = 'false'
        xbmcaddon._settings['rcb_scrapingMode'] = 'Automatic: Accurate'
        xbmcaddon._settings['rcb_enableFullReimport'] = 'true'
        xbmcaddon._settings['rcb_overwriteWithNullvalues'] = 'false'

        dbu = DBUpdate()
        dbu.updateDB(self.gdb, RCBMockGui(), rcs, False)

        likeStmnt = '0 = 0'
        games = Game(self.gdb).getGamesByFilter(1, 0, 0, 0, 0, likeStmnt)

        self.assertEquals(len(games), 4)

        airborneRanger = games[0]
        self.assertEquals(airborneRanger.name, 'Airborne Ranger Update')
        self.assertEquals(airborneRanger.year, '1990')
        self.assertTrue(
            airborneRanger.plot.startswith(
                'Update: In this action/simulation game by Microprose the player takes the role of an U.S. Army airborne ranger.'
            ))
        self.assertEquals(airborneRanger.genre, 'Action, Adventure, Update')
        self.assertEquals(airborneRanger.publisher, 'MicroProse (Update)')
        self.assertEquals(airborneRanger.developer, 'Imagitec (Update)')
        self.assertEquals(airborneRanger.maxPlayers, '2')
        roms = File(self.gdb).getRomsByGameId(airborneRanger.id)
        self.assertEquals(len(roms), 1)
Esempio n. 8
0
    def test_update_rescrape_nullvalues(self):
        """test if update works when rcb_overwriteWithNullvalues is set to true"""
        config_xml_file = os.path.join(os.path.dirname(__file__), 'testdata',
                                       'config',
                                       'romcollections_importtests.xml')
        conf = Config(config_xml_file)
        conf.readXml()

        rcs = {}
        rcs[1] = conf.romCollections['1']

        self.register_responses_Amiga_nullvalues()

        # adjust settings
        xbmcaddon._settings[
            'rcb_nfoFolder'] = './script.games.rom.collection.browser/nfo/'
        xbmcaddon._settings['rcb_PreferNfoFileIfAvailable'] = 'false'
        xbmcaddon._settings['rcb_ignoreGamesWithoutDesc'] = 'false'
        xbmcaddon._settings['rcb_scrapingMode'] = 'Automatic: Accurate'
        xbmcaddon._settings['rcb_enableFullReimport'] = 'true'
        xbmcaddon._settings['rcb_overwriteWithNullvalues'] = 'true'

        dbu = DBUpdate()
        dbu.updateDB(self.gdb, RCBMockGui(), rcs, False)

        likeStmnt = '0 = 0'
        games = Game(self.gdb).getGamesByFilter(1, 0, 0, 0, 0, likeStmnt)

        self.assertEquals(len(games), 4)

        airborneRanger = games[0]
        self.assertEquals(airborneRanger.name, 'Airborne Ranger Update')
        self.assertEquals(airborneRanger.year, None)
        self.assertEquals(airborneRanger.plot, '')
        #HACK: genres are stored in genregame link table and are not overwritten with null values
        self.assertEquals(airborneRanger.genre, 'Action, Adventure')
        self.assertEquals(airborneRanger.publisher, None)
        self.assertEquals(airborneRanger.developer, None)
        self.assertEquals(airborneRanger.maxPlayers, '')
        roms = File(self.gdb).getRomsByGameId(airborneRanger.id)
        self.assertEquals(len(roms), 1)
Esempio n. 9
0
	def gatherWidgetData(self, param):
		print 'start gatherWidgetData'
		import util, helper
		from gamedatabase import Game, GameDataBase, File
		from config import Config, RomCollection
		
		gdb = GameDataBase(util.getAddonDataPath())
		gdb.connect()
		
		doImport, errorMsg = gdb.checkDBStructure()
		if(doImport) > 0:
			print "RCB: No database available. Won't gather any data."
			gdb.close()
			return
				
		#cache lookup tables
		yearDict = helper.cacheYears(gdb)
		publisherDict = helper.cachePublishers(gdb)
		developerDict = helper.cacheDevelopers(gdb)
		reviewerDict = helper.cacheReviewers(gdb)
		genreDict = helper.cacheGenres(gdb)
				
		limit = int(param.replace('limit=', ''))
		games = Game(gdb).getMostPlayedGames(limit)
		print 'most played games: %s' %games
		
		config = Config(None)
		statusOk, errorMsg = config.readXml()
		
		settings = util.getSettings()
		
		import xbmcgui
		count = 0
		for gameRow in games:
		
			count += 1
			try:
				print "Gathering data for rom no %i: %s" %(count, gameRow[util.ROW_NAME])
				
				romCollection = config.romCollections[str(gameRow[util.GAME_romCollectionId])]				
		
				#get artwork that is chosen to be shown in gamelist
				files = File(gdb).getFilesByParentIds(gameRow[util.ROW_ID], gameRow[util.GAME_romCollectionId], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId])
				fileDict = helper.cacheFiles(files)
				files = helper.getFilesByControl_Cached(gdb, romCollection.imagePlacingMain.fileTypesForGameList, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict)		
				if(files != None and len(files) != 0):
					thumb = files[0]
				else:
					thumb = ""
					
				files = helper.getFilesByControl_Cached(gdb, romCollection.imagePlacingMain.fileTypesForMainViewBackground, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict)		
				if(files != None and len(files) != 0):
					fanart = files[0]
				else:
					fanart = ""
				
				description = gameRow[util.GAME_description]
				if(description == None):
					description = ""
				
				year = helper.getPropertyFromCache(gameRow, yearDict, util.GAME_yearId, util.ROW_NAME)
				publisher = helper.getPropertyFromCache(gameRow, publisherDict, util.GAME_publisherId, util.ROW_NAME)
				developer = helper.getPropertyFromCache(gameRow, developerDict, util.GAME_developerId, util.ROW_NAME)
				genre = genreDict[gameRow[util.ROW_ID]]
				
				maxplayers = helper.saveReadString(gameRow[util.GAME_maxPlayers])
				rating = helper.saveReadString(gameRow[util.GAME_rating])
				votes = helper.saveReadString(gameRow[util.GAME_numVotes])
				url = helper.saveReadString(gameRow[util.GAME_url])
				region = helper.saveReadString(gameRow[util.GAME_region])
				media = helper.saveReadString(gameRow[util.GAME_media])				
				perspective = helper.saveReadString(gameRow[util.GAME_perspective])
				controllertype = helper.saveReadString(gameRow[util.GAME_controllerType])
				originaltitle = helper.saveReadString(gameRow[util.GAME_originalTitle])
				alternatetitle = helper.saveReadString(gameRow[util.GAME_alternateTitle])
				translatedby = helper.saveReadString(gameRow[util.GAME_translatedBy])
				version = helper.saveReadString(gameRow[util.GAME_version])
				playcount = helper.saveReadString(gameRow[util.GAME_launchCount])
				
				#get launch command
				filenameRows = File(gdb).getRomsByGameId(gameRow[util.ROW_ID])
				
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Id" %count, str(gameRow[util.ROW_ID]))
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Console" %count, romCollection.name)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Title" %count, gameRow[util.ROW_NAME])
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Thumb" %count, thumb)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Fanart" %count, fanart)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Plot" %count, description)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Year" %count, year)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Publisher" %count, publisher)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Developer" %count, developer)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Genre" %count, genre)
				
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Maxplayers" %count, maxplayers)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Region" %count, region)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Media" %count, media)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Perspective" %count, perspective)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Controllertype" %count, controllertype)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Playcount" %count, playcount)				
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Rating" %count, rating)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Votes" %count, votes)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Url" %count, url)				
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Originaltitle" %count, originaltitle)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Alternatetitle" %count, alternatetitle)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Translatedby" %count, translatedby)
				xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Version" %count, version)
								
			except Exception, (exc):
				print 'RCB: Error while getting most played games: ' +str(exc)
Esempio n. 10
0
    def gatherWidgetData(self, param):
        xbmc.log('start gatherWidgetData')
        import util, helper
        from gamedatabase import Game, GameDataBase, File
        from config import Config

        gdb = GameDataBase(util.getAddonDataPath())
        gdb.connect()

        doImport, errorMsg = gdb.checkDBStructure()
        if (doImport) > 0:
            xbmc.log("RCB: No database available. Won't gather any data.")
            gdb.close()
            return
        elif (doImport < 0):
            xbmc.log("RCB: Error occured while checking db structure: {0}" %
                     errorMsg)

        limit = param.replace('limit=', '')
        query = 'Select * From GameView Where launchCount > 0 Order by launchCount desc Limit %s;' % str(
            limit)
        games = Game(gdb).getGamesByQueryNoArgs(query)
        xbmc.log('most played games: %s' % games)

        config = Config(None)
        statusOk, errorMsg = config.readXml()

        if (not statusOk):
            xbmc.log('RCB: Error reading config.xml: {0}' % errorMsg)
            return

        mediaDict = {}
        mediaDict = helper.cacheMediaPathsForSelection(0, mediaDict, config)

        import xbmcgui
        count = 0
        for game in games:

            count += 1
            try:
                xbmc.log("RCB widget: Gathering data for rom no %i: %s" %
                         (count, game.name))

                romCollection = config.romCollections[str(
                    game.romCollectionId)]
                gamenameFromFile = romCollection.getGamenameFromFilename(
                    game.firstRom)
                mediaPathsDict = mediaDict[str(game.romCollectionId)]

                #get artwork that is chosen to be shown in gamelist
                thumb = helper.getFileForControl(
                    romCollection.imagePlacingMain.fileTypesForGameList,
                    romCollection, mediaPathsDict, gamenameFromFile, False)
                fanart = helper.getFileForControl(
                    romCollection.imagePlacingMain.
                    fileTypesForMainViewBackground, romCollection,
                    mediaPathsDict, gamenameFromFile, False)

                url = "plugin://script.games.rom.collection.browser/?launchid=%s" % game.id

                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Id" % count, str(game.id))
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Console" % count, romCollection.name)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Title" % count, game.name)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Thumb" % count, thumb)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Fanart" % count, fanart)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Plot" % count, game.plot)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Year" % count, game.year)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Publisher" % count, game.publisher)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Developer" % count, game.developer)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Genre" % count, game.genre)

                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Maxplayers" % count, game.maxplayers)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Region" % count, game.region)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Media" % count, game.media)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Perspective" % count, game.perspective)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Controllertype" % count,
                    game.controllertype)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Playcount" % count, game.playcount)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Rating" % count, game.rating)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Votes" % count, game.votes)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Url" % count, url)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Originaltitle" % count,
                    game.originalTitle)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Alternatetitle" % count,
                    game.alternateTitle)
                xbmcgui.Window(10000).setProperty(
                    "MostPlayedROM.%d.Version" % count, game.version)

            except Exception, (exc):
                xbmc.log('RCB: Error while getting most played games: ' +
                         str(exc))
Esempio n. 11
0
 def test_PropertyRedirection(self):
     ''' Validate the @property plot (used in UI) matches the DB column 'description' '''
     game = Game(self.gdb).getGameById(1)
     self.assertEqual(
         game.plot, game.description,
         'Expected runtime property plot to match DB value description')
Esempio n. 12
0
 def test_UnknownPropertyThrowsException(self):
     ''' Validate that trying to reference an unknown runtime property throws an exception '''
     game = Game(self.gdb).getGameById(1)
     self.assertRaises(AttributeError, self.function_to_raise_assertion,
                       game)
Esempio n. 13
0
    def test_RetrieveGameWithUnicode(self):
        ''' Validate items with unicode descriptions are stored/retrieved correctly '''
        game = Game(self.gdb).getGameById(66)

        self.assertTrue(game.plot.startswith(u'Mario\u2019s off'),
                        'Game with unicode plot not handled correctly')
Esempio n. 14
0
    def test_RetrieveGameById(self):
        ''' Validate basic retrieve works '''
        game = Game(self.gdb).getGameById(1)

        self.assertTrue(game.name == 'Adventure',
                        'Game with ID 1 expected to be Adventure')