예제 #1
0
def main():
    args = parse_args()

    if args.debug:
        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
        logging.debug('brave_version: {}'.format(get_upload_version()))

    if args.file and args.github:
        exit("Error: --file and --github are mutually exclusive, only one allowed")

    if not os.environ.get('OMAHA_PASS') or not os.environ.get('OMAHA_USER'):
        message = (
            'Error: Please set the $OMAHA_USER, $OMAHA_PASS and $OMAHA_HOST environment variables')
        exit(message)

    if args.github:
        file_list = download_from_github(args, logging)
    else:
        file_list = [args.file]

    for source_file in file_list:
        app_info = {}

        if args.debug:
            logging.debug("source_file: {}".format(source_file))

        if re.match(r'.*\.dmg$', source_file):
            app_info['platform'] = 'darwin'
            app_info['arch'] = 'x64'
        elif re.match(r'.*brave_installer-ia32\.exe$', source_file):
            app_info['platform'] = 'win32'
            app_info['arch'] = 'ia32'
        elif re.match(r'.*brave_installer-x64\.exe$', source_file):
            app_info['platform'] = 'win32'
            app_info['arch'] = 'x64'

        app_info = get_app_info(app_info, args)
        app_info['omahahost'] = os.environ.get('OMAHA_HOST')
        app_info['auth'] = get_base64_authorization(
            os.environ.get('OMAHA_USER'), os.environ.get('OMAHA_PASS'))
        app_info['headers'] = headers = {
            'Authorization': 'Basic %s' % app_info['auth']
        }

        if app_info['platform'] in 'darwin':
            app_info['version_url'] = '/api/sparkle/version/'
            if not os.environ.get('DSA_PRIVATE_PEM'):
                exit('Error: Please set the $DSA_PRIVATE_PEM environment variable')
        elif app_info['platform'] in 'win32':
            app_info['version_url'] = '/api/omaha/version/'

        app_info['version_post_url'] = 'https://' + \
            app_info['omahahost'] + app_info['version_url']

        app_info['size'] = os.path.getsize(source_file)

        if args.debug:
            for item in app_info:
                if item in 'auth':
                    logging.debug('{}: {}'.format(item, "NOTAREALPASSWORD"))
                elif item in 'headers':
                    logging.debug('{}: {}'.format(
                        item, "{'Authorization': 'Basic NOTAREALPASSWORD'}"))
                else:
                    logging.debug('{}: {}'.format(item, app_info[item]))
            logging.debug("omaha_channel: {}".format(omaha_channel(app_info['platform'], app_info['arch'],
                                                                   app_info['preview'])))
            logging.debug("omaha_channel_id: {}".format(get_channel_id(omaha_channel(app_info['platform'],
                                                                       app_info['arch'], app_info['preview']),
                                                                       app_info['omahahost'], app_info['headers'],
                                                                       logging)))
            logging.debug("URL: {}".format(app_info['version_post_url']))
            logging.debug("file_list: {}".format(file_list))

        with open(source_file, 'rb') as f:
            files = {'file': f}
            params = {
                'app': app_info['appguid'],
                'channel': get_channel_id(omaha_channel(app_info['platform'], app_info['arch'], app_info['preview']),
                                          app_info['omahahost'], app_info['headers'], logging),
                'version': app_info['version'],
                'release_notes': app_info['release_notes']
            }

            if app_info['platform'] in 'win32':
                params['is_enabled'] = app_info['is_enabled']
                params['platform'] = app_info['platform_id']
            else:
                app_info['darwindsasig'] = sign_update_sparkle(
                    source_file, os.environ.get('DSA_PRIVATE_PEM')).rstrip('\n')
                params['dsa_signature'] = app_info['darwindsasig']
                params['short_version'] = app_info['short_version']

            response = post_with_file(
                app_info['version_post_url'], files, params, headers)
            if response.status_code != 201:
                logging.error("ERROR: Version not created! response.status_code : {}".format(
                    response.status_code))
                logging.error("response.text : {}".format(response.text))

                if response.status_code == 400 and 'version must make a unique set' in response.text:
                    logging.error("ERROR: This version({}), channel({}), appguid({}) set has already been "
                                  "uploaded to the Omaha server!".format(params['version'], app_info['channel'],
                                                                         params['app']))

                remove_github_downloaded_files(file_list, logging)

                exit(1)

        if app_info['platform'] in 'win32':
            # When uploading windows builds, add actions to version just created
            rjson = response.json()

            if args.debug:
                logging.debug("response['id']: {}".format(rjson['id']))

            post_action(app_info['omahahost'], rjson['id'],
                        'install', headers, args)
            post_action(app_info['omahahost'],
                        rjson['id'], 'update', headers, args)

    # if downloading from github, remove files after upload
    if args.github:
        remove_github_downloaded_files(file_list, logging)
