From 36484e8672f5ee1fdc2bd57622e330ab8dbb7671 Mon Sep 17 00:00:00 2001 From: Jan Barta <55042barta@sstebrno.eu> Date: Sep 22 2016 14:52:57 +0000 Subject: pylint: fix simplifiable-if-statement warnings fix inefficient if statements, enable pylint check Reviewed-By: Tomas Krizek Reviewed-By: Florence Blanc-Renaud --- diff --git a/ipalib/config.py b/ipalib/config.py index 55a95bb..eb6c3ae 100644 --- a/ipalib/config.py +++ b/ipalib/config.py @@ -455,14 +455,10 @@ class Env(object): # Determine if running in source tree: if 'in_tree' not in self: - if ( + self.in_tree = ( self.bin == self.site_packages and path.isfile(path.join(self.bin, 'setup.py')) - ): - self.in_tree = True - else: - self.in_tree = False - + ) if self.in_tree and 'mode' not in self: self.mode = 'developer' diff --git a/ipaplatform/base/services.py b/ipaplatform/base/services.py index a36b2f4..750d979 100644 --- a/ipaplatform/base/services.py +++ b/ipaplatform/base/services.py @@ -271,10 +271,8 @@ class SystemdService(PlatformService): ipautil.run(args, skip_output=not capture_output) - if getattr(self.api.env, 'context', None) in ['ipactl', 'installer']: - update_service_list = True - else: - update_service_list = False + update_service_list = getattr(self.api.env, 'context', + None) in ['ipactl', 'installer'] super(SystemdService, self).stop( instance_name, update_service_list=update_service_list) @@ -284,10 +282,8 @@ class SystemdService(PlatformService): self.service_instance(instance_name)], skip_output=not capture_output) - if getattr(self.api.env, 'context', None) in ['ipactl', 'installer']: - update_service_list = True - else: - update_service_list = False + update_service_list = getattr(self.api.env, 'context', + None) in ['ipactl', 'installer'] if wait and self.is_running(instance_name): self.wait_for_open_ports(self.service_instance(instance_name)) diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 64901b5..62d029d 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -519,20 +519,14 @@ def nolog_replace(string, nolog): def file_exists(filename): try: mode = os.stat(filename)[stat.ST_MODE] - if stat.S_ISREG(mode): - return True - else: - return False + return bool(stat.S_ISREG(mode)) except Exception: return False def dir_exists(filename): try: mode = os.stat(filename)[stat.ST_MODE] - if stat.S_ISDIR(mode): - return True - else: - return False + return bool(stat.S_ISDIR(mode)) except Exception: return False diff --git a/ipapython/nsslib.py b/ipapython/nsslib.py index b5e5b65..1573de9 100644 --- a/ipapython/nsslib.py +++ b/ipapython/nsslib.py @@ -74,10 +74,7 @@ def auth_certificate_callback(sock, check_sig, is_server, certdb): ', '.join(nss.cert_usage_flags(intended_usage))) # Is the intended usage a proper subset of the approved usage - if approved_usage & intended_usage: - cert_is_valid = True - else: - cert_is_valid = False + cert_is_valid = bool(approved_usage & intended_usage) # If this is a server, we're finished if is_server or not cert_is_valid: diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py index e0d0908..cd09cae 100644 --- a/ipapython/sysrestore.py +++ b/ipapython/sysrestore.py @@ -437,7 +437,4 @@ class StateFile: Can be used to determine if a service is configured. """ - if module in self.modules: - return True - else: - return False + return module in self.modules diff --git a/ipaserver/install/ca.py b/ipaserver/install/ca.py index 00e0b03..dcda19a 100644 --- a/ipaserver/install/ca.py +++ b/ipaserver/install/ca.py @@ -127,14 +127,9 @@ def install_step_0(standalone, replica_config, options): if replica_config is not None: # Configure the CA if necessary if standalone: - postinstall = True - else: - postinstall = False - - if standalone: api.Backend.ldap2.disconnect() - cainstance.install_replica_ca(replica_config, postinstall, + cainstance.install_replica_ca(replica_config, standalone, ra_p12=getattr(options, 'ra_p12', None)) if standalone and not api.Backend.ldap2.isconnected(): diff --git a/ipaserver/plugins/dogtag.py b/ipaserver/plugins/dogtag.py index 644b41e..ffe6ead 100644 --- a/ipaserver/plugins/dogtag.py +++ b/ipaserver/plugins/dogtag.py @@ -1750,10 +1750,7 @@ class ra(rabase.rabase, RestClient): # Return command result cmd_result = {} - if parse_result.get('revoked') == 'yes': - cmd_result['revoked'] = True - else: - cmd_result['revoked'] = False + cmd_result['revoked'] = parse_result.get('revoked') == 'yes' return cmd_result @@ -1814,10 +1811,7 @@ class ra(rabase.rabase, RestClient): if 'error_string' in parse_result: cmd_result['error_string'] = parse_result['error_string'] - if parse_result.get('unrevoked') == 'yes': - cmd_result['unrevoked'] = True - else: - cmd_result['unrevoked'] = False + cmd_result['unrevoked'] = parse_result.get('unrevoked') == 'yes' return cmd_result diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py index b39df34..6b3082a 100644 --- a/ipatests/test_integration/tasks.py +++ b/ipatests/test_integration/tasks.py @@ -172,11 +172,7 @@ def host_service_active(host, service): res = host.run_command(['systemctl', 'is-active', '--quiet', service], raiseonerr=False) - if res.returncode == 0: - return True - else: - return False - + return res.returncode == 0 def fix_apache_semaphores(master): systemd_available = master.transport.file_exists(paths.SYSTEMCTL) @@ -325,11 +321,7 @@ def master_authoritative_for_client_domain(master, client): zone = ".".join(client.hostname.split('.')[1:]) result = master.run_command(["ipa", "dnszone-show", zone], raiseonerr=False) - if result.returncode == 0: - return True - else: - return False - + return result.returncode == 0 def replica_prepare(master, replica, extra_args=(), raiseonerr=True, stdin_text=None): diff --git a/pylintrc b/pylintrc index bb9c636..1f7e49f 100644 --- a/pylintrc +++ b/pylintrc @@ -23,7 +23,6 @@ disable= interface-not-implemented, no-self-use, redefined-variable-type, - simplifiable-if-statement, too-few-public-methods, too-many-ancestors, too-many-arguments,