From cddff32792bcb0e0d03922eaec6a8221ad784dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Fri, 22 Sep 2017 19:11:11 +0200 Subject: [PATCH] [fix] pylint errors on modules packaging language (#30748) * cleaning pylint errors for module packaging/language/* --- .../modules/packaging/language/bower.py | 4 +- .../modules/packaging/language/bundler.py | 5 ++- .../modules/packaging/language/cpanm.py | 10 ++--- lib/ansible/modules/packaging/language/gem.py | 5 ++- .../packaging/language/maven_artifact.py | 42 +++++++++---------- lib/ansible/modules/packaging/language/npm.py | 6 +-- .../modules/packaging/language/pear.py | 5 ++- 7 files changed, 39 insertions(+), 38 deletions(-) diff --git a/lib/ansible/modules/packaging/language/bower.py b/lib/ansible/modules/packaging/language/bower.py index cd6d6ed6ce..c5bd296441 100644 --- a/lib/ansible/modules/packaging/language/bower.py +++ b/lib/ansible/modules/packaging/language/bower.py @@ -217,12 +217,12 @@ def main(): changed = False if state == 'present': installed, missing, outdated = bower.list() - if len(missing): + if missing: changed = True bower.install() elif state == 'latest': installed, missing, outdated = bower.list() - if len(missing) or len(outdated): + if missing or outdated: changed = True bower.update() else: # Absent diff --git a/lib/ansible/modules/packaging/language/bundler.py b/lib/ansible/modules/packaging/language/bundler.py index 5a02a8fca1..88013b6ed4 100644 --- a/lib/ansible/modules/packaging/language/bundler.py +++ b/lib/ansible/modules/packaging/language/bundler.py @@ -136,9 +136,10 @@ from ansible.module_utils.basic import AnsibleModule def get_bundler_executable(module): if module.params.get('executable'): - return module.params.get('executable').split(' ') + result = module.params.get('executable').split(' ') else: - return [ module.get_bin_path('bundle', True) ] + result = [module.get_bin_path('bundle', True)] + return result def main(): diff --git a/lib/ansible/modules/packaging/language/cpanm.py b/lib/ansible/modules/packaging/language/cpanm.py index 9633c577f6..c6ca05f1a1 100644 --- a/lib/ansible/modules/packaging/language/cpanm.py +++ b/lib/ansible/modules/packaging/language/cpanm.py @@ -139,10 +139,7 @@ def _is_package_installed(module, name, locallib, cpanm, version): else: cmd = "%s;'" % cmd res, stdout, stderr = module.run_command(cmd, check_rc=False) - if res == 0: - return True - else: - return False + return res == 0 def _build_cmd_line(name, from_path, notest, locallib, mirror, mirror_only, installdeps, cpanm, use_sudo): # this code should use "%s" like everything else and just return early but not fixing all of it now. @@ -175,9 +172,10 @@ def _build_cmd_line(name, from_path, notest, locallib, mirror, mirror_only, inst def _get_cpanm_path(module): if module.params['executable']: - return module.params['executable'] + result = module.params['executable'] else: - return module.get_bin_path('cpanm', True) + result = module.get_bin_path('cpanm', True) + return result def main(): diff --git a/lib/ansible/modules/packaging/language/gem.py b/lib/ansible/modules/packaging/language/gem.py index d446629bb4..900b3ac696 100644 --- a/lib/ansible/modules/packaging/language/gem.py +++ b/lib/ansible/modules/packaging/language/gem.py @@ -116,9 +116,10 @@ from ansible.module_utils.basic import AnsibleModule def get_rubygems_path(module): if module.params['executable']: - return module.params['executable'].split(' ') + result = module.params['executable'].split(' ') else: - return [ module.get_bin_path('gem', True) ] + result = [module.get_bin_path('gem', True)] + return result def get_rubygems_version(module): cmd = get_rubygems_path(module) + [ '--version' ] diff --git a/lib/ansible/modules/packaging/language/maven_artifact.py b/lib/ansible/modules/packaging/language/maven_artifact.py index 8136e3db25..339205d3f9 100644 --- a/lib/ansible/modules/packaging/language/maven_artifact.py +++ b/lib/ansible/modules/packaging/language/maven_artifact.py @@ -189,7 +189,7 @@ def adjust_recursive_directory_permissions(pre_existing_dir, new_directory_list, Walk the new directories list and make sure that permissions are as we would expect ''' - if len(new_directory_list) > 0: + if new_directory_list: working_dir = os.path.join(pre_existing_dir, new_directory_list.pop(0)) directory_args['path'] = working_dir changed = module.set_fs_attributes_if_different(directory_args, changed) @@ -220,15 +220,14 @@ class Artifact(object): def path(self, with_version=True): base = posixpath.join(self.group_id.replace(".", "/"), self.artifact_id) if with_version and self.version: - return posixpath.join(base, self.version) - else: - return base + base = posixpath.join(base, self.version) + return base def _generate_filename(self): + filename = self.artifact_id + "-" + self.classifier + "." + self.extension if not self.classifier: - return self.artifact_id + "." + self.extension - else: - return self.artifact_id + "-" + self.classifier + "." + self.extension + filename = self.artifact_id + "." + self.extension + return filename def get_filename(self, filename=None): if not filename: @@ -238,12 +237,12 @@ class Artifact(object): return filename def __str__(self): + result = "%s:%s:%s" % (self.group_id, self.artifact_id, self.version) if self.classifier: - return "%s:%s:%s:%s:%s" % (self.group_id, self.artifact_id, self.extension, self.classifier, self.version) + result = "%s:%s:%s:%s:%s" % (self.group_id, self.artifact_id, self.extension, self.classifier, self.version) elif self.extension != "jar": - return "%s:%s:%s:%s" % (self.group_id, self.artifact_id, self.extension, self.version) - else: - return "%s:%s:%s" % (self.group_id, self.artifact_id, self.version) + result = "%s:%s:%s:%s" % (self.group_id, self.artifact_id, self.extension, self.version) + return result @staticmethod def parse(input): @@ -293,8 +292,10 @@ class MavenDownloader: timestamp = xml.xpath("/metadata/versioning/snapshot/timestamp/text()")[0] buildNumber = xml.xpath("/metadata/versioning/snapshot/buildNumber/text()")[0] for snapshotArtifact in xml.xpath("/metadata/versioning/snapshotVersions/snapshotVersion"): - artifact_classifier = snapshotArtifact.xpath("classifier/text()")[0] if len(snapshotArtifact.xpath("classifier/text()")) > 0 else '' - artifact_extension = snapshotArtifact.xpath("extension/text()")[0] if len(snapshotArtifact.xpath("extension/text()")) > 0 else '' + classifier = snapshotArtifact.xpath("classifier/text()") + artifact_classifier = classifier[0] if classifier else '' + extension = snapshotArtifact.xpath("extension/text()") + artifact_extension = extension[0] if extension else '' if artifact_classifier == artifact.classifier and artifact_extension == artifact.extension: return self._uri_for_artifact(artifact, snapshotArtifact.xpath("value/text()")[0]) return self._uri_for_artifact(artifact, artifact.version.replace("SNAPSHOT", timestamp + "-" + buildNumber)) @@ -342,6 +343,7 @@ class MavenDownloader: artifact.classifier, artifact.extension) url = self.find_uri_for_artifact(artifact) + result = True if not self.verify_md5(filename, url + ".md5"): response = self._request(url, "Failed to download artifact " + str(artifact), lambda r: r) if response: @@ -349,11 +351,9 @@ class MavenDownloader: # f.write(response.read()) self._write_chunks(response, f, report_hook=self.chunk_report) f.close() - return True else: - return False - else: - return True + result = False + return result def chunk_report(self, bytes_so_far, chunk_size, total_size): percent = float(bytes_so_far) / total_size @@ -383,12 +383,12 @@ class MavenDownloader: return bytes_so_far def verify_md5(self, file, remote_md5): - if not os.path.exists(file): - return False - else: + result = False + if os.path.exists(file): local_md5 = self._local_md5(file) remote = self._request(remote_md5, "Failed to download MD5", lambda r: r.read()) - return local_md5 == remote + result = local_md5 == remote + return result def _local_md5(self, file): md5 = hashlib.md5() diff --git a/lib/ansible/modules/packaging/language/npm.py b/lib/ansible/modules/packaging/language/npm.py index 8cc9edbf76..f2a48deb03 100644 --- a/lib/ansible/modules/packaging/language/npm.py +++ b/lib/ansible/modules/packaging/language/npm.py @@ -264,16 +264,16 @@ def main(): changed = False if state == 'present': installed, missing = npm.list() - if len(missing): + if missing: changed = True npm.install() elif state == 'latest': installed, missing = npm.list() outdated = npm.list_outdated() - if len(missing): + if missing: changed = True npm.install() - if len(outdated): + if outdated: changed = True npm.update() else: # absent diff --git a/lib/ansible/modules/packaging/language/pear.py b/lib/ansible/modules/packaging/language/pear.py index 91ae606b22..a4b738d170 100644 --- a/lib/ansible/modules/packaging/language/pear.py +++ b/lib/ansible/modules/packaging/language/pear.py @@ -85,9 +85,10 @@ def get_local_version(pear_output): def _get_pear_path(module): if module.params['executable'] and os.path.isfile(module.params['executable']): - return module.params['executable'] + result = module.params['executable'] else: - return module.get_bin_path('pear', True, [module.params['executable']]) + result = module.get_bin_path('pear', True, [module.params['executable']]) + return result def get_repository_version(pear_output): """Take pear remote-info output and get the latest version"""