summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils/library
diff options
context:
space:
mode:
authorJason DeTiberus <jdetiber@redhat.com>2017-02-20 16:10:43 -0500
committerSteve Milner <smilner@redhat.com>2017-02-22 11:26:23 -0500
commit9a01b3a021fc457d917386c93e17ad34cefbdc92 (patch)
treee0d827b6ac61ef76c34cd63462a83d4e8ffe19cb /roles/lib_utils/library
parentde8d10d8a6eb34c4f6821353345c7baadc1f3b60 (diff)
downloadopenshift-9a01b3a021fc457d917386c93e17ad34cefbdc92.tar.gz
openshift-9a01b3a021fc457d917386c93e17ad34cefbdc92.tar.bz2
openshift-9a01b3a021fc457d917386c93e17ad34cefbdc92.tar.xz
openshift-9a01b3a021fc457d917386c93e17ad34cefbdc92.zip
fix up ruamel.yaml/pyyaml no-member lint errors
Diffstat (limited to 'roles/lib_utils/library')
-rw-r--r--roles/lib_utils/library/repoquery.py1
-rw-r--r--roles/lib_utils/library/yedit.py79
2 files changed, 42 insertions, 38 deletions
diff --git a/roles/lib_utils/library/repoquery.py b/roles/lib_utils/library/repoquery.py
index f31c8911b..ee98470b0 100644
--- a/roles/lib_utils/library/repoquery.py
+++ b/roles/lib_utils/library/repoquery.py
@@ -35,7 +35,6 @@ import os # noqa: F401
import re # noqa: F401
import shutil # noqa: F401
-# pylint: disable=import-error
try:
import ruamel.yaml as yaml # noqa: F401
except ImportError:
diff --git a/roles/lib_utils/library/yedit.py b/roles/lib_utils/library/yedit.py
index ee20cc49b..b1d9d6869 100644
--- a/roles/lib_utils/library/yedit.py
+++ b/roles/lib_utils/library/yedit.py
@@ -35,7 +35,6 @@ import os # noqa: F401
import re # noqa: F401
import shutil # noqa: F401
-# pylint: disable=import-error
try:
import ruamel.yaml as yaml # noqa: F401
except ImportError:
@@ -381,16 +380,16 @@ class Yedit(object):
if self.backup and self.file_exists():
shutil.copy(self.filename, self.filename + '.orig')
- if hasattr(yaml, 'RoundTripDumper'):
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
- if hasattr(self.yaml_dict, 'fa'):
- self.yaml_dict.fa.set_block_style()
+ # Try to set format attributes if supported
+ try:
+ self.yaml_dict.fa.set_block_style()
+ except AttributeError:
+ pass
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
+ # Try to use RoundTripDumper if supported.
+ try:
Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
- else:
+ except AttributeError:
Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False))
return (True, self.yaml_dict)
@@ -431,17 +430,23 @@ class Yedit(object):
# check if it is yaml
try:
if content_type == 'yaml' and contents:
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
- if hasattr(yaml, 'RoundTripLoader'):
- self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
- else:
+ # Try to set format attributes if supported
+ try:
+ self.yaml_dict.fa.set_block_style()
+ except AttributeError:
+ pass
+
+ # Try to use RoundTripLoader if supported.
+ try:
+ self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader)
+ except AttributeError:
self.yaml_dict = yaml.safe_load(contents)
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
- if hasattr(self.yaml_dict, 'fa'):
+ # Try to set format attributes if supported
+ try:
self.yaml_dict.fa.set_block_style()
+ except AttributeError:
+ pass
elif content_type == 'json' and contents:
self.yaml_dict = json.loads(contents)
@@ -613,21 +618,20 @@ class Yedit(object):
return (False, self.yaml_dict)
# deepcopy didn't work
- if hasattr(yaml, 'round_trip_dump'):
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
+ # Try to use ruamel.yaml and fallback to pyyaml
+ try:
tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
default_flow_style=False),
yaml.RoundTripLoader)
-
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
- if hasattr(self.yaml_dict, 'fa'):
- tmp_copy.fa.set_block_style()
-
- else:
+ except AttributeError:
tmp_copy = copy.deepcopy(self.yaml_dict)
+ # set the format attributes if available
+ try:
+ tmp_copy.fa.set_block_style()
+ except AttributeError:
+ pass
+
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if not result:
return (False, self.yaml_dict)
@@ -640,19 +644,20 @@ class Yedit(object):
''' create a yaml file '''
if not self.file_exists():
# deepcopy didn't work
- if hasattr(yaml, 'round_trip_dump'):
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
- tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False), # noqa: E501
+ # Try to use ruamel.yaml and fallback to pyyaml
+ try:
+ tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
+ default_flow_style=False),
yaml.RoundTripLoader)
-
- # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
- # pylint: disable=no-member
- if hasattr(self.yaml_dict, 'fa'):
- tmp_copy.fa.set_block_style()
- else:
+ except AttributeError:
tmp_copy = copy.deepcopy(self.yaml_dict)
+ # set the format attributes if available
+ try:
+ tmp_copy.fa.set_block_style()
+ except AttributeError:
+ pass
+
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if result:
self.yaml_dict = tmp_copy