Exemplo n.º 1
0
def submit_git_build(binstar, args):

    log.info("Submitting the following repo for package creation: %s" % args.git_url)
    builds = get_gitrepo(urlparse(args.git_url))

    if not args.package:
        user = binstar.user()
        user_name = user['login']
        package_name = builds['repo'].split('/')[1]
        log.info("Using repo name '%s' as the pkg name." % package_name)
        args.package = PackageSpec(user_name, package_name)

    try:
        _ = binstar.package(args.package.user, args.package.name)
    except errors.NotFound:
        raise errors.UserError("Package %s does not exist" % (args.package,))


    if not args.dry_run:
        log.info("Submitting the following repo for package creation: %s" % args.git_url)
        builds = get_gitrepo(urlparse(args.path))
        build = binstar.submit_for_url_build(args.package.user, args.package.name, builds,
                                             channels=args.channels, queue=args.queue, sub_dir=args.sub_dir,
                                             test_only=args.test_only, callback=upload_print_callback(args),
                                             filter_platform=args.platform,
                                                )

        print_build_results(args, build)

    else:
        log.info('Build not submitted (dry-run)')
Exemplo n.º 2
0
def submit_git_build(binstar, args):

    log.info("Submitting the following repo for package creation: %s" % args.git_url)
    builds = get_gitrepo(urlparse(args.git_url))

    if not args.package:
        user = binstar.user()
        user_name = user['login']
        package_name = builds['repo'].split('/')[1]
        log.info("Using repo name '%s' as the pkg name." % package_name)
        args.package = PackageSpec(user_name, package_name)

    try:
        _ = binstar.package(args.package.user, args.package.name)
    except errors.NotFound:
        raise errors.UserError("Package %s does not exist" % (args.package,))


    if not args.dry_run:
        log.info("Submitting the following repo for package creation: %s" % args.git_url)
        builds = get_gitrepo(urlparse(args.path))
        build = binstar.submit_for_url_build(args.package.user, args.package.name, builds,
                                             channels=args.channels, queue=args.queue, sub_dir=args.sub_dir,
                                             test_only=args.test_only, callback=upload_print_callback(args),
                                             filter_platform=args.platform,
                                                )

        print_build_results(args, build)

    else:
        log.info('Build not submitted (dry-run)')
Exemplo n.º 3
0
def main(args):

    binstar = get_binstar(args)

    print("main upload!")

    if args.dest and '/' in args.dest:
        username = args.dest.split('/', 1)[0]
    else:
        user = binstar.user()
        username = user['login']

    if args.dest:
        package_name = args.dest.rsplit('/', 1)[-1]
    else:
        package_name = os.path.basename(args.datafile).split('.')[0]

    if not exists(args.datafile):
        raise errors.BinstarError('file %s does not exist' % args.datafile)
    package_type = 'data'

    ensure_package(binstar, username, package_name, args.summary)
    ensure_version(binstar, username, package_name, args.version)
    ensure_unique(binstar,
                  username,
                  package_name,
                  args.version,
                  os.path.basename(args.datafile),
                  force=False)

    with open(args.datafile) as fd:
        upload_info = binstar.upload(username,
                                     package_name,
                                     args.version,
                                     os.path.basename(args.datafile),
                                     fd,
                                     package_type,
                                     args.description,
                                     attrs={'data_type': 'download'},
                                     channels=['main'],
                                     callback=upload_print_callback(args))

    log.info("\n\nUpload(s) Complete\n")

    package_url = upload_info.get(
        'url', 'https://anaconda.org/%s/%s' % (username, package_name))
    log.info("Package located at:\n%s\n" % package_url)
Exemplo n.º 4
0
def main(args):

    binstar = get_binstar(args)

    print("main upload!")

    if args.dest and '/' in args.dest:
        username = args.dest.split('/', 1)[0]
    else:
        user = binstar.user()
        username = user['login']

    if args.dest:
        package_name = args.dest.rsplit('/', 1)[-1]
    else:
        package_name = os.path.basename(args.datafile).split('.')[0]

    if not exists(args.datafile):
        raise errors.BinstarError('file %s does not exist' % args.datafile)
    package_type = 'data'

    ensure_package(binstar, username, package_name, args.summary)
    ensure_version(binstar, username, package_name, args.version)
    ensure_unique(binstar, username, package_name, args.version, os.path.basename(args.datafile), force=False)

    with open(args.datafile) as fd:
        upload_info = binstar.upload(username, package_name, args.version, os.path.basename(args.datafile),
                                     fd, package_type,
                                     args.description,
                                     attrs={'data_type': 'download'},
                                     channels=['main'],
                                     callback=upload_print_callback(args))

    log.info("\n\nUpload(s) Complete\n")

    package_url = upload_info.get('url', 'https://anaconda.org/%s/%s' % (username, package_name))
    log.info("Package located at:\n%s\n" % package_url)
