#! /usr/bin/env python
#
# autoflight.py
#
# Created by Andrea Stagi (stagi.andrea at gmail dot com)
#
# A simple script to upload a given .apk or .ipa to testflight.
#
# -------------------------------------------------------------------------

import requests, json, sys, os.path
from requests.exceptions import ConnectionError
from optparse import OptionParser

url = 'http://testflightapp.com/api/builds.json'

def is_empty(text):
    return text == None or text == ""

def main():
    usage = "Usage: %prog [options] my_apk_or_ipa_path"
    parser = OptionParser(usage=usage)
    parser.add_option( "-a", "--api-token", dest="api_token", default="", help="The API token from the testflight website." )
    parser.add_option( "-t", "--team-token", dest="team_token", default="",help="The team token from the testflight website." )
    parser.add_option( "-l", "--distribution-lists", dest="distribution_lists", default="",help="The name of the distribution list in testflight which should have access to this build." )
    parser.add_option( "-n", "--notify", dest="notify", default=False, help="True if the distribution list should be notified for new builds." )
    parser.add_option( "-d", "--notes", dest="notes", default="", help="Your notes for this build." )
    parser.add_option( "-s", "--dsym", dest="dsym", default="", help="iOS ONLY, the zipped .dSYM corresponding to the build.")
    parser.add_option( "-c", "--config-file", dest="config_file", default="", help="Configuration file" )

    (options, args) = parser.parse_args()

    if len(args) == 0:
        parser.print_usage()
        exit(0)
    if len(args) == 1:
        build_file = args[0]

    if not os.path.exists(build_file):
        print "Error! %s build file doesn't exist" % build_file
        exit(0)

    if not is_empty(options.dsym) and not os.path.exists(options.dsym):
        print "Error! %s dSYM file doesn't exist" % options
        exit(0)

    params = {}
    if not is_empty(options.config_file):
        print "Reading configuration..."
        if os.path.exists(options.config_file):
            json_file_content = open(options.config_file, "r").read()
        else:
            print "Error! %s file doesn't exist" % options.config_file
            exit(0)
        params = json.loads(json_file_content)
    else:
        params['api_token'] = options.api_token
        params['team_token'] = options.team_token
        params['notify'] = options.notify
        params['notes'] = options.notes
        params['distribution_lists'] = options.distribution_lists

    if not 'notes' in params or is_empty(params['notes']):
        params['notes'] = raw_input("Release Notes - What's new in this build? \n> ")

    print "Uploading file..."
    files = {'file': open(build_file, 'rb')}
    if not is_empty(options.dsym):
        files['dsym'] = open(options.dsym, 'rb')
    try:
        req = requests.post(url=url, data=params, files=files)
        print req.text
    except ConnectionError:
        print "Connection error. Please try again."

if __name__ == "__main__":
    main()

@@ -412,67 +412,8 @@
 n'%0A%0A
-def is_empty(text):%0A    return text == None or text == %22%22%0A%0A
 def 
@@ -1725,37 +1725,24 @@
 (0)%0A%0A    if 
-not is_empty(
 options.dsym
@@ -1741,17 +1741,16 @@
 ons.dsym
-)
  and not
@@ -1876,37 +1876,24 @@
 = %7B%7D%0A    if 
-not is_empty(
 options.conf
@@ -1891,33 +1891,32 @@
 ions.config_file
-)
 :%0A        print 
@@ -2501,25 +2501,20 @@
 rams or 
-is_empty(
+not 
 params%5B'
@@ -2520,17 +2520,16 @@
 'notes'%5D
-)
 :%0A      
@@ -2695,21 +2695,8 @@
  if 
-not is_empty(
 opti
@@ -2695,33 +2695,32 @@
  if options.dsym
-)
 :%0A        files%5B

Remove unneeded is_empty method.