1 # ex: python3 sort_yaml_functions.py
2 # ex: must be within yaml directory
7 def sort_yaml_functions(yaml_file
):
8 with
open(yaml_file
, "r") as f
:
9 yaml_data
= yaml
.safe_load(f
)
11 if "functions" in yaml_data
:
12 yaml_data
["functions"].sort(key
=lambda x
: x
["name"])
14 class IndentYamlListDumper(yaml
.Dumper
):
15 def increase_indent(self
, flow
=False, indentless
=False):
16 return super(IndentYamlListDumper
, self
).increase_indent(flow
, False)
18 with
open(yaml_file
, "w") as f
:
22 Dumper
=IndentYamlListDumper
,
23 default_flow_style
=False,
29 current_directory
= os
.getcwd()
31 file for file in os
.listdir(current_directory
) if file.endswith(".yaml")
34 for yaml_file
in yaml_files
:
35 sort_yaml_functions(yaml_file
)
38 if __name__
== "__main__":