Exemplo n.º 5
0
def submit_build(binstar, args):

    path = abspath(args.path)

    log.info('Getting build product: %s' % abspath(args.path))

    build_matrix = load_all_binstar_yml(path)
    builds = list(serialize_builds(build_matrix))

    if args.platform:

        log.info("Only selecting builds on platform %s" % args.platform)
        builds = [b for b in builds if b['platform'] == args.platform]

    if not builds:
        msg = "No build instructions found"
        if args.platform:
            msg += " for platform %s" % args.platform
        raise errors.BinstarError(msg)

    log.info('Submitting %i sub builds' % len(builds))
    for i, build in enumerate(builds):
        log.info(' %i)' % i +
                 ' %(platform)-10s  %(engine)-15s  %(env)-15s' % build)

    if not args.dry_run:
        if args.git_url:
            log.info("Submitting the following repo for package creation: %s" %
                     args.git_url)

        else:
            with mktemp() as tmp:
                log.info("Archiving build directory for upload ...")
                with tarfile.open(tmp, mode='w|bz2') as tf:
                    exclude = ExcludeGit(
                        path, use_git_ignore=not args.dont_git_ignore)
                    tf.add(path, '.', exclude=exclude)

                log.info(
                    "Created archive (%i files); Uploading to Anaconda Build service"
                    % exclude.num_included)
                queue_tags = []
                if args.buildhost:
                    queue_tags.append('hostname:%s' % args.buildhost)

                if args.dist:
                    queue_tags.append('dist:%s' % args.dist)

                with open(tmp, mode='rb') as fd:

                    # TODO: change channels= to labels=
                    build = binstar.submit_for_build(
                        args.package.user,
                        args.package.name,
                        fd,
                        builds,
                        channels=args.labels,
                        queue=args.queue,
                        queue_tags=queue_tags,
                        test_only=args.test_only,
                        callback=upload_print_callback(args))

                print_build_results(args, build, binstar)

    else:
        log.info('Build not submitted (dry-run)')
Exemplo n.º 6
0
def main(args):

    aserver_api = get_binstar(args)

    if args.user:
        username = args.user
    else:
        user = aserver_api.user()
        username = user['login']

    uploaded_packages = []

    # Flatten file list because of 'windows_glob' function
    files = [f for fglob in args.files for f in fglob]

    for filename in files:

        if not exists(filename):
            raise errors.BinstarError('file %s does not exist' % (filename))

        package_type = determine_package_type(filename, args)

        log.info('extracting package attributes for upload ...')
        sys.stdout.flush()
        try:
            package_attrs, release_attrs, file_attrs = get_attrs(package_type,
                                                                 filename, parser_args=args)
        except Exception:
            if args.show_traceback:
                raise
            raise errors.BinstarError('Trouble reading metadata from %r. Is this a valid %s package' % (filename, package_type))

        if args.build_id:
            file_attrs['attrs']['binstar_build'] = args.build_id

        log.info('done')

        package_name = get_package_name(args, package_attrs, filename, package_type)
        version = get_version(args, release_attrs, package_type)

        add_package(aserver_api, args, username, package_name, package_attrs, package_type)

        add_release(aserver_api, args, username, package_name, version, release_attrs)

        binstar_package_type = file_attrs.pop('binstar_package_type', package_type)

        with open(filename, 'rb') as fd:
            log.info('\nUploading file %s/%s/%s/%s ... ' % (username, package_name, version, file_attrs['basename']))
            sys.stdout.flush()

            if remove_existing_file(aserver_api, args, username, package_name, version, file_attrs):
                continue
            try:
                upload_info = aserver_api.upload(username, package_name, version, file_attrs['basename'],
                                             fd, binstar_package_type,
                                             args.description,
                                             dependencies=file_attrs.get('dependencies'),
                                             attrs=file_attrs['attrs'],
                                             channels=args.channels,
                                             callback=upload_print_callback(args))
            except errors.Conflict:
                full_name = '%s/%s/%s/%s' % (username, package_name, version, file_attrs['basename'])
                log.info('Distribution already exists. Please use the -i/--interactive or --force options or `anaconda remove %s`' % full_name)
                raise

            uploaded_packages.append([package_name, upload_info])
            log.info("\n\nUpload(s) Complete\n")


    for package, upload_info in uploaded_packages:
        package_url = upload_info.get('url', 'https://anaconda.org/%s/%s' % (username, package))
        log.info("Package located at:\n%s\n" % package_url)
