1
+ import logging
1
2
import sys
2
3
import ntpath
3
4
import yaml
@@ -26,7 +27,7 @@ def update_playbook_task_name(playbook):
26
27
:param playbook: playbook dict loaded from yaml
27
28
:return: updated playbook dict
28
29
"""
29
- for task_id , task in playbook .get ("tasks" , {}).items ():
30
+ for _task_id , task in playbook .get ("tasks" , {}).items ():
30
31
if task .get ("type" ) == "playbook" :
31
32
task ["task" ]["name" ] = task ["task" ]["playbookName" ]
32
33
@@ -92,10 +93,10 @@ def update_replace_copy_dev(playbook):
92
93
93
94
94
95
def update_playbook (source_path , destination_path ):
95
- print ("Starting..." )
96
+ logging . info ("Starting..." )
96
97
97
98
with open (source_path ) as f :
98
- playbook = yaml .load ( f , Loader = yamlordereddictloader . SafeLoader )
99
+ playbook = yaml .safe_load ( f )
99
100
100
101
playbook = update_replace_copy_dev (playbook )
101
102
@@ -114,14 +115,14 @@ def update_playbook(source_path, destination_path):
114
115
destination_path = ntpath .basename (source_path )
115
116
116
117
if not destination_path .startswith ("playbook-" ):
117
- destination_path = "playbook-{}" . format ( destination_path )
118
+ destination_path = f "playbook-{ destination_path } "
118
119
119
120
# Configure safe dumper (multiline for strings)
120
121
yaml .SafeDumper .org_represent_str = yaml .SafeDumper .represent_str # type: ignore[attr-defined]
121
122
122
123
def repr_str (dumper , data ):
123
124
if '\n ' in data :
124
- return dumper .represent_scalar (u 'tag:yaml.org,2002:str' , data , style = '|' )
125
+ return dumper .represent_scalar ('tag:yaml.org,2002:str' , data , style = '|' )
125
126
return dumper .org_represent_str (data )
126
127
yaml .add_representer (str , repr_str , Dumper = yamlordereddictloader .SafeDumper )
127
128
@@ -132,12 +133,12 @@ def repr_str(dumper, data):
132
133
Dumper = yamlordereddictloader .SafeDumper ,
133
134
default_flow_style = False )
134
135
135
- print ( "Finished - new yml saved at {}" . format ( destination_path ) )
136
+ logging . info ( f "Finished - new yml saved at { destination_path } " )
136
137
137
138
138
139
def main (argv ):
139
140
if len (argv ) < 1 :
140
- print ("Please provide <source playbook path>, <optional - destination playbook path>" )
141
+ logging . info ("Please provide <source playbook path>, <optional - destination playbook path>" )
141
142
sys .exit (1 )
142
143
143
144
source_path = argv [0 ]
0 commit comments