def _ReadArgGroupsFromFile(arg_file): """Collects all the arg groups defined in the yaml file into a dictionary. Each dictionary key is an arg-group name whose corresponding value is a nested dictionary containing arg-name: arg-value pairs defined in that group. Args: arg_file: str, the name of the YAML argument file to open and parse. Returns: A dict containing all arg-groups found in the arg_file. Raises: yaml.Error: If the YAML file could not be read or parsed. BadFileException: If the contents of the file are not valid. """ all_groups = {} for d in yaml.load_all_path(arg_file): if d is None: log.warning('Ignoring empty yaml document.') elif isinstance(d, dict): all_groups.update(d) else: raise calliope_exceptions.BadFileException( 'Failed to parse YAML file [{}]: [{}] is not a valid argument ' 'group.'.format(arg_file, str(d))) return all_groups
def _ReadArgGroupsFromFile(arg_file): """Collects all the arg groups defined in the yaml file into a dictionary. Each dictionary key is an arg-group name whose corresponding value is a nested dictionary containing arg-name: arg-value pairs defined in that group. Args: arg_file: str, the name of the YAML argument file to open and parse. Returns: A dict containing all arg-groups found in the arg_file. Raises: yaml.Error: If the YAML file could not be read or parsed. BadFileException: If the contents of the file are not valid. """ all_groups = {} for d in yaml.load_all_path(arg_file): if d is None: log.warning('Ignoring empty yaml document.') elif isinstance(d, dict): all_groups.update(d) else: raise calliope_exceptions.BadFileException( 'Failed to parse YAML file [{}]: [{}] is not a valid argument ' 'group.'.format(arg_file, str(d))) return all_groups
def Run(self, args): """This is what gets called when the user runs this command.""" loaded_yaml = list(yaml.load_all_path(args.file)) deploy_client = deploy.DeployClient() region_ref = args.CONCEPTS.region.Parse() region = region_ref.AsDict()['locationsId'] deploy_client.DeleteResources(loaded_yaml, region, args.force)
def __init__(self, file_path, item_type): self._file_path = file_path self._item_type = item_type try: items = yaml.load_all_path(file_path) self._data = [item_type(x) for x in items] except yaml.FileLoadError as fe: raise YamlConfigFileError( 'Error Loading Config File: [{}]'.format(fe))
def _MakeTempConfigFiles(self): """Copy fixture data files to temp directories so they can be modified.""" fixture_file_dir = self.Resource('tests', 'unit', 'command_lib', 'anthos', 'testdata') config_v2_path = self.Resource(fixture_file_dir, 'auth-config-v2alpha1.yaml') config_v2_multi_path = self.Resource( fixture_file_dir, 'auth-config-multiple-v2alpha1.yaml') config_v1_multi_path = self.Resource( fixture_file_dir, 'auth-config-multiple-v1alpha1.yaml') config_v1_path = self.Resource(fixture_file_dir, 'auth-config-v1alpha1.yaml') config_v2_missing_providers = self.Resource( fixture_file_dir, 'auth-config-v2alpha1-missing-providers.yaml') config_v2_1p = self.Resource(fixture_file_dir, 'auth-config-v2alpha1-1p.yaml') config_v2_1p_ldap = self.Resource(fixture_file_dir, 'auth-config-v2alpha1-1p-ldap.yaml') self.v2_ex1_path = self.Touch(self.temp_path, 'config_v2_ex1.yaml', contents=yaml.dump_all( yaml.load_all_path(config_v2_path))) self.v2_ex1_contents = files.ReadFileContents(self.v2_ex1_path) self.v2_ex2_multi_path = self.Touch( self.temp_path, 'config_v2_ex2.yaml', contents=yaml.dump_all(yaml.load_all_path(config_v2_multi_path))) self.v2_ex2_multi_contents = files.ReadFileContents( self.v2_ex2_multi_path) self.v1_ex1_path = self.Touch( self.temp_path, 'config_v1_multi_path.yaml', contents=yaml.dump_all(yaml.load_all_path(config_v1_multi_path))) self.v1_ex2_multi_path = self.Touch( self.temp_path, 'config_v1_multi_path.yaml', contents=yaml.dump_all(yaml.load_all_path(config_v1_path))) self.v2_ex2_missing_providers = self.Touch( self.temp_path, 'config-v2alpha1-missing-providers.yaml', contents=yaml.dump_all( yaml.load_all_path(config_v2_missing_providers))) self.v2_ex3_1p = self.Touch(self.temp_path, 'config-v2alpha1-1p.yaml', contents=yaml.dump_all( yaml.load_all_path(config_v2_1p))) self.v2_ex4_1p_ldap = self.Touch( self.temp_path, 'config-v2alpha1-1p-ldap.yaml', contents=yaml.dump_all(yaml.load_all_path(config_v2_1p_ldap)))
def __init__(self, item_type, file_contents=None, file_path=None): self._file_contents = file_contents self._file_path = file_path self._item_type = item_type if not self._file_contents and not self._file_path: raise YamlConfigFileError('Could Not Initialize YamlConfigFile:' 'file_contents And file_path Are Both Empty') # Priority is to try to load from contents if specified. Else from file. if self._file_contents: try: items = yaml.load_all(self._file_contents, round_trip=True) self._data = [item_type(x) for x in items] except yaml.YAMLParseError as fe: raise YamlConfigFileError('Error Parsing Config File: [{}]'.format(fe)) elif self._file_path: try: items = yaml.load_all_path(self._file_path, round_trip=True) self._data = [item_type(x) for x in items] except yaml.FileLoadError as fe: raise YamlConfigFileError('Error Loading Config File: [{}]'.format(fe))