def get_installer_script(installer): script = load_yaml(installer.content) if not script: return {} if not isinstance(script, dict): raise TypeError("Malformed script") return script
def as_dict(self, with_metadata=True): try: yaml_content = load_yaml(self.content) or {} except yaml.parser.ParserError: LOGGER.exception("Invalid YAML %s", self.content) yaml_content = {} # Allow pasting raw install scripts (which are served as lists) if isinstance(yaml_content, list): yaml_content = yaml_content[0] # If yaml content evaluates to a string return an empty dict if isinstance(yaml_content, six.string_types): return {} # Do not add metadata if the clean argument has been passed if with_metadata: yaml_content["game_slug"] = self.game.slug yaml_content["version"] = self.version yaml_content["description"] = self.description yaml_content["notes"] = self.notes yaml_content["name"] = self.game.name yaml_content["year"] = self.game.year yaml_content["steamid"] = self.game.steamid yaml_content["gogslug"] = self.game.gogslug yaml_content["humblestoreid"] = self.game.humblestoreid try: yaml_content["runner"] = self.runner.slug except ObjectDoesNotExist: yaml_content["runner"] = "" # Set slug to both slug and installer_slug for backward compatibility # reasons with the client. Remove installer_slug sometime in the future yaml_content["slug"] = self.slug yaml_content["installer_slug"] = self.slug return yaml_content
def clean_content(self): """Verify that the content field is valid yaml""" yaml_data = self.cleaned_data["content"] try: yaml_data = load_yaml(yaml_data) except yaml.error.MarkedYAMLError as ex: raise forms.ValidationError( "Invalid YAML, problem at line %s, %s" % (ex.problem_mark.line, ex.problem)) return dump_yaml(yaml_data)
def get_installer_data(self): """Return the data saved in the revision in an usable format""" installer_data = json.loads(self._version.serialized_data)[0]["fields"] installer_data["script"] = load_yaml(installer_data["content"]) installer_data["id"] = self.id # Return a defaultdict to prevent key errors for new fields that # weren't present in previous revisions default_installer_data = defaultdict(str) default_installer_data.update(installer_data) return default_installer_data
def clean_content(self): """Verify that the content field is valid yaml""" yaml_data = self.cleaned_data["content"] try: yaml_data = load_yaml(yaml_data) except yaml.error.MarkedYAMLError as ex: raise forms.ValidationError( "Invalid YAML, problem at line %s, %s" % (ex.problem_mark.line, ex.problem) ) return dump_yaml(yaml_data)
def add_arch_to_non_wine_installers(self, installer): script_updated = False script = load_yaml(installer.content) for step in [step for step in script["installer"] if "task" in step]: task = step["task"] if task["name"] == "wine.wineexec" and "arch" not in task: step["task"]["arch"] = "win32" script_updated = True if script_updated: installer.content = dump_yaml(script) return script_updated
def add_arch_to_non_wine_installers(self, installer): script_updated = False script = load_yaml(installer.content) for step in [step for step in script['installer'] if 'task' in step]: task = step['task'] if task['name'] == 'wine.wineexec' and 'arch' not in task: step['task']['arch'] = 'win32' script_updated = True if script_updated: installer.content = dump_yaml(script) return script_updated
def get_installer_data(self): installer_data = json.loads(self._version.serialized_data)[0]["fields"] try: installer_data["script"] = load_yaml(installer_data["content"]) except (yaml.scanner.ScannerError, yaml.parser.ParserError) as ex: LOGGER.exception(ex) installer_data["script"] = ["This installer is f'd up."] installer_data["id"] = self.id # Return a defaultdict to prevent key errors for new fields that # weren't present in previous revisions default_installer_data = defaultdict(str) default_installer_data.update(installer_data) return default_installer_data
def add_arch_to_wine_installers(self, installer): script_updated = False script = load_yaml(installer.content) try: game_config = script.get("game", {}) except AttributeError: LOGGER.error("The script %s is invalid", installer.slug) return False # Intaller ahs arch, we're good if game_config.get("arch") in ("win32", "win64"): # Game has architecture already set return False if game_config.get("arch"): raise ValueError("Weird value for arch: %s", game_config["arch"]) # Set a prefix so the game doesn't use ~/.wine if "prefix" not in game_config: LOGGER.warning("No prefix found for %s", installer.slug) detected_prefix = None for task in [ step for step in script.get("installer", []) if "task" in step ]: if "prefix" in task: if detected_prefix and detected_prefix != task["prefix"]: raise ValueError("Different values of prefixes found") detected_prefix = task["prefix"] if not detected_prefix: detected_prefix = "$GAMEDIR" LOGGER.info("Setting prefix to %s", detected_prefix) game_config["prefix"] = detected_prefix script_updated = True if "Program Files (x86)" in installer.content: LOGGER.info("%s is a 64bit game?", installer.slug) detected_arch = "win64" else: detected_arch = "win32" LOGGER.info("Setting arch for %s to %s", installer.slug, detected_arch) game_config["arch"] = detected_arch script_updated = True if script_updated: script["game"] = game_config installer.content = dump_yaml(script) return True
def handle(self, *args, **kwargs): self.stdout.write("Installer stats\n") installers = models.Installer.objects.all() command_stats = {} for installer in installers: slug = installer.slug installer_content = load_yaml(installer.content) commands = installer_content.get("installer", []) for command in commands: command_key = command.keys()[0] if command_key not in command_stats: command_stats[command_key] = set() command_stats[command_key].add(installer.slug) for command in command_stats: self.stdout.write(command) for slug in command_stats[command]: self.stdout.write("\t" + slug)
def add_arch_to_wine_installers(self, installer): script_updated = False script = load_yaml(installer.content) try: game_config = script.get('game', {}) except AttributeError: LOGGER.error("The script %s is invalid", installer.slug) return False # Intaller ahs arch, we're good if game_config.get('arch') in ('win32', 'win64'): # Game has architecture already set return False if game_config.get('arch'): raise ValueError("Weird value for arch: %s", game_config['arch']) # Set a prefix so the game doesn't use ~/.wine if 'prefix' not in game_config: LOGGER.warning("No prefix found for %s", installer.slug) detected_prefix = None for task in [step for step in script.get('installer', []) if 'task' in step]: if 'prefix' in task: if detected_prefix and detected_prefix != task['prefix']: raise ValueError("Different values of prefixes found") detected_prefix = task['prefix'] if not detected_prefix: detected_prefix = '$GAMEDIR' LOGGER.info("Setting prefix to %s", detected_prefix) game_config['prefix'] = detected_prefix script_updated = True if 'Program Files (x86)' in installer.content: LOGGER.info("%s is a 64bit game?", installer.slug) detected_arch = 'win64' else: detected_arch = 'win32' LOGGER.info("Setting arch for %s to %s", installer.slug, detected_arch) game_config['arch'] = detected_arch script_updated = True if script_updated: script['game'] = game_config installer.content = dump_yaml(script) return True
def handle(self, *args, **options): """Enables DXVK where D9VK was active before and removes all D9VK attributes and dxvk_version from installers.""" dry_run = options.get('dry_run') installers = Installer.objects.filter( Q(content__icontains="d9vk") | Q(content__icontains="dxvk_version")) for installer in installers: script = load_yaml(installer.content) changed = Command.clean_up_dxvk_d9vk(script, installer.slug) if not changed: continue installer.content = dump_yaml(script) if dry_run: LOGGER.info("Dry run only, not saving installer %s", installer) else: LOGGER.info("Saving installer %s", installer) installer.save()
def write_as_conf_and_path_policy(isd_as, as_obj, instance_path, bf, bs): """ Writes AS configuration (i.e. as.yml) and path policy files. :param ISD_AS isd_as: ISD-AS for which the config will be written. :param obj as_obj: An object that stores crypto information for AS :param str instance_path: Location (in the file system) to write the configuration into. """ conf = { # 'MasterASKey': as_obj.keys['master_as_key'], 'RegisterTime': bf, 'PropagateTime': bf, 'CertChainVersion': 0, 'RegisterPath': True, 'PathSegmentTTL': 21600, } conf_file = os.path.join(instance_path, AS_CONF_FILE) write_file(conf_file, yaml.dump(conf, default_flow_style=False)) path_policy_file = os.path.join(PROJECT_ROOT, DEFAULT_PATH_POLICY_FILE) path_policy = load_yaml(path_policy_file) path_policy['BestSetSize'] = bs write_yaml(os.path.join(instance_path, PATH_POLICY_FILE), path_policy)
def handle(self, *args, **options): """Removes specified Wine versions from all installers.""" dry_run = options.get('dry_run') # Search for installers that have a Wine version specified. installers = Installer.objects.filter( (Q(content__contains="\nwine:") | Q(content__contains="\nwinesteam:")) & Q(content__contains=" version: ")) for installer in installers: script = load_yaml(installer.content) changed = self.remove_wine_version( script, installer.slug, ) if not changed: continue installer.content = dump_yaml(script) if dry_run: LOGGER.info("Not saving installer %s, dry run only", installer) else: LOGGER.info("Updating installer %s", installer) installer.save()