def test_createNfoFromDesc_newfile_missinginfos(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' self.assertFalse(os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'nfo file should not exist') writer = NfoWriter() writer.createNfoFromDesc('Airborne Ranger', #gamename '', #plot 'Amiga', #romCollectionname '', #publisher '', #developer '', #year '', #players '', #rating '', #votes '', #url '', #region '', #media '', #perspective '', #controller '', #originalTitle '', #alternateTitle '', #version [], #genreList '', #isFavorite '', #launchCount './testdata/roms/Amiga/Airborne Ranger.adf', #romFile 'Airborne Ranger', #gamenameFromFile {}, #artworkfiles {} #artworkurls ) self.assertTrue(os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'Expected nfo file to be written') #use nfo scraper to read the file scraper = NFO_Scraper() scraper.nfo_file = './testdata/nfo/Amiga/Airborne Ranger.nfo' result = scraper.retrieve(1, 'Amiga') self.assertEqual(["Airborne Ranger"], result['Game']) self.assertEqual([None], result['OriginalTitle']) self.assertEqual([None], result['AlternateTitle']) self.assertEqual([None], result['ReleaseYear']) self.assertEqual([None], result['Publisher']) self.assertEqual([None], result['Developer']) self.assertEqual([None], result['Perspective']) self.assertEqual([None], result['Controller']) self.assertEqual([None], result['Media']) self.assertEqual([None], result['Region']) self.assertEqual([None], result['Version']) self.assertEqual([None], result['Players']) self.assertEqual([None], result['LaunchCount']) self.assertEqual([None], result['IsFavorite']) self.assertEqual([None], result['Rating']) self.assertEqual([None], result['Votes']) self.assertEqual([None], result['Description']) self.assertEqual(len(result['Genre']), 0) os.remove('./testdata/nfo/Amiga/Airborne Ranger.nfo')
def insertGameFromDesc(self, gamedescription, gamename_from_file, romCollection, romfiles, foldername, isUpdate, gameId): log.info("insertGameFromDesc") if gamedescription is not None: game = self.resolveParseResult(gamedescription, 'Game') else: game = '' # if no game name has been scraped we expect that no results have been found if game == '': self.missingDescFile.add_entry(gamename_from_file) if __addon__.getSetting(util.SETTING_RCB_IGNOREGAMEWITHOUTDESC).upper() == 'TRUE': log.warn("No description found for game '%s'. Game will not be imported." % gamename_from_file) return None gamedescription = {} game_row = self.convert_parseresult_to_gamerow(gamedescription, gamename_from_file) game_row[Game.COL_romCollectionId] = romCollection.id gamename = game_row[Game.COL_NAME] publisher = self.resolveParseResult(gamedescription, 'Publisher') developer = self.resolveParseResult(gamedescription, 'Developer') artWorkFound, artworkfiles, artworkurls = self.getArtworkForGame(romCollection, gamename, gamename_from_file, gamedescription, foldername, publisher, developer) #add artwork filenames to game_row for filetype, filenames in list(artworkfiles.items()): for filename in filenames: prop = 'COL_fileType%s' % filetype.id index = getattr(Game, prop) game_row[index] = filename gameId = self.insertGame(game_row, isUpdate, gameId, romCollection.allowUpdate, ) if gameId is None: return None genreIds = self.insertForeignKeyItemList(gamedescription, 'Genre', Genre(self.gdb)) self.add_genres_to_db(genreIds, gameId) self.add_romfiles_to_db(romfiles, gameId) self.gdb.commit() # Create Nfo file with game properties try: # Read game from db as nfowriter expects GameView db row gamerow = GameView(self.gdb).getGameById(gameId) writer = NfoWriter() writer.createNfoFromDesc(gamerow, romCollection.name, romfiles[0], gamename_from_file, artworkfiles, artworkurls) except Exception as e: log.warn(u"Unable to write NFO file for game %s: %s" % (gamename, e)) return gameId
def test_getNfoFilePath_path_in_settings(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' writer = NfoWriter() filename = writer.getNfoFilePath("Amiga", "./testdata/roms/Amiga/Airborne Ranger.adf", "Airborne Ranger") filename = filename.replace("\\", "/") self.assertEquals("./testdata/nfo/Amiga/Airborne Ranger.nfo", filename)
def test_getNfoFilePath_path_in_settings(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' writer = NfoWriter() filename = writer.getNfoFilePath( "Amiga", "./testdata/roms/Amiga/Airborne Ranger.adf", "Airborne Ranger") filename = filename.replace("\\", "/") self.assertEquals("./testdata/nfo/Amiga/Airborne Ranger.nfo", filename)
def test_exportLibrary(self): export_base_folder = './testdata/nfo/export/' xbmcaddon._settings['rcb_nfoFolder'] = export_base_folder # Setup data - MyGames.db is the hard-coded expected DB name db_path = './testdata/database/' shutil.copyfile(os.path.join(db_path, 'MyGames_2.2.0_full.db'), os.path.join(db_path, 'MyGames.db')) gdb = GameDataBase(db_path) gdb.connect() # Setup config config_xml_file = './testdata/config/romcollections_importtests.xml' conf = Config(config_xml_file) conf.readXml() writer = NfoWriter() writer.exportLibrary(gdb, conf.romCollections) #check if all files have been created self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Amiga/Airborne Ranger.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Amiga/Chuck Rock.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Amiga/Eliminator.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Amiga/MicroProse Formula One Grand Prix.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Atari 2600/Adventure (1980) (Atari).nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Atari 2600/Air-Sea Battle (32 in 1) (1988) (Atari) (PAL).nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Atari 2600/Asteroids (1981) (Atari) [no copyright].nfo'))) #FIXME TODO: can't find file even if it exists #self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Nintendo 64/1080° Snowboarding.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'PlayStation/Bushido Blade.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'PlayStation/Silent Hill.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'SNES/Chrono Trigger.nfo'))) self.assertTrue(os.path.isfile(os.path.join(export_base_folder, "SNES/Madden NFL '97.nfo"))) os.remove(os.path.join(export_base_folder, 'Amiga/Airborne Ranger.nfo')) os.remove(os.path.join(export_base_folder, 'Amiga/Chuck Rock.nfo')) os.remove(os.path.join(export_base_folder, 'Amiga/Eliminator.nfo')) os.remove(os.path.join(export_base_folder, 'Amiga/MicroProse Formula One Grand Prix.nfo')) os.remove(os.path.join(export_base_folder, 'Atari 2600/Adventure (1980) (Atari).nfo')) os.remove(os.path.join(export_base_folder, 'Atari 2600/Air-Sea Battle (32 in 1) (1988) (Atari) (PAL).nfo')) os.remove(os.path.join(export_base_folder, 'Atari 2600/Asteroids (1981) (Atari) [no copyright].nfo')) #FIXME TODO: can't find file even if it exists #os.remove(os.path.join(export_base_folder, 'Nintendo 64/1080° Snowboarding.nfo')) os.remove(os.path.join(export_base_folder, 'PlayStation/Bushido Blade.nfo')) os.remove(os.path.join(export_base_folder, 'PlayStation/Silent Hill.nfo')) os.remove(os.path.join(export_base_folder, 'SNES/Chrono Trigger.nfo')) os.remove(os.path.join(export_base_folder, "SNES/Madden NFL '97.nfo")) gdb.close() os.remove(os.path.join(db_path, 'MyGames.db'))
def insertData(self, gamedescription, gamenameFromFile, romCollection, romFiles, foldername, isUpdate, gameId): log.info("Insert data") publisher = self.resolveParseResult(gamedescription, 'Publisher') developer = self.resolveParseResult(gamedescription, 'Developer') year = self.resolveParseResult(gamedescription, 'ReleaseYear') yearId = self.insertForeignKeyItem(gamedescription, 'ReleaseYear', Year(self.gdb)) genreIds = self.insertForeignKeyItemList(gamedescription, 'Genre', Genre(self.gdb)) reviewerId = self.insertForeignKeyItem(gamedescription, 'Reviewer', Reviewer(self.gdb)) publisherId = self.insertForeignKeyItem(gamedescription, 'Publisher', Publisher(self.gdb)) developerId = self.insertForeignKeyItem(gamedescription, 'Developer', Developer(self.gdb)) region = self.resolveParseResult(gamedescription, 'Region') media = self.resolveParseResult(gamedescription, 'Media') controller = self.resolveParseResult(gamedescription, 'Controller') players = self.resolveParseResult(gamedescription, 'Players') rating = self.resolveParseResult(gamedescription, 'Rating') votes = self.resolveParseResult(gamedescription, 'Votes') url = self.resolveParseResult(gamedescription, 'URL') perspective = self.resolveParseResult(gamedescription, 'Perspective') originalTitle = self.resolveParseResult(gamedescription, 'OriginalTitle') alternateTitle = self.resolveParseResult(gamedescription, 'AlternateTitle') translatedBy = self.resolveParseResult(gamedescription, 'TranslatedBy') version = self.resolveParseResult(gamedescription, 'Version') plot = self.resolveParseResult(gamedescription, 'Description') isFavorite = self.resolveParseResult(gamedescription, 'IsFavorite') if isFavorite == '': isFavorite = '0' launchCount = self.resolveParseResult(gamedescription, 'LaunchCount') if launchCount == '': launchCount = '0' if gamedescription is not None: gamename = self.resolveParseResult(gamedescription, 'Game') if gamename != gamenameFromFile: self.possibleMismatchFile.add_entry(gamename, gamenameFromFile) if gamename == "": gamename = gamenameFromFile else: gamename = gamenameFromFile artWorkFound, artworkfiles, artworkurls = self.getArtworkForGame(romCollection, gamename, gamenameFromFile, gamedescription, foldername, publisher, developer) # Create Nfo file with game properties try: genreList = gamedescription.get('Genre', []) writer = NfoWriter() writer.createNfoFromDesc(gamename, plot, romCollection.name, publisher, developer, year, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, version, genreList, isFavorite, launchCount, romFiles[0], gamenameFromFile, artworkfiles, artworkurls) except Exception as e: log.warn(u"Unable to write NFO file for game %s: %s" % (gamename, e)) del publisher, developer, year gameId = self.insertGame(gamename, plot, romCollection.id, publisherId, developerId, reviewerId, yearId, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, translatedBy, version, isFavorite, launchCount, isUpdate, gameId, romCollection.allowUpdate, ) del plot, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, translatedBy, version if gameId is None: return None self.add_genres_to_db(genreIds, gameId) self.add_romfiles_to_db(romFiles, gameId) for fileType, fileNames in artworkfiles.iteritems(): for filename in fileNames: log.info("Importing artwork file %s = %s" % (fileType.type, filename)) self.insertFile(filename, gameId, fileType, romCollection.id, publisherId, developerId) self.gdb.commit() return gameId
def get_nfo_path(self, gamename, platform, romFile): self.nfo_file = NfoWriter().getNfoFilePath(platform, romFile, gamename) return self.nfo_file
def test_createNfoFromDesc_newfile(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' self.assertFalse( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'nfo file should not exist') writer = NfoWriter() game_row = [None] * GameView.NUM_COLUMNS game_row[GameView.COL_NAME] = 'Airborne Ranger' game_row[ GameView. COL_description] = "Description with some special characters: ' & < >" game_row[GameView.COL_publisher] = '"MicroProse"' game_row[GameView.COL_developer] = 'Imagitec' game_row[GameView.COL_year] = '1989' game_row[GameView.COL_maxPlayers] = '1' game_row[GameView.COL_rating] = '3.2' game_row[GameView.COL_numVotes] = '128' game_row[GameView.COL_url] = '' game_row[GameView.COL_region] = 'USA' game_row[GameView.COL_media] = 'Floppy' game_row[GameView.COL_perspective] = 'Top-Down' game_row[GameView.COL_controllerType] = 'Joystick' game_row[GameView.COL_originalTitle] = 'Airborne Ranger' game_row[GameView.COL_alternateTitle] = 'Airborne Ranger' game_row[GameView.COL_version] = 'v1.00' game_row[GameView.COL_genre] = 'Action, Simulation' game_row[GameView.COL_isFavorite] = '1' game_row[GameView.COL_launchCount] = '1' writer.createNfoFromDesc(game_row, 'Amiga', './testdata/roms/Amiga/Airborne Ranger.adf', 'Airborne Ranger', {}, {}) self.assertTrue( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'Expected nfo file to be written') #use nfo scraper to read the file scraper = NFO_Scraper() scraper.nfo_file = './testdata/nfo/Amiga/Airborne Ranger.nfo' result = scraper.retrieve(1, 'Amiga') self.assertEqual(["Airborne Ranger"], result['Game']) self.assertEqual(["Airborne Ranger"], result['OriginalTitle']) self.assertEqual(["Airborne Ranger"], result['AlternateTitle']) self.assertEqual(["1989"], result['ReleaseYear']) self.assertEqual(['"MicroProse"'], result['Publisher']) self.assertEqual(["Imagitec"], result['Developer']) self.assertEqual(["Top-Down"], result['Perspective']) self.assertEqual(["Joystick"], result['Controller']) self.assertEqual(["Floppy"], result['Media']) self.assertEqual(["USA"], result['Region']) self.assertEqual(["v1.00"], result['Version']) self.assertEqual(["1"], result['Players']) self.assertEqual(["1"], result['LaunchCount']) self.assertEqual(["1"], result['IsFavorite']) self.assertEqual(["3.2"], result['Rating']) self.assertEqual(["128"], result['Votes']) self.assertTrue(result['Description'][0].startswith( "Description with some special characters: ' & < >")) self.assertEqual(len(result['Genre']), 2) self.assertIn("Action", result['Genre']) self.assertIn("Simulation", result['Genre']) os.remove('./testdata/nfo/Amiga/Airborne Ranger.nfo')
def test_exportLibrary(self): export_base_folder = './testdata/nfo/export/' xbmcaddon._settings['rcb_nfoFolder'] = export_base_folder # Setup data - MyGames.db is the hard-coded expected DB name db_path = './testdata/database/' shutil.copyfile(os.path.join(db_path, 'MyGames_current_12_games.db'), os.path.join(db_path, 'MyGames.db')) gdb = GameDataBase(db_path) gdb.connect() # Setup config config_xml_file = './testdata/config/romcollections_importtests.xml' conf = Config(config_xml_file) conf.readXml() writer = NfoWriter() writer.exportLibrary(gdb, conf.romCollections) #check if all files have been created self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'Amiga/Airborne Ranger.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'Amiga/Chuck Rock.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'Amiga/Eliminator.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'Amiga/MicroProse Formula One Grand Prix.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'Atari 2600/Adventure (1980) (Atari).nfo'))) self.assertTrue( os.path.isfile( os.path.join( export_base_folder, 'Atari 2600/Air-Sea Battle (32 in 1) (1988) (Atari) (PAL).nfo' ))) self.assertTrue( os.path.isfile( os.path.join( export_base_folder, 'Atari 2600/Asteroids (1981) (Atari) [no copyright].nfo'))) #FIXME TODO: can't find file even if it exists #self.assertTrue(os.path.isfile(os.path.join(export_base_folder, 'Nintendo 64/1080° Snowboarding.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'PlayStation/Bushido Blade.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'PlayStation/Silent Hill.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, 'SNES/Chrono Trigger.nfo'))) self.assertTrue( os.path.isfile( os.path.join(export_base_folder, "SNES/Madden NFL '97.nfo"))) os.remove(os.path.join(export_base_folder, 'Amiga/Airborne Ranger.nfo')) os.remove(os.path.join(export_base_folder, 'Amiga/Chuck Rock.nfo')) os.remove(os.path.join(export_base_folder, 'Amiga/Eliminator.nfo')) os.remove( os.path.join(export_base_folder, 'Amiga/MicroProse Formula One Grand Prix.nfo')) os.remove( os.path.join(export_base_folder, 'Atari 2600/Adventure (1980) (Atari).nfo')) os.remove( os.path.join( export_base_folder, 'Atari 2600/Air-Sea Battle (32 in 1) (1988) (Atari) (PAL).nfo') ) os.remove( os.path.join( export_base_folder, 'Atari 2600/Asteroids (1981) (Atari) [no copyright].nfo')) #FIXME TODO: can't find file even if it exists #os.remove(os.path.join(export_base_folder, 'Nintendo 64/1080° Snowboarding.nfo')) os.remove( os.path.join(export_base_folder, 'PlayStation/Bushido Blade.nfo')) os.remove( os.path.join(export_base_folder, 'PlayStation/Silent Hill.nfo')) os.remove(os.path.join(export_base_folder, 'SNES/Chrono Trigger.nfo')) os.remove(os.path.join(export_base_folder, "SNES/Madden NFL '97.nfo")) gdb.close() os.remove(os.path.join(db_path, 'MyGames.db'))
def test_createNfoFromDesc_newfile_missinginfos(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' self.assertFalse( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'nfo file should not exist') writer = NfoWriter() game_row = [None] * GameView.NUM_COLUMNS game_row[GameView.COL_NAME] = 'Airborne Ranger' game_row[GameView.COL_description] = '' game_row[GameView.COL_publisher] = '' game_row[GameView.COL_developer] = '' game_row[GameView.COL_year] = '' game_row[GameView.COL_maxPlayers] = '' game_row[GameView.COL_rating] = '' game_row[GameView.COL_numVotes] = '' game_row[GameView.COL_url] = '' game_row[GameView.COL_region] = '' game_row[GameView.COL_media] = '' game_row[GameView.COL_perspective] = '' game_row[GameView.COL_controllerType] = '' game_row[GameView.COL_originalTitle] = '' game_row[GameView.COL_alternateTitle] = '' game_row[GameView.COL_version] = '' game_row[GameView.COL_genre] = '' game_row[GameView.COL_isFavorite] = '' game_row[GameView.COL_launchCount] = '' writer.createNfoFromDesc(game_row, 'Amiga', './testdata/roms/Amiga/Airborne Ranger.adf', 'Airborne Ranger', {}, {}) self.assertTrue( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'Expected nfo file to be written') #use nfo scraper to read the file scraper = NFO_Scraper() scraper.nfo_file = './testdata/nfo/Amiga/Airborne Ranger.nfo' result = scraper.retrieve(1, 'Amiga') self.assertEqual(["Airborne Ranger"], result['Game']) self.assertEqual([None], result['OriginalTitle']) self.assertEqual([None], result['AlternateTitle']) self.assertEqual([None], result['ReleaseYear']) self.assertEqual([None], result['Publisher']) self.assertEqual([None], result['Developer']) self.assertEqual([None], result['Perspective']) self.assertEqual([None], result['Controller']) self.assertEqual([None], result['Media']) self.assertEqual([None], result['Region']) self.assertEqual([None], result['Version']) self.assertEqual([None], result['Players']) self.assertEqual([None], result['LaunchCount']) self.assertEqual([None], result['IsFavorite']) self.assertEqual([None], result['Rating']) self.assertEqual([None], result['Votes']) self.assertEqual([None], result['Description']) self.assertEqual(len(result['Genre']), 0) os.remove('./testdata/nfo/Amiga/Airborne Ranger.nfo')
def test_createNfoFromDesc_newfile(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' self.assertFalse(os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'nfo file should not exist') writer = NfoWriter() writer.createNfoFromDesc('Airborne Ranger', #gamename "Description with some special characters: ' & < >", #plot 'Amiga', #romCollectionname '"MicroProse"', #publisher 'Imagitec', #developer '1989', #year '1', #players '3.2', #rating '128', #votes '', #url 'USA', #region 'Floppy', #media 'Top-Down', #perspective 'Joystick', #controller 'Airborne Ranger', #originalTitle 'Airborne Ranger', #alternateTitle 'v1.00', #version ['Action', 'Simulation'], #genreList '1', #isFavorite '1', #launchCount './testdata/roms/Amiga/Airborne Ranger.adf', #romFile 'Airborne Ranger', #gamenameFromFile {}, #artworkfiles {} #artworkurls ) self.assertTrue(os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'Expected nfo file to be written') #use nfo scraper to read the file scraper = NFO_Scraper() scraper.nfo_file = './testdata/nfo/Amiga/Airborne Ranger.nfo' result = scraper.retrieve(1, 'Amiga') self.assertEqual(["Airborne Ranger"], result['Game']) self.assertEqual(["Airborne Ranger"], result['OriginalTitle']) self.assertEqual(["Airborne Ranger"], result['AlternateTitle']) self.assertEqual(["1989"], result['ReleaseYear']) self.assertEqual(['"MicroProse"'], result['Publisher']) self.assertEqual(["Imagitec"], result['Developer']) self.assertEqual(["Top-Down"], result['Perspective']) self.assertEqual(["Joystick"], result['Controller']) self.assertEqual(["Floppy"], result['Media']) self.assertEqual(["USA"], result['Region']) self.assertEqual(["v1.00"], result['Version']) self.assertEqual(["1"], result['Players']) self.assertEqual(["1"], result['LaunchCount']) self.assertEqual(["1"], result['IsFavorite']) self.assertEqual(["3.2"], result['Rating']) self.assertEqual(["128"], result['Votes']) self.assertTrue(result['Description'][0].startswith( "Description with some special characters: ' & < >")) self.assertEqual(len(result['Genre']), 2) self.assertIn("Action", result['Genre']) self.assertIn("Simulation", result['Genre']) os.remove('./testdata/nfo/Amiga/Airborne Ranger.nfo')
def test_createNfoFromDesc_newfile(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' self.assertFalse( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'nfo file should not exist') writer = NfoWriter() writer.createNfoFromDesc( 'Airborne Ranger', #gamename "Description with some special characters: ' & < >", #plot 'Amiga', #romCollectionname '"MicroProse"', #publisher 'Imagitec', #developer '1989', #year '1', #players '3.2', #rating '128', #votes '', #url 'USA', #region 'Floppy', #media 'Top-Down', #perspective 'Joystick', #controller 'Airborne Ranger', #originalTitle 'Airborne Ranger', #alternateTitle 'v1.00', #version ['Action', 'Simulation'], #genreList '1', #isFavorite '1', #launchCount './testdata/roms/Amiga/Airborne Ranger.adf', #romFile 'Airborne Ranger', #gamenameFromFile {}, #artworkfiles {} #artworkurls ) self.assertTrue( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'Expected nfo file to be written') #use nfo scraper to read the file scraper = NFO_Scraper() scraper.nfo_file = './testdata/nfo/Amiga/Airborne Ranger.nfo' result = scraper.retrieve(1, 'Amiga') self.assertEqual(["Airborne Ranger"], result['Game']) self.assertEqual(["Airborne Ranger"], result['OriginalTitle']) self.assertEqual(["Airborne Ranger"], result['AlternateTitle']) self.assertEqual(["1989"], result['ReleaseYear']) self.assertEqual(['"MicroProse"'], result['Publisher']) self.assertEqual(["Imagitec"], result['Developer']) self.assertEqual(["Top-Down"], result['Perspective']) self.assertEqual(["Joystick"], result['Controller']) self.assertEqual(["Floppy"], result['Media']) self.assertEqual(["USA"], result['Region']) self.assertEqual(["v1.00"], result['Version']) self.assertEqual(["1"], result['Players']) self.assertEqual(["1"], result['LaunchCount']) self.assertEqual(["1"], result['IsFavorite']) self.assertEqual(["3.2"], result['Rating']) self.assertEqual(["128"], result['Votes']) self.assertTrue(result['Description'][0].startswith( "Description with some special characters: ' & < >")) self.assertEqual(len(result['Genre']), 2) self.assertIn("Action", result['Genre']) self.assertIn("Simulation", result['Genre']) os.remove('./testdata/nfo/Amiga/Airborne Ranger.nfo')
def test_createNfoFromDesc_newfile_missinginfos(self): xbmcaddon._settings['rcb_nfoFolder'] = './testdata/nfo/' self.assertFalse( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'nfo file should not exist') writer = NfoWriter() writer.createNfoFromDesc( 'Airborne Ranger', #gamename '', #plot 'Amiga', #romCollectionname '', #publisher '', #developer '', #year '', #players '', #rating '', #votes '', #url '', #region '', #media '', #perspective '', #controller '', #originalTitle '', #alternateTitle '', #version [], #genreList '', #isFavorite '', #launchCount './testdata/roms/Amiga/Airborne Ranger.adf', #romFile 'Airborne Ranger', #gamenameFromFile {}, #artworkfiles {} #artworkurls ) self.assertTrue( os.path.isfile('./testdata/nfo/Amiga/Airborne Ranger.nfo'), 'Expected nfo file to be written') #use nfo scraper to read the file scraper = NFO_Scraper() scraper.nfo_file = './testdata/nfo/Amiga/Airborne Ranger.nfo' result = scraper.retrieve(1, 'Amiga') self.assertEqual(["Airborne Ranger"], result['Game']) self.assertEqual([None], result['OriginalTitle']) self.assertEqual([None], result['AlternateTitle']) self.assertEqual([None], result['ReleaseYear']) self.assertEqual([None], result['Publisher']) self.assertEqual([None], result['Developer']) self.assertEqual([None], result['Perspective']) self.assertEqual([None], result['Controller']) self.assertEqual([None], result['Media']) self.assertEqual([None], result['Region']) self.assertEqual([None], result['Version']) self.assertEqual([None], result['Players']) self.assertEqual([None], result['LaunchCount']) self.assertEqual([None], result['IsFavorite']) self.assertEqual([None], result['Rating']) self.assertEqual([None], result['Votes']) self.assertEqual([None], result['Description']) self.assertEqual(len(result['Genre']), 0) os.remove('./testdata/nfo/Amiga/Airborne Ranger.nfo')
def insertData(self, gamedescription, gamenameFromFile, romCollection, romFiles, foldername, isUpdate, gameId): log.info("Insert data") publisher = self.resolveParseResult(gamedescription, 'Publisher') developer = self.resolveParseResult(gamedescription, 'Developer') year = self.resolveParseResult(gamedescription, 'ReleaseYear') yearId = self.insertForeignKeyItem(gamedescription, 'ReleaseYear', Year(self.gdb)) genreIds = self.insertForeignKeyItemList(gamedescription, 'Genre', Genre(self.gdb)) reviewerId = self.insertForeignKeyItem(gamedescription, 'Reviewer', Reviewer(self.gdb)) publisherId = self.insertForeignKeyItem(gamedescription, 'Publisher', Publisher(self.gdb)) developerId = self.insertForeignKeyItem(gamedescription, 'Developer', Developer(self.gdb)) region = self.resolveParseResult(gamedescription, 'Region') media = self.resolveParseResult(gamedescription, 'Media') controller = self.resolveParseResult(gamedescription, 'Controller') players = self.resolveParseResult(gamedescription, 'Players') rating = self.resolveParseResult(gamedescription, 'Rating') votes = self.resolveParseResult(gamedescription, 'Votes') url = self.resolveParseResult(gamedescription, 'URL') perspective = self.resolveParseResult(gamedescription, 'Perspective') originalTitle = self.resolveParseResult(gamedescription, 'OriginalTitle') alternateTitle = self.resolveParseResult(gamedescription, 'AlternateTitle') translatedBy = self.resolveParseResult(gamedescription, 'TranslatedBy') version = self.resolveParseResult(gamedescription, 'Version') plot = self.resolveParseResult(gamedescription, 'Description') isFavorite = self.resolveParseResult(gamedescription, 'IsFavorite') if isFavorite == '': isFavorite = '0' launchCount = self.resolveParseResult(gamedescription, 'LaunchCount') if launchCount == '': launchCount = '0' if gamedescription is not None: gamename = self.resolveParseResult(gamedescription, 'Game') if gamename != gamenameFromFile: self.possibleMismatchFile.add_entry(gamename, gamenameFromFile) if gamename == "": gamename = gamenameFromFile else: gamename = gamenameFromFile artWorkFound, artworkfiles, artworkurls = self.getArtworkForGame( romCollection, gamename, gamenameFromFile, gamedescription, foldername, publisher, developer) # Create Nfo file with game properties try: genreList = gamedescription.get('Genre', []) writer = NfoWriter() writer.createNfoFromDesc( gamename, plot, romCollection.name, publisher, developer, year, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, version, genreList, isFavorite, launchCount, romFiles[0], gamenameFromFile, artworkfiles, artworkurls) except Exception as e: log.warn(u"Unable to write NFO file for game %s: %s" % (gamename, e)) del publisher, developer, year gameId = self.insertGame( gamename, plot, romCollection.id, publisherId, developerId, reviewerId, yearId, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, translatedBy, version, isFavorite, launchCount, isUpdate, gameId, romCollection.allowUpdate, ) del plot, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, translatedBy, version if gameId is None: return None self.add_genres_to_db(genreIds, gameId) self.add_romfiles_to_db(romFiles, gameId) for fileType, fileNames in artworkfiles.iteritems(): for filename in fileNames: log.info("Importing artwork file %s = %s" % (fileType.type, filename)) self.insertFile(filename, gameId, fileType, romCollection.id, publisherId, developerId) self.gdb.commit() return gameId