Exemplo n.º 7
0
def main(args):
    for item in args.deprecated:
        log.warn('Argument %s has been deprecated and is no longer used. '
                 'Please see the command "binstar register" for details' % item)


    binstar = get_binstar(args)

    if args.user:
        username = args.user
    else:
        user = binstar.user()
        username = user ['login']

    uploaded_packages = []

    for filename in args.files:

        if not exists(filename):
            raise BinstarError('file %s does not exist' % (filename))

        if args.package_type:
            package_type = args.package_type
        else:
            log.info('detecting package type ...')
            sys.stdout.flush()
            package_type = detect_package_type(filename)
            if package_type is None:
                raise BinstarError('Could not detect package type of file %r please specify package type with option --package-type' % filename)
            log.info(package_type)

        if args.metadata:
            attrs = json.loads(args.metadata)
            package_name = args.package
            version = args.version
            description = ''
            basefilename = basename(filename)
        else:
            log.info('extracting package attributes for upload ...')
            sys.stdout.flush()
            try:
                package_attrs = get_attrs(package_type, filename)
            except Exception:
                if args.show_traceback:
                    raise

                raise BinstarError('Trouble reading metadata from %r. Please make sure this package is correct or specify the --metadata, --package and --version arguments' % (filename))

            basefilename, package_name, version, attrs, summary, description, license = package_attrs
            log.info('done')

        if args.package:
            package_name = args.package

        if args.version:
            version = args.version

        try:
            binstar.package(username, package_name)
        except NotFound:
            if args.no_register:
                raise UserError('Binstar package %s/%s does not exist. '
                                'Please run "binstar register" to create this package namespace in the cloud.' % (username, package_name))
            else:
                binstar.add_package(username, package_name, summary, license,
                                    public=True, publish=False)

        try:
            binstar.release(username, package_name, version)
        except NotFound:
            if args.mode == 'interactive':
                create_release_interactive(binstar, username, package_name, version)
            else:
                create_release(binstar, username, package_name, version, description)

        with open(filename, 'rb') as fd:
            log.info('\nUploading file %s/%s/%s/%s ... ' % (username, package_name, version, basefilename))
            sys.stdout.flush()
            try:
                binstar.distribution(username, package_name, version, basefilename)
            except NotFound:
                pass
            else:

                if args.mode == 'force':
                    log.warning('Distribution %s already exists ... removing' % (basefilename,))
                    binstar.remove_dist(username, package_name, version, basefilename)
                if args.mode == 'interactive':
                    if bool_input('Distribution %s already exists. Would you like to replace it?' % (basefilename,)):
                        binstar.remove_dist(username, package_name, version, basefilename)
                    else:
                        log.info('Not replacing distribution %s' % (basefilename,))
                        continue
            try:
                if args.build_id:
                    attrs['binstar_build'] = args.build_id
                binstar.upload(username, package_name, version, basefilename, fd, package_type, args.description, attrs=attrs,
                               channels=args.channels,
                               callback=upload_print_callback(args))
            except Conflict:
                full_name = '%s/%s/%s/%s' % (username, package_name, version, basefilename)
                log.info('Distribution already exists. Please use the -i/--interactive or --force options or `binstar remove %s`' % full_name)
                raise

            uploaded_packages.append(package_name)
            log.info("\n\nUpload(s) Complete\n")


    for package in uploaded_packages:
        log.info("Package located at:\nhttps://binstar.org/%s/%s\n" % (username, package))
Exemplo n.º 8
0
def submit_build(args):

    binstar = get_binstar(args, cls=BinstarBuildAPI)

    path = abspath(args.path)

    log.info('Getting build product: %s' % abspath(args.path))

    with open(join(path, '.binstar.yml')) as cfg:
        build_matrix = list(yaml.load_all(cfg))

    builds = list(serialize_builds(build_matrix))
    log.info('Submitting %i sub builds' % len(builds))
    for i, build in enumerate(builds):
        log.info(' %i)' % i + ' %(platform)-10s  %(engine)-15s  %(env)-15s' % build)

    if not args.dry_run:
        with mktemp() as tmp:
            log.info("Archiving build directory for upload ...")
            with tarfile.open(tmp, mode='w|bz2') as tf:
                tf.add(path, '.', exclude=ExcludeGit(path, use_git_ignore=not args.dont_git_ignore))

            log.info("Created archive; Uploading to binstar")
            with open(tmp, mode='rb') as fd:

                build_no = binstar.submit_for_build(args.package.user, args.package.name, fd, builds,
                                                    test_only=args.test_only, callback=upload_print_callback(args))

        log.info('')
        log.info('To view this build go to http://alpha.binstar.org/%s/%s/builds/matrix/%s' % (args.package.user, args.package.name, build_no))
        log.info('')
        log.info('You may also run\n\n    binstar-build tail -f %s/%s %s\n' % (args.package.user, args.package.name, build_no))
        log.info('')
        log.info('Build %s submitted' % build_no)

    else:
        log.info('Build not submitted (dry-run)')
