Пример #1
0
def upload(cli, meta, owner, channels=['main'], config=None):
    """Upload a distribution, given the build metadata."""
    if hasattr(conda_build, 'api'):
        fname = bldpkg_path(meta, config)
    else:
        fname = bldpkg_path(meta)
    package_type = detect_package_type(fname)
    package_attrs, release_attrs, file_attrs = get_attrs(package_type, fname)
    package_name = package_attrs['name']
    version = release_attrs['version']

    # Check the package exists, otherwise create one.
    try:
        cli.package(owner, package_name)
    except binstar_client.NotFound:
        print('Creating the {} package on {}'.format(package_name, owner))
        summary = package_attrs['summary']
        cli.add_package(owner,
                        package_name,
                        summary,
                        package_attrs.get('license'),
                        public=True)

    # Check the release exists, otherwise create one.
    try:
        cli.release(owner, package_name, version)
    except binstar_client.NotFound:
        # TODO: Add readme.md support for descriptions?
        cli.add_release(owner,
                        package_name,
                        version,
                        requirements=[],
                        announce=None,
                        description='')

    try:
        cli.distribution(owner, package_name, version, file_attrs['basename'])
    except binstar_client.NotFound:
        # The file doesn't exist.
        pass
    else:
        print('Distribution %s already exists ... removing' %
              (file_attrs['basename'], ))
        cli.remove_dist(owner, package_name, version, file_attrs['basename'])

    with open(fname, 'rb') as fd:
        print('\nUploading file %s/%s/%s/%s to %s...' %
              (owner, package_name, version, file_attrs['basename'], channels))
        upload_info = cli.upload(owner,
                                 package_name,
                                 version,
                                 file_attrs['basename'],
                                 fd,
                                 package_type,
                                 description='',
                                 dependencies=file_attrs.get('dependencies'),
                                 attrs=file_attrs['attrs'],
                                 channels=channels)
        return upload_info
Пример #2
0
def main(args):

    binstar = get_binstar(args)

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

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

    log.info('detecting package type ...')
    sys.stdout.flush()
    package_type = detect_package_type(args.filename)
    if package_type is None:
        raise UserError('Could not detect package type of file %r' %
                        args.filename)

    log.info(package_type)

    log.info('extracting package attributes ...')
    sys.stdout.flush()
    try:
        package_attrs = get_attrs(package_type, args.filename)
    except Exception:
        if args.show_traceback:
            raise

        raise BinstarError(
            'Trouble reading metadata from %r. Please make sure this package is correct.'
            % (args.filename))

    _, package_name, _, _, summary, _, license = package_attrs

    if args.summary:
        summary = args.summary

    if args.package:
        package_name = args.package

    try:
        binstar.package(username, package_name)
    except NotFound:
        binstar.add_package(username,
                            package_name,
                            summary,
                            license,
                            public=args.access != 'private',
                            publish=args.access == 'publish')
        log.info('Created package %s/%s' % (username, package_name))
    else:
        raise UserError('Package %s/%s already exists' %
                        (username, package_name))
Пример #3
0
def main(args):

    binstar = get_binstar(args)

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

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

    log.info('detecting package type ...')
    sys.stdout.flush()
    package_type = detect_package_type(args.filename)
    if package_type is None:
        raise UserError('Could not detect package type of file %r' % args.filename)
    
    log.info(package_type)

    log.info('extracting package attributes ...')
    sys.stdout.flush()
    try:
        package_attrs = get_attrs(package_type, args.filename)
    except Exception:
        if args.show_traceback:
            raise
        
        raise BinstarError('Trouble reading metadata from %r. Please make sure this package is correct.' % (args.filename))
        
    _, package_name, _, _, summary, _, license = package_attrs
    
    if args.summary:
        summary = args.summary
        
    if args.package:
        package_name = args.package

    try:
        binstar.package(username, package_name)
    except NotFound:
        binstar.add_package(username, package_name,
                            summary,
                            license,
                            public=args.access != 'private',
                            publish=args.access == 'publish')
        log.info('Created package %s/%s' % (username, package_name))
    else:
        raise UserError('Package %s/%s already exists' % (username, package_name))
Пример #4
0
def upload(cli, meta, owner, channels=['main'], config=None):
    """Upload a distribution, given the build metadata."""
    fname = get_output_file_path(meta)
    package_type = detect_package_type(fname)
    package_attrs, release_attrs, file_attrs = get_attrs(package_type, fname)
    package_name = package_attrs['name']
    version = release_attrs['version']

    # Check the package exists, otherwise create one.
    try:
        cli.package(owner, package_name)
    except binstar_client.NotFound:
        print('Creating the {} package on {}'.format(package_name, owner))
        summary = package_attrs['summary']
        cli.add_package(owner, package_name, summary, package_attrs.get('license'), public=True)

    # Check the release exists, otherwise create one.
    try:
        cli.release(owner, package_name, version)
    except binstar_client.NotFound:
        # TODO: Add readme.md support for descriptions?

        # The signature for add_release changed in anaconda-client 1.6.3.
        # First try the old signature, and if that fails, use the new.
        try:
            cli.add_release(owner, package_name, version, requirements=[],
                            announce=None, description='')
        except TypeError:
            cli.add_release(owner, package_name, version, requirements=[],
                            announce=None, release_attrs={'description': ''})

    try:
        cli.distribution(owner, package_name, version, file_attrs['basename'])
    except binstar_client.NotFound:
        # The file doesn't exist.
        pass
    else:
        print('Distribution %s already exists ... removing' % (file_attrs['basename'],))
        cli.remove_dist(owner, package_name, version, file_attrs['basename'])

    with open(fname, 'rb') as fd:
        print('\nUploading file %s/%s/%s/%s to %s...' % (owner, package_name, version, file_attrs['basename'], channels))
        upload_info = cli.upload(owner, package_name, version, file_attrs['basename'],
                                 fd, package_type, description='',
                                 dependencies=file_attrs.get('dependencies'),
                                 attrs=file_attrs['attrs'],
                                 channels=channels)
        return upload_info
Пример #5
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)
Пример #6
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))
Пример #7
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]
Пример #8
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]
Пример #9
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]