old_contents: # vim:fileencoding=utf-8:ft=python
  #
  # Author: R.F. Smith <rsmith@xs4all.nl>
  # Last modified: 2015-09-23 01:04:14 +0200
  #
  # To the extent possible under law, Roland Smith has waived all
  # copyright and related or neighboring rights to checkfor.py This work
  # is published from the Netherlands. See
  # http://creativecommons.org/publicdomain/zero/1.0/
  
  from __future__ import division, print_function
  
  import os
  import subprocess
  import sys
  
  
  def checkfor(args, rv=0):
      """
      Make sure that a program necessary for using this script is available.
      If the required utility is not found, this function will exit the program.
  
      Arguments:
          args: String or list of strings of commands. A single string may not
              contain spaces.
          rv: Expected return value from evoking the command.
      """
      if isinstance(args, str):
          if ' ' in args:
              raise ValueError('no spaces in single command allowed')
          args = [args]
      try:
          rc = subprocess.call(args, stdout=subprocess.DEVNULL,
                               stderr=subprocess.DEVNULL)
          if rc != rv:
              raise OSError
      except OSError as oops:
          outs = "Required program '{}' not found: {}."
          print(outs.format(args[0], oops.strerror))
          sys.exit(1)
  
new_contents: # vim:fileencoding=utf-8:ft=python
  #
  # Author: R.F. Smith <rsmith@xs4all.nl>
  # Last modified: 2015-10-08 20:13:09 +0200
  #
  # To the extent possible under law, Roland Smith has waived all
  # copyright and related or neighboring rights to checkfor.py This work
  # is published from the Netherlands. See
  # http://creativecommons.org/publicdomain/zero/1.0/
  
  from __future__ import division, print_function
  
  import logging
  import os
  import subprocess
  import sys
  
  
  def checkfor(args, rv=0):
      """
      Make sure that a program necessary for using this script is available.
      If the required utility is not found, this function will exit the program.
  
      Arguments:
          args: String or list of strings of commands. A single string may not
              contain spaces.
          rv: Expected return value from evoking the command.
      """
      if isinstance(args, str):
          if ' ' in args:
              raise ValueError('no spaces in single command allowed')
          args = [args]
      try:
          rc = subprocess.call(args, stdout=subprocess.DEVNULL,
                               stderr=subprocess.DEVNULL)
          if rc != rv:
              raise OSError
          logging.info('found required program "{}"'.format(args[0]))
      except OSError as oops:
          outs = "required program '{}' not found: {}."
          logging.error(outs.format(args[0], oops.strerror))
          sys.exit(1)
  
subject: Use logging in checkfor