Exemplo n.º 9
0
def submit_build(binstar, args):

    path = abspath(args.path)

    log.info('Getting build product: %s' % abspath(args.path))

    with open(join(path, '.binstar.yml')) as cfg:
        build_matrix = list(yaml.load_all(cfg))

    builds = list(serialize_builds(build_matrix))

    if args.platform:

        log.info("Only selecting builds on platform %s" % args.platform)
        builds = [b for b in builds if b['platform'] == args.platform]

    if not builds:
        msg = "No build instructions found"
        if args.platform:
            msg += " for platform %s" % args.platform
        raise errors.BinstarError(msg)

    log.info('Submitting %i sub builds' % len(builds))
    for i, build in enumerate(builds):
        log.info(' %i)' % i + ' %(platform)-10s  %(engine)-15s  %(env)-15s' % build)

    if not args.dry_run:
        if args.git_url:
            log.info("Submitting the following repo for package creation: %s" % args.git_url)

        else:
            with mktemp() as tmp:
                log.info("Archiving build directory for upload ...")
                with tarfile.open(tmp, mode='w|bz2') as tf:
                    exclude = ExcludeGit(path, use_git_ignore=not args.dont_git_ignore)
                    tf.add(path, '.', exclude=exclude)

                log.info("Created archive (%i files); Uploading to binstar" % exclude.num_included)
                queue_tags = []
                if args.buildhost:
                    queue_tags.append('hostname:%s' % args.buildhost)

                if args.dist:
                    queue_tags.append('dist:%s' % args.dist)

                with open(tmp, mode='rb') as fd:

                    build = binstar.submit_for_build(args.package.user, args.package.name, fd, builds,
                                                     channels=args.channels,
                                                     queue=args.queue, queue_tags=queue_tags,
                                                     test_only=args.test_only, callback=upload_print_callback(args))

                print_build_results(args, build)

    else:
        log.info('Build not submitted (dry-run)')
Exemplo n.º 10
0
def upload_package(filename, package_type, aserver_api, username, args):
    logger.info('Extracting {} attributes for upload'.format(
        verbose_package_type(package_type)))

    try:
        package_attrs, release_attrs, file_attrs = get_attrs(package_type,
                                                             filename,
                                                             parser_args=args)
    except Exception:
        message = 'Trouble reading metadata from {}. Is this a valid {} package?'.format(
            filename, verbose_package_type(package_type))
        logger.error(message)

        if args.show_traceback:
            raise

        raise errors.BinstarError(message)

    if args.build_id:
        file_attrs['attrs']['binstar_build'] = args.build_id

    package_name = get_package_name(args, package_attrs, filename,
                                    package_type)
    version = get_version(args, release_attrs, package_type)

    logger.info('Creating package "%s"', package_name)

    package = add_package(aserver_api, args, username, package_name,
                          package_attrs, package_type)
    package_types = package.get('package_types', [])

    if package_types and package_type not in package_types:
        message = 'You already have a {} named \'{}\'. Use a different name for this {}.'.format(
            verbose_package_type(package_types[0] if package_types else ''),
            package_name,
            verbose_package_type(package_type),
        )
        logger.error(message)
        raise errors.BinstarError(message)

    logger.info('Creating release "%s"', version)

    add_release(aserver_api, args, username, package_name, version,
                release_attrs)
    binstar_package_type = file_attrs.pop('binstar_package_type', package_type)

    with open(filename, 'rb') as fd:
        logger.info('Uploading file "%s/%s/%s/%s"', username, package_name,
                    version, file_attrs['basename'])

        if remove_existing_file(aserver_api, args, username, package_name,
                                version, file_attrs):
            return None

        try:
            upload_info = aserver_api.upload(
                username,
                package_name,
                version,
                file_attrs['basename'],
                fd,
                binstar_package_type,
                args.description,
                dependencies=file_attrs.get('dependencies'),
                attrs=file_attrs['attrs'],
                channels=args.labels,
                callback=upload_print_callback(args))
        except errors.Conflict:
            logger.info(
                'Distribution already exists. Please use the -i/--interactive or --force options or `anaconda '
                'remove %s/%s/%s/%s', username, package_name, version,
                file_attrs['basename'])
            raise

        logger.info("Upload complete")

        return [package_name, upload_info]