예제 #2
0
def main():
    args = parse_args()

    if args.debug:
        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
        logging.debug('brave_version: {}'.format(get_upload_version()))

    if args.uploaded and args.platform:
        exit("Error: --platform and --uploaded are mutually exclusive, only one allowed")

    # Default to requiring all 3 platforms
    if not args.uploaded and not args.platform:
        args.platform = ['win32', 'win64', 'darwin']

    if args.debug and args.platform:
        logging.debug("args.platform: {}".format(args.platform))

    if args.file and args.github:
        exit("Error: --file and --github are mutually exclusive, only one allowed")

    if not os.environ.get('OMAHA_PASS') or not os.environ.get('OMAHA_USER'):
        message = (
            'Error: Please set the $OMAHA_USER, $OMAHA_PASS and $OMAHA_HOST environment variables')
        exit(message)

    if args.github:
        file_list = download_from_github(args, logging)
    else:
        file_list = [args.file]

    for source_file in file_list:
        app_info = {}

        if args.debug:
            logging.debug("source_file: {}".format(source_file))

        if re.match(r'.*\.dmg$', source_file):
            app_info['platform'] = 'darwin'
            app_info['arch'] = 'x64'
        elif re.match(r'.*brave_installer-ia32\.exe$', source_file):
            app_info['platform'] = 'win32'
            app_info['arch'] = 'ia32'
        elif re.match(r'.*brave_installer-x64\.exe$', source_file):
            app_info['platform'] = 'win32'
            app_info['arch'] = 'x64'

        app_info = get_app_info(app_info, args)
        app_info['omahahost'] = os.environ.get('OMAHA_HOST')
        app_info['auth'] = get_base64_authorization(
            os.environ.get('OMAHA_USER'), os.environ.get('OMAHA_PASS'))
        app_info['headers'] = headers = {
            'Authorization': 'Basic %s' % app_info['auth']
        }

        if app_info['platform'] in 'darwin':
            app_info['version_url'] = '/api/sparkle/version/'
            if not os.environ.get('DSA_PRIVATE_PEM'):
                exit('Error: Please set the $DSA_PRIVATE_PEM environment variable')
        elif app_info['platform'] in 'win32':
            app_info['version_url'] = '/api/omaha/version/'

        app_info['version_post_url'] = 'https://' + \
            app_info['omahahost'] + app_info['version_url']

        app_info['size'] = os.path.getsize(source_file)

        if args.debug:
            for item in app_info:
                if item in 'auth':
                    logging.debug('{}: {}'.format(item, "NOTAREALPASSWORD"))
                elif item in 'headers':
                    logging.debug('{}: {}'.format(
                        item, "{'Authorization': 'Basic NOTAREALPASSWORD'}"))
                else:
                    logging.debug('{}: {}'.format(item, app_info[item]))
            logging.debug("omaha_channel: {}".format(omaha_channel(app_info['platform'], app_info['arch'],
                                                                   app_info['preview'])))
            logging.debug("omaha_channel_id: {}".format(get_channel_id(omaha_channel(app_info['platform'],
                                                                       app_info['arch'], app_info['preview']),
                                                                       app_info['omahahost'], app_info['headers'],
                                                                       logging)))
            logging.debug("URL: {}".format(app_info['version_post_url']))
            logging.debug("file_list: {}".format(file_list))

        with open(source_file, 'rb') as f:
            files = {'file': f}
            params = {
                'app': app_info['appguid'],
                'channel': get_channel_id(omaha_channel(app_info['platform'], app_info['arch'], app_info['preview']),
                                          app_info['omahahost'], app_info['headers'], logging),
                'version': app_info['version'],
                'release_notes': app_info['release_notes']
            }

            if app_info['platform'] in 'win32':
                params['is_enabled'] = app_info['is_enabled']
                params['platform'] = app_info['platform_id']
            else:
                app_info['darwindsasig'] = sign_update_sparkle(
                    source_file, os.environ.get('DSA_PRIVATE_PEM')).rstrip('\n')
                params['dsa_signature'] = app_info['darwindsasig']
                params['short_version'] = app_info['short_version']

            response = post_with_file(
                app_info['version_post_url'], files, params, headers)
            if response.status_code != 201:
                logging.error("ERROR: Version not created! response.status_code : {}".format(
                    response.status_code))
                logging.error("response.text : {}".format(response.text))

                if response.status_code == 400 and 'version must make a unique set' in response.text:
                    logging.error("ERROR: This version({}), channel({}), appguid({}) set has already been "
                                  "uploaded to the Omaha server!".format(params['version'], app_info['channel'],
                                                                         params['app']))

                remove_github_downloaded_files(file_list, logging)

                exit(1)

        if app_info['platform'] in 'win32':
            # When uploading windows builds, add actions to version just created
            rjson = response.json()

            if args.debug:
                logging.debug("response['id']: {}".format(rjson['id']))

            post_action(app_info['omahahost'], rjson['id'],
                        'install', headers, args)
            post_action(app_info['omahahost'],
                        rjson['id'], 'update', headers, args)

    # if downloading from github, remove files after upload
    if args.github:
        remove_github_downloaded_files(file_list, logging)