Main function - launches the program

def main(args):
    """
    Main function - launches the program
    """

    if args:
        
        if not args.outputRepository:
            HOME_DIR = os.path.expanduser('~')
            # Utility's base directory
            BASE_DIR = os.path.abspath(os.path.dirname(__file__))
            DOWNLOAD_DIR = HOME_DIR + '/landsat'
            ZIP_DIR = DOWNLOAD_DIR + '/zip'
        else:
            ZIP_DIR = args.outputRepository
        
        if args.subs == 'search':

            try:
                if args.start:
                    args.start = reformat_date(parse(args.start))

                if args.end:
                    args.end = reformat_date(parse(args.end))
            except TypeError:
                exit("You date format is incorrect. Please try again!", 1)

            s = Search()
            
            clipper = Clipper()
            if args.search_subs == 'shapefile':
                clipper.shapefile(args.path)
            elif args.search_subs == 'query':
                clipper.query(args.name)
            
            result = s.search(args.limit,args.start,args.end,clipper)
            try:
                if result['status'] == 'SUCCESS':
                    if result['total'] > 200:
                        exit('Too many results. Please narrow your search or limit your query with -l options')
                    else:
                        if args.outputRepository:
                            with open(ZIP_DIR+'/result.geojson', 'w') as outfile:
                                json.dump(result['results'], outfile)
                            print ("The geojsonFIle have been created  here: %s" %
                                 ZIP_DIR)
                        else:
                            print ("the IDs which matched with request are : ")
                            for i in result['ID']:
                                print (i)
                    
                    if args.download:
                        gs = GsHelper(ZIP_DIR)
                        if (args.password) and (args.user):
                            print('Starting the download:')
                            for item in result['downloads']:
                                login=args.user
                                mdp=args.password
                                gs.single_download(login,mdp,item['download'],item['id'],ZIP_DIR)
                                print ("%s have been downloaded ... continuing downloading" % item['id'])
                            print("%s images were downloaded"
                                  % result['total'])
                            exit("The downloaded images are located here: %s" %
                                 ZIP_DIR)
                        else:
                             exit("Please give a loggin and a password for theia downloading")
                    else:
                        exit("")
                elif result['status'] == 'error':
                    exit(result['message'])
            except KeyError:
                exit('Too Many API queries. You can only query DevSeed\'s '
                     'API 5 times per minute', 1)

        elif args.subs == 'download':
            gs = GsHelper(ZIP_DIR)
            print('Starting the download:')
            if (args.password) and (args.user):
                for scene in args.scenes:
                    login=args.user
                    mdp=args.password
                    download='http://spirit.cnes.fr/resto/Landsat/'+scene+'/$download'
                    testD=gs.checkifDownloadExist(login,mdp,download,scene)
                    if testD:
                        gs.single_download(login,mdp,download,scene,ZIP_DIR)
                    else:
                        exit("SceneID has not been founded or wrong User/Password given!")
                exit("The downloaded images are located here: %s" % gs.zip_dir)
            else:
                exit("Please give a loggin and a password for theia downloading")