Exemplo n.º 11
0
def upload_package(filename, package_type, aserver_api, username, args):
    logger.info('Extracting {} attributes for upload'.format(verbose_package_type(package_type)))

    try:
        package_attrs, release_attrs, file_attrs = get_attrs(package_type, filename, parser_args=args)
    except Exception:
        message = 'Trouble reading metadata from {}. Is this a valid {} package?'.format(
            filename, verbose_package_type(package_type)
        )
        logger.error(message)

        if args.show_traceback:
            raise

        raise errors.BinstarError(message)

    if args.build_id:
        file_attrs['attrs']['binstar_build'] = args.build_id

    package_name = get_package_name(args, package_attrs, filename, package_type)
    version = get_version(args, release_attrs, package_type)

    logger.info('Creating package "%s"', package_name)

    package = add_package(aserver_api, args, username, package_name, package_attrs, package_type)
    package_types = package.get('package_types', [])

    if package_types and package_type not in package_types:
        message = 'You already have a {} named \'{}\'. Use a different name for this {}.'.format(
            verbose_package_type(package_types[0] if package_types else ''), package_name,
            verbose_package_type(package_type),
        )
        logger.error(message)
        raise errors.BinstarError(message)

    logger.info('Creating release "%s"', version)

    add_release(aserver_api, args, username, package_name, version, release_attrs)
    binstar_package_type = file_attrs.pop('binstar_package_type', package_type)

    with open(filename, 'rb') as fd:
        logger.info('Uploading file "%s/%s/%s/%s"', username, package_name, version, file_attrs['basename'])

        if remove_existing_file(aserver_api, args, username, package_name, version, file_attrs):
            return None

        try:
            upload_info = aserver_api.upload(username, package_name, version, file_attrs['basename'], fd,
                                             binstar_package_type, args.description,
                                             dependencies=file_attrs.get('dependencies'), attrs=file_attrs['attrs'],
                                             channels=args.labels, callback=upload_print_callback(args))
        except errors.Conflict:
            upload_info = {}
            if args.mode != 'skip':
                logger.info('Distribution already exists. Please use the -i/--interactive or --force or --skip options '
                            'or `anaconda remove %s/%s/%s/%s', username, package_name, version, file_attrs['basename'])
                raise
            else:
                logger.info('Distribution already exists. Skipping upload.\n')

        if upload_info:
            logger.info("Upload complete\n")
        else:
            pass

        return [package_name, upload_info]
Exemplo n.º 12
0
def upload_package(filename, package_type, aserver_api, username, args):
    log.info('extracting package attributes for upload ...')
    sys.stdout.flush()
    try:
        package_attrs, release_attrs, file_attrs = get_attrs(package_type,
                                                             filename,
                                                             parser_args=args)
    except Exception:
        if args.show_traceback:
            raise
        message = 'Trouble reading metadata from {}. Is this a valid {} package'.format(
            filename, package_type)
        log.error(message)
        raise errors.BinstarError(message)

    if args.build_id:
        file_attrs['attrs']['binstar_build'] = args.build_id

    log.info('done')

    package_name = get_package_name(args, package_attrs, filename,
                                    package_type)
    version = get_version(args, release_attrs, package_type)

    add_package(aserver_api, args, username, package_name, package_attrs,
                package_type)
    add_release(aserver_api, args, username, package_name, version,
                release_attrs)
    binstar_package_type = file_attrs.pop('binstar_package_type', package_type)

    with open(filename, 'rb') as fd:
        log.info('\nUploading file %s/%s/%s/%s ... ' %
                 (username, package_name, version, file_attrs['basename']))
        sys.stdout.flush()

        if remove_existing_file(aserver_api, args, username, package_name,
                                version, file_attrs):
            return None
        try:
            upload_info = aserver_api.upload(
                username,
                package_name,
                version,
                file_attrs['basename'],
                fd,
                binstar_package_type,
                args.description,
                dependencies=file_attrs.get('dependencies'),
                attrs=file_attrs['attrs'],
                channels=args.labels,
                callback=upload_print_callback(args))
        except errors.Conflict:
            full_name = '%s/%s/%s/%s' % (username, package_name, version,
                                         file_attrs['basename'])
            log.info(
                'Distribution already exists. Please use the '
                '-i/--interactive or --force options or `anaconda remove %s`' %
                full_name)
            raise

        log.info("\n\nUpload(s) Complete\n")
        return [package_name, upload_info]