From fa8e653011ad71a632a797ec14b72b4629bf3846 Mon Sep 17 00:00:00 2001 From: Blair Zajac Date: Sat, 9 Feb 2013 15:49:54 -0800 Subject: [PATCH] Simplify and correct comparisons with None. --- lib/ansible/callbacks.py | 2 +- lib/ansible/runner/__init__.py | 2 +- library/apt | 2 +- library/git | 2 +- library/mysql_db | 2 +- library/mysql_user | 2 +- library/selinux | 4 ++-- library/service | 10 +++++----- library/virt | 2 +- plugins/inventory/ec2.py | 4 ++-- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index 706bcad261b..2c2226a29e5 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -132,7 +132,7 @@ def regular_generic_msg(hostname, result, oneline, caption): def banner(msg): - if cowsay != None: + if cowsay: cmd = subprocess.Popen([cowsay, "-W", "60", msg], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = cmd.communicate() diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 45d0ec6ae76..ef0e7c146c9 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -501,7 +501,7 @@ class Runner(object): else: err = stderr - if rc != None: + if rc is not None: return dict(rc=rc, stdout=out, stderr=err ) else: return dict(stdout=out, stderr=err ) diff --git a/library/apt b/library/apt index 4692ad323f5..3c8a270a6ce 100644 --- a/library/apt +++ b/library/apt @@ -202,7 +202,7 @@ def main(): if module.boolean(p['update_cache']): cache.update() cache.open(progress=None) - if p['package'] == None: + if not p['package']: module.exit_json(changed=False) force_yes = module.boolean(p['force']) diff --git a/library/git b/library/git index aff83e3df8b..020306bd1f2 100644 --- a/library/git +++ b/library/git @@ -89,7 +89,7 @@ def has_local_mods(dest): os.chdir(dest) cmd = "git status -s" lines = os.popen(cmd).read().splitlines() - lines = filter(lambda c: re.search('^\\?\\?.*$',c) == None,lines) + lines = filter(lambda c: not re.search('^\\?\\?.*$', c), lines) return len(lines) > 0 def reset(module,dest,force): diff --git a/library/mysql_db b/library/mysql_db index 42150370506..807603a83dd 100644 --- a/library/mysql_db +++ b/library/mysql_db @@ -187,7 +187,7 @@ def main(): else: connect_to_db = 'mysql' try: - if module.params["login_unix_socket"] != None: + if module.params["login_unix_socket"]: db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db=connect_to_db) else: db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db=connect_to_db) diff --git a/library/mysql_user b/library/mysql_user index bcf90b70332..b9b833e1f64 100644 --- a/library/mysql_user +++ b/library/mysql_user @@ -285,7 +285,7 @@ def main(): module.fail_json(msg="when supplying login arguments, both login_user and login_password must be provided") try: - if module.params["login_unix_socket"] != None: + if module.params["login_unix_socket"]: db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db="mysql") else: db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db="mysql") diff --git a/library/selinux b/library/selinux index c2965a33398..eafa3bf1a61 100644 --- a/library/selinux +++ b/library/selinux @@ -147,10 +147,10 @@ def main(): # check to see if policy is set if state is not 'disabled' if (state != 'disabled'): - if (policy == '' or policy == None): + if not policy: module.fail_json(msg='policy is required if state is not \'disabled\'') else: - if (policy == '' or policy == None): + if not policy: policy = config_policy # check changed values and run changes diff --git a/library/service b/library/service index adac3ba4b93..cb862d859c3 100644 --- a/library/service +++ b/library/service @@ -236,7 +236,7 @@ class Service(object): break def check_service_changed(self): - if self.state and self.running == None: + if self.state and self.running is None: self.module.fail_json(msg="failed determining the current service state => state stays unchanged") # Find out if state has changed if not self.running and self.state in ["started", "running"]: @@ -377,7 +377,7 @@ class LinuxService(Service): rc, status_stdout, status_stderr = self.service_control() # Check if we have upstart on the system and then the job state - if self.svc_initctl != None and self.running is None: + if self.svc_initctl and self.running is None: # check the job status by upstart response initctl_rc, initctl_status_stdout, initctl_status_stderr = self.execute_command("%s status %s" % (self.svc_initctl, self.name)) if initctl_status_stdout.find("stop/waiting") != -1: @@ -386,14 +386,14 @@ class LinuxService(Service): self.running = True # if the job status is still not known check it by response code - if self.running == None: + if self.running is None: if rc in [2, 3, 4, 69]: self.running = False elif rc == 0: self.running = True # if the job status is still not known check it by status output keywords - if self.running == None: + if self.running is None: # first tranform the status output that could irritate keyword matching cleanout = status_stdout.lower().replace(self.name.lower(), '') if "stop" in cleanout: @@ -414,7 +414,7 @@ class LinuxService(Service): self.running = False # if the job status is still not known check it by special conditions - if self.running == None: + if self.running is None: if self.name == 'iptables' and status_stdout.find("ACCEPT") != -1: # iptables status command output is lame # TODO: lookup if we can use a return code for this instead? diff --git a/library/virt b/library/virt index d7ef80b434f..85d3fcc395e 100644 --- a/library/virt +++ b/library/virt @@ -322,7 +322,7 @@ class Virt(object): """ conn = libvirt.openReadOnly(None) - if conn == None: + if not conn: return (-1,'Failed to open connection to the hypervisor') try: domV = conn.lookupByName(vmid) diff --git a/plugins/inventory/ec2.py b/plugins/inventory/ec2.py index fcad5703ee4..08c37c065e5 100755 --- a/plugins/inventory/ec2.py +++ b/plugins/inventory/ec2.py @@ -283,7 +283,7 @@ class Ec2Inventory(object): else: dest = getattr(instance, self.destination_variable) - if dest == None: + if not dest: # Skip instances we cannot address (e.g. private VPC subnet) return @@ -303,7 +303,7 @@ class Ec2Inventory(object): self.push(self.inventory, self.to_safe('type_' + instance.instance_type), dest) # Inventory: Group by key pair - if instance.key_name != None: + if instance.key_name: self.push(self.inventory, self.to_safe('key_' + instance.key_name), dest) # Inventory: Group by security group