def verify(self, console): if console.emulator is None: logger.debug("No emulator provided for console `%s`" % console.fullname) #return False #We don't want to return false here anymore, because we want non-setup emulators to work still return True
def findArtWorkUrl(self, gameId): url = self.api_url_getArt() + str(gameId) try: response = self.http_get(url) body = response.content xmlResult = xml.etree.ElementTree.fromstring(body) baseImgUrl = xmlResult._children[0].text imagesXml = xmlResult._children[1] imgUrl = None # try to find a fanart boxarts = imagesXml.findall("boxart") frontBoxArt = self.findFrontBoxArt(boxarts) if frontBoxArt is not None: imgUrl = frontBoxArt.text else: fanart = imagesXml.find("fanart") if fanart is not None: imgUrl = fanart.text else: if len(imagesXml._children) > 0: # take any image which is available imgUrl = imagesXml._children[0].text if imgUrl is not None: return baseImgUrl + imgUrl else: return None except IOError as error: logger.debug("There was an error contacting %s" % url)
def rgc_get_result(self, url): try: response = urllib.urlopen(url) return json.loads(response.read())["results"] except IOError as error: logger.debug("There was an error contacting Retrogaming.cloud") return None
def image_for_rom(self, rom): if not os.path.exists('hash.csv'): f = urllib2.urlopen( 'https://raw.githubusercontent.com/sselph/scraper/master/hash.csv' ) with open('hash.csv', 'w') as hashfile: hashfile.write(f.read()) gameid = None title = None for method in ( 'md5', ): # map(lambda m: getattr(hashlib,m), hashlib.algorithms): hash = self.rom_hash(rom.path) gameid, title = self.find_hash_id_and_title(hash) if gameid is not None: break if gameid is None: logger.debug('Did not find hash for %s', rom.path) return None query = urllib.urlencode({'id': gameid}) xml_url = urlparse.urlunparse( ('http', 'thegamesdb.net', '/api/GetArt.php', '', query, '')) try: image_url = self.get_image_url(xml_url) except Exception: logger.exception('Error parsing thegamesdb xml %s', xml_url) return None logger.debug('Hash-based image found: %s %s', rom.path, image_url) if image_url is None or image_url == "": return None return self.download_image(image_url)
def verify(self, console): if console.emulator is None: logger.debug("No emulator provided for console `%s`" % console.fullname) return False return True
def __init__(self, steam): self.steam = steam logger.debug("Initializing Ice") # We want to ignore the anonymous context, cause theres no reason to sync # ROMs for it since you cant log in as said user. is_user_context = lambda context: context.user_id != 'anonymous' self.users = filter(is_user_context, steam_module.local_user_contexts(self.steam))
def searchTheGamesDb(self, rom): url = self.api_url_findId() + str(rom.name) try: response = self.http_get(url) body = response.content gameList = xml.etree.ElementTree.fromstring(body) foundImage = self.findImageForPlattformGame(gameList, rom) return foundImage except IOError as error: logger.debug("There was an error contacting %s" % url)
def __call__(self, users, roms, dry_run): for user in users: if dry_run: logger.debug("Not creating backup because its a dry run") else: logger.info("::Backing up shortcuts for U:%s" % user.user_id) backups.create_backup_of_shortcuts(self.app_settings.config, user) logger.info("::Syncing Shortcuts for U:%s" % user.user_id) self.shortcut_synchronizer.sync_roms_for_user(user, roms, self.app_settings.consoles, dry_run=dry_run)
def __init__(self, steam): self.steam = steam logger.debug("Initializing Ice") # We want to ignore the anonymous context, cause theres no reason to sync # ROMs for it since you cant log in as said user. self.users = [ item for item in steam_module.local_user_contexts(self.steam) if item.user_id != 'anonymous' ]
def _create_backup(self, user, dry_run=False): if dry_run: logger.debug("Not creating backup because its a dry run") return backup_path = self.config.shortcuts_backup_path(user) if backup_path is None: logger.info("No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info") return shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
def parse(self, path): """Parses the name of the ROM given its path.""" filename = os.path.basename(path) opts = re.IGNORECASE match = reduce(lambda match, regex: match if match else re.match(regex, filename, opts), self.regexes, None) if match: logger.debug("[ROMParser] Matched game '%s' using regular expression `%s`", filename, match.re.pattern) name = match.groupdict()["name"] else: logger.debug("[ROMParser] No match found for '%s'", filename) name = filename return name.strip()
def convertToSteamBannerImage(self, oldImagePath): try: background = self.__createGaussianBackground(oldImagePath) foreground = self.resizeToHeight(self.STEAM_BANNER_HEIGHT(), oldImagePath) background.paste( foreground, (background.size[0] / 2 - foreground.size[0] / 2, 0)) background.save(oldImagePath) except IOError as error: logger.debug("There was an error converting the image " + oldImagePath + ": " + error.message)
def _create_backup(self, user, dry_run=False): if dry_run: logger.debug("Not creating backup because its a dry run") return backup_path = self.config.shortcuts_backup_path(user) if backup_path is None: logger.info( "No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info" ) return shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
def parse(self, path): """Parses the name of the ROM given its path.""" basename = os.path.basename(path) (filename, ext) = os.path.splitext(basename) opts = re.IGNORECASE match = reduce(lambda match, regex: match if match else re.match(regex, filename, opts), self.regexes, None) if match: logger.debug("Matched game '%s' as %s using regular expression `%s`", filename, str(match.groupdict()), match.re.pattern) name = match.groupdict()["name"] else: logger.debug("No match found for '%s'", filename) name = filename return name.strip()
def download_image(self, url): filetype = self.getFileType(url) logger.debug("Downloading %s \n Extrated filetype: %s " % (url, filetype)) if filetype is not None and len(filetype) > 3: from tempfile import mkstemp fd, path = mkstemp(suffix=filetype) response = requests.get(url, stream=True) with open(path, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response return path
def __init__(self, steam, filesystem, app_settings): self.steam = steam self.filesystem = filesystem # We want to ignore the anonymous context, cause theres no reason to sync # ROMs for it since you cant log in as said user. is_user_context = lambda context: context.user_id != 'anonymous' self.users = filter(is_user_context, steam_module.local_user_contexts(self.steam)) logger.debug("Initializing Ice") self.app_settings = app_settings parser = ROMParser() self.rom_finder = ROMFinder(app_settings.config, filesystem, parser)
def __init__(self, steam, filesystem, app_settings,options): self.app = Qt.QApplication(sys.argv) QtWidgets.QMainWindow.__init__(self) self.steam = steam self.filesystem = filesystem is_user_context = lambda context: context.user_id != 'anonymous' self.users = filter(is_user_context, steam_module.local_user_contexts(self.steam)) logger.debug("Initializing Ice") self.app_settings = app_settings parser = ROMParser() self.rom_finder = ROMFinder(app_settings.config, filesystem, parser) self.options = options
def __call__(self, app_settings, users, dry_run): roms = self.rom_finder.roms_for_consoles( app_settings.config, app_settings.consoles, ) managed_rom_archive = history.ManagedROMArchive(paths.archive_path()) shortcut_synchronizer = SteamShortcutSynchronizer(app_settings.config, managed_rom_archive) for user in users: if dry_run: logger.debug("Not creating backup because its a dry run") else: logger.info("::Backing up shortcuts for U:%s" % user.user_id) backups.create_backup_of_shortcuts(app_settings.config, user) logger.info("::Syncing Shortcuts for U:%s" % user.user_id) shortcut_synchronizer.sync_roms_for_user(user, roms, app_settings.consoles, dry_run=dry_run)
def find_url_for_rom(self, rom): """ Determines a suitable grid image for a given ROM by hitting ConsoleGrid.com """ try: response = request.urlopen(self.consolegrid_top_picture_url(rom)) if response.getcode() == 204: name = rom.name console = rom.console.fullname logger.debug("ConsoleGrid has no game called `%s` for %s" % (name, console)) else: return response.read() except error.URLError as err: # Connection was refused. ConsoleGrid may be down, or something bad # may have happened logger.debug( "No image was downloaded due to an error with ConsoleGrid")
def __init__(self, steam, filesystem, options): """Valid options for creating an IceEngine are as follows: * config - The path to the config file to use. Searches the default paths for 'config.txt' otherwise * consoles - The path to the consoles file to use. Searches the default paths for 'consoles.txt' if none is provided * emulators - The path to the emulators file to use. Searches the default paths for 'emulators.txt' if none is provided """ self.validated_base_environment = False self.validated_configuration = False self.filesystem = filesystem logger.debug("Initializing Ice") config_data_path = _path_with_override(filesystem, options.config, "config.txt") consoles_data_path = _path_with_override(filesystem, options.consoles, "consoles.txt") emulators_data_path = _path_with_override(filesystem, options.emulators, "emulators.txt") self.config = Configuration( ConfigFileBackingStore(config_data_path), ConfigFileBackingStore(consoles_data_path), ConfigFileBackingStore(emulators_data_path), filesystem, ) self.steam = steam parser = ROMParser() self.rom_finder = ROMFinder(self.config, filesystem, parser) archive_data_path = paths.highest_precedent_data_file( filesystem, "archive.json") managed_rom_archive = ManagedROMArchive(archive_data_path) self.shortcut_synchronizer = SteamShortcutSynchronizer( managed_rom_archive) provider = CombinedProvider( LocalProvider(), ConsoleGridProvider(), ) self.grid_updater = SteamGridUpdater(provider)
def find_url_for_rom(self, rom): """ Determines a suitable grid image for a given ROM by hitting ConsoleGrid.com """ try: response = urllib2.urlopen(self.consolegrid_top_picture_url(rom)) if response.getcode() == 204: name = rom.name console = rom.console.fullname logger.debug( "ConsoleGrid has no game called `%s` for %s" % (name, console) ) else: return response.read() except urllib2.URLError as error: # Connection was refused. ConsoleGrid may be down, or something bad # may have happened logger.debug( "No image was downloaded due to an error with ConsoleGrid" )
def image_for_rom(self, rom): """ Checks the filesystem for images for a given ROM. To do so, it makes use of a consoles 'images' directory. If it finds an image in that directory with the same name as the ROMs name then it will return that. """ img_dir = rom.console.images_directory if img_dir == "": logger.debug("[%s] No images directory specified for %s" % (rom.name, rom.console.shortname)) return None for extension in self.valid_extensions(): filename = rom.name + extension path = os.path.join(img_dir, filename) if os.path.isfile(path): # We found a valid path, return it return path # We went through all of the possible filenames for this ROM and a # file didnt exist with any of them. There is no image for this ROM in # the consoles image directory return None
def image_for_rom(self, rom): """ Checks the filesystem for images for a given ROM. To do so, it makes use of a consoles 'images' directory. If it finds an image in that directory with the same name as the ROMs name then it will return that. """ img_dir = rom.console.images_directory if img_dir == "": logger.debug( "[%s] No images directory specified for %s" % (rom.name, rom.console.shortname) ) return None for extension in self.valid_extensions(): filename = rom.name + extension path = os.path.join(img_dir, filename) if os.path.isfile(path): # We found a valid path, return it return path # We went through all of the possible filenames for this ROM and a # file didnt exist with any of them. There is no image for this ROM in # the consoles image directory return None
def find_url_for_rom(self, rom): """ Determines a suitable grid image for a given ROM by hitting ConsoleGrid.com """ try: response = requests.get(self.api_url, params={ 'console': rom.console.shortname, 'game': rom.name }) if response.status_code == 204: name = rom.name console = rom.console.fullname logger.debug("ConsoleGrid has no game called `%s` for %s" % (name, console)) else: return response.text except requests.ConnectionError as error: # Connection was refused. ConsoleGrid may be down, or something bad # may have happened logger.debug( "No image was downloaded due to an error with ConsoleGrid")
def __init__(self, steam, filesystem, options): """Valid options for creating an IceEngine are as follows: * config - The path to the config file to use. Searches the default paths for 'config.txt' otherwise * consoles - The path to the consoles file to use. Searches the default paths for 'consoles.txt' if none is provided * emulators - The path to the emulators file to use. Searches the default paths for 'emulators.txt' if none is provided """ self.validated_base_environment = False self.validated_configuration = False self.filesystem = filesystem logger.debug("Initializing Ice") config_data_path = _path_with_override(filesystem, options.config, "config.txt") consoles_data_path = _path_with_override(filesystem, options.consoles, "consoles.txt") emulators_data_path = _path_with_override(filesystem, options.emulators, "emulators.txt") self.config = Configuration( ConfigFileBackingStore(config_data_path), ConfigFileBackingStore(consoles_data_path), ConfigFileBackingStore(emulators_data_path), filesystem, ) self.steam = steam parser = ROMParser() self.rom_finder = ROMFinder(self.config, filesystem, parser) archive_data_path = paths.highest_precedent_data_file(filesystem, "archive.json") managed_rom_archive = ManagedROMArchive(archive_data_path) self.shortcut_synchronizer = SteamShortcutSynchronizer(managed_rom_archive) provider = CombinedProvider( LocalProvider(), ConsoleGridProvider(), ) self.grid_updater = SteamGridUpdater(provider)
def log_configuration(config): logger.debug("Using `config.txt` at `%s`" % config.config_backing_store.path) logger.debug("Using `consoles.txt` at `%s`" % config.console_manager.backing_store.path) logger.debug("Using `emulators.txt` at `%s`" % config.emulator_manager.backing_store.path) for emulator in config.emulator_manager: log_emulator_state(emulator) for console in config.console_manager: log_console_state(console)
def log_configuration(config): logger.debug("Using `config.txt` at `%s`" % config.config_backing_store.path) logger.debug( "Using `consoles.txt` at `%s`" % config.console_manager.backing_store.path) logger.debug( "Using `emulators.txt` at `%s`" % config.emulator_manager.backing_store.path) for emulator in config.emulator_manager: log_emulator_state(emulator) for console in config.console_manager: log_console_state(console)
def __init__(self): logger.debug("Creating ROM parser with regexes: %s" % self.regexes)
def image_for_rom(self, rom): image_url = self.find_url_for_rom(rom) if image_url is None or image_url == "": return None logger.debug('Found consolegrid image %s %s', rom.path, image_url) return self.download_image(image_url)