summaryrefslogtreecommitdiffstats
path: root/roles/lib_openshift/library/oc_route.py
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2017-02-16 14:13:26 -0500
committerKenny Woodson <kwoodson@redhat.com>2017-02-16 14:34:34 -0500
commit42af186c6f961a9a7cd76abc4ac423d9141bded2 (patch)
tree34a99e1c8c851e8a05fcbfe01722df3652c867d8 /roles/lib_openshift/library/oc_route.py
parent43330fbd7cb90491d63e54430394a309f7a41f73 (diff)
downloadopenshift-42af186c6f961a9a7cd76abc4ac423d9141bded2.tar.gz
openshift-42af186c6f961a9a7cd76abc4ac423d9141bded2.tar.bz2
openshift-42af186c6f961a9a7cd76abc4ac423d9141bded2.tar.xz
openshift-42af186c6f961a9a7cd76abc4ac423d9141bded2.zip
Adding fallback support for pyyaml.
Diffstat (limited to 'roles/lib_openshift/library/oc_route.py')
-rw-r--r--roles/lib_openshift/library/oc_route.py43
1 files changed, 30 insertions, 13 deletions
diff --git a/roles/lib_openshift/library/oc_route.py b/roles/lib_openshift/library/oc_route.py
index d5dc84116..715ce1cdc 100644
--- a/roles/lib_openshift/library/oc_route.py
+++ b/roles/lib_openshift/library/oc_route.py
@@ -372,7 +372,11 @@ class Yedit(object):
if hasattr(self.yaml_dict, 'fa'):
self.yaml_dict.fa.set_block_style()
- Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+ # pylint: disable=no-member
+ if hasattr(yaml, 'RoundTripDumper'):
+ Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+ else:
+ Yedit._write(self.filename, yaml.dump(self.yaml_dict, default_flow_style=False))
return (True, self.yaml_dict)
@@ -412,7 +416,10 @@ class Yedit(object):
# check if it is yaml
try:
if content_type == 'yaml' and contents:
- self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+ if hasattr(yaml, 'RoundTripLoader'):
+ self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
+ else:
+ self.yaml_dict = yaml.load(contents)
# pylint: disable=no-member
if hasattr(self.yaml_dict, 'fa'):
self.yaml_dict.fa.set_block_style()
@@ -580,12 +587,18 @@ class Yedit(object):
return (False, self.yaml_dict)
# deepcopy didn't work
- tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
- default_flow_style=False),
- yaml.RoundTripLoader)
- # pylint: disable=no-member
- if hasattr(self.yaml_dict, 'fa'):
- tmp_copy.fa.set_block_style()
+ if hasattr(yaml, 'round_trip_dump'):
+ tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+ default_flow_style=False),
+ yaml.RoundTripLoader)
+
+ # pylint: disable=no-member
+ if hasattr(self.yaml_dict, 'fa'):
+ tmp_copy.fa.set_block_style()
+
+ else:
+ tmp_copy = copy.deepcopy(self.yaml_dict)
+
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if not result:
return (False, self.yaml_dict)
@@ -598,11 +611,15 @@ class Yedit(object):
''' create a yaml file '''
if not self.file_exists():
# deepcopy didn't work
- tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False), # noqa: E501
- yaml.RoundTripLoader)
- # pylint: disable=no-member
- if hasattr(self.yaml_dict, 'fa'):
- tmp_copy.fa.set_block_style()
+ if hasattr(yaml, 'round_trip_dump'):
+ tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False), # noqa: E501
+ yaml.RoundTripLoader)
+ # pylint: disable=no-member
+ if hasattr(self.yaml_dict, 'fa'):
+ tmp_copy.fa.set_block_style()
+ else:
+ tmp_copy = copy.deepcopy(self.yaml_dict)
+
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if result:
self.yaml_dict = tmp_copy