code: def zip_dir(dir_path, zip_file):
      
      log = logging.getLogger(mod_logger + '.zip_dir')
  
      # Validate args
      if not isinstance(dir_path, basestring):
          msg = 'dir_path argument must be a string'
          log.error(msg)
          raise CommandError(msg)
      if not isinstance(zip_file, basestring):
          msg = 'zip_file argument must be a string'
          log.error(msg)
          raise CommandError(msg)
  
      # Ensure the dir_path file exists
      if not os.path.isdir(dir_path):
          msg = 'Directory not found: {f}'.format(f=dir_path)
          log.error(msg)
          raise CommandError(msg)
  
      try:
          with contextlib.closing(zipfile.ZipFile(zip_file, 'w', allowZip64=True)) as zip_w:
              for root, dirs, files in os.walk(dir_path):
                  for f in files:
                      log.debug('Adding file to zip: %s', f)
                      strip = len(dir_path) - len(os.path.split(dir_path)[-1])
                      file_name = os.path.join(root, f)
                      archive_name = os.path.join(root[strip:], f)
                      zip_w.write(file_name, archive_name)
      except Exception:
          _, ex, trace = sys.exc_info()
          msg = 'Unable to create zip file: {f}\n{e}'.format(
              f=zip_file, e=str(ex))
          log.error(msg)
          raise CommandError, msg, trace
      log.info('Successfully created zip file: %s', zip_file)
docs: Creates a zip file of a directory tree
  
      This method creates a zip archive using the directory tree dir_path
      and adds to zip_file output.
  
      :param dir_path: (str) Full path to directory to be zipped
      :param zip_file: (str) Full path to the output zip file
      :return: None
      :raises CommandError