def main()

in clone_mediaconvert_resources/clone_mediaconvert_resources.py [0:0]


def main(argv=None):
    initialize = False
    save_file = False
    clone_region_used = False
    destination_region = None
    source_region = None
    action = None

    # check opt
    if initialize:
        if not os.path.exists('mediaconvertcloner.config.json'):
            print("No configuration file found please run the script with -i before cloning")
            exit(-1)

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'hic:r:a:f', ['help', 'initialize', 'clone=', 'region=', 'action=',
                                                               'file'])
    except getopt.GetoptError as err:
        print(str(err))
        usage(sys.argv[0])
        exit(-1)

    if len(sys.argv) == 1:
        usage(sys.argv[0])
        exit()

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage(sys.argv[0])
            sys.exit(0)
        elif opt in ("-r", "--region"):
            if is_valid_supported_region(arg):
                if is_valid_config_region(arg):
                    source_region = arg
                else:
                    print("Invalid region parameter: Specified region was not found in the configuration "
                          "file. Re-run the script with -i")
                    exit(-1)
            else:
                print("Invalid region parameter: Not a supported MediaConvert Region")
                exit(-1)
        elif opt in ("-a", "--action"):
            if is_valid_action(arg):
                action = arg
            else:
                print("Invalid action parameter: Not a supported action")
                exit(-1)
        elif opt in ("-c", "--clone"):
            if is_valid_supported_region(arg):
                if is_valid_config_region(arg):
                    destination_region = arg
                else:
                    print("Invalid clone parameter: Specified region was not found in the configuration file. "
                          "Re-run the script with -i")
                    exit(-1)
            else:
                print("Invalid clone parameter: Not a supported MediaConvert Region")
                exit(-1)
            clone_region_used = True
        elif opt in ("-f", "--file"):
            save_file = True
        elif opt in ("-i", "--initialize"):
            initialize = True
        else:
            assert False, "Unhandled option '{0}'".format(opt)

    if initialize:
        if os.path.exists('mediaconvertcloner.config.json'):
            check_config()
            exit()
        else:
            create_config()
            exit()


    if source_region == destination_region:
        print("Error: Source region and clone region are the same")
        exit(-1)

    if save_file:
        save_to_file(source_region, destination_region, action)
    else:
        clone(source_region, destination_region, action)