예제 #1
0
def main(args):

    binstar = get_binstar(args)

    for spec in args.specs:
        try:
            if spec._basename:
                msg = 'Are you sure you want to remove file %s ?' % (spec, )
                if not args.force and bool_input(msg, False):
                    binstar.remove_dist(spec.user, spec.package, spec.version,
                                        spec.basename)
                else:
                    log.warn('Not removing file %s' % (spec))
            elif spec._version:
                msg = 'Are you sure you want to remove the package release %s ? (and all files under it?)' % (
                    spec, )
                if not args.force and bool_input(msg, False):
                    binstar.remove_release(spec.user, spec.package,
                                           spec.version)
                else:
                    log.warn('Not removing release %s' % (spec))
            elif spec._package:
                msg = 'Are you sure you want to remove the package %s ? (and all data with it?)' % (
                    spec, )
                if not args.force and bool_input(msg, False):
                    binstar.remove_package(spec.user, spec.package)
                else:
                    log.warn('Not removing release %s' % (spec))

        except NotFound:
            if args.force:
                continue
            else:
                raise
예제 #2
0
def main(args):

    aserver_api = get_server_api(args.token, args.site)

    for spec in args.specs:
        try:
            if spec._basename:
                msg = 'Are you sure you want to remove file %s ?' % (spec,)
                if args.force or bool_input(msg, False):
                    aserver_api.remove_dist(spec.user, spec.package, spec.version, spec.basename)
                else:
                    logger.warning('Not removing file %s' % (spec))
            elif spec._version:
                msg = 'Are you sure you want to remove the package release %s ? (and all files under it?)' % (spec,)
                if args.force or bool_input(msg, False):
                    aserver_api.remove_release(spec.user, spec.package, spec.version)
                else:
                    logger.warning('Not removing release %s' % (spec))
            elif spec._package:
                msg = 'Are you sure you want to remove the package %s ? (and all data with it?)' % (spec,)
                if args.force or bool_input(msg, False):
                    aserver_api.remove_package(spec.user, spec.package)
                else:
                    logger.warning('Not removing release %s' % (spec))
            else:
                logger.error('Invalid package specification: %s', spec)

        except errors.NotFound:
            if args.force:
                logger.warning('', exc_info=True)
                continue
            else:
                raise
예제 #3
0
파일: remove.py 프로젝트: Casolt/binstar
def main(args):

    binstar = get_binstar(args)

    for spec in args.specs:
        try:
            if spec._basename:
                msg = 'Are you sure you want to remove file %s ?' % (spec,)
                if args.force or bool_input(msg, False):
                    binstar.remove_dist(spec.user, spec.package, spec.version, spec.basename)
                else:
                    log.warn('Not removing file %s' % (spec))
            elif spec._version:
                msg = 'Are you sure you want to remove the package release %s ? (and all files under it?)' % (spec,)
                if args.force or bool_input(msg, False):
                    binstar.remove_release(spec.user, spec.package, spec.version)
                else:
                    log.warn('Not removing release %s' % (spec))
            elif spec._package:
                msg = 'Are you sure you want to remove the package %s ? (and all data with it?)' % (spec,)
                if args.force or bool_input(msg, False):
                    binstar.remove_package(spec.user, spec.package)
                else:
                    log.warn('Not removing release %s' % (spec))

        except NotFound:
            if args.force:
                continue
            else:
                raise
예제 #4
0
def create_package_interactive(binstar, username, package_name, public=True, publish=True):

    log.info('\nThe package %s/%s does not exist' % (username, package_name))
    if not bool_input('Would you lke to create it now?'):
        log.info('goodbbye')
        raise SystemExit(-1)

    summary = raw_input('Enter a short description of the package\nsummary: ')
    license = raw_input('Enter the name of the license (default:BSD)\nlicense: ')
    license_url = raw_input('Enter the url of the license (optional)\nlicense url: ')
    public = bool_input('\nDo you want to make this package public?', public)
    if public:
        publish = bool_input('\nDo you want to make publish this package?\n'
                             'When published it will be added to the global public repositories.',
                             public)
    else:
        publish = False

    binstar.add_package(username, package_name,
                    summary,
                    license,
                    license_url,
                    public,
                    public=public,
                    publish=publish)
예제 #5
0
def main(args):

    aserver_api = get_server_api(args.token, args.site, args.log_level)

    for spec in args.specs:
        try:
            if spec._basename:
                msg = 'Are you sure you want to remove file %s ?' % (spec,)
                if args.force or bool_input(msg, False):
                    aserver_api.remove_dist(spec.user, spec.package, spec.version, spec.basename)
                else:
                    log.warn('Not removing file %s' % (spec))
            elif spec._version:
                msg = 'Are you sure you want to remove the package release %s ? (and all files under it?)' % (spec,)
                if args.force or bool_input(msg, False):
                    aserver_api.remove_release(spec.user, spec.package, spec.version)
                else:
                    log.warn('Not removing release %s' % (spec))
            elif spec._package:
                msg = 'Are you sure you want to remove the package %s ? (and all data with it?)' % (spec,)
                if args.force or bool_input(msg, False):
                    aserver_api.remove_package(spec.user, spec.package)
                else:
                    log.warn('Not removing release %s' % (spec))
            else:
                log.error('Invalid package specification: %s', spec)

        except errors.NotFound:
            if args.force:
                log.warn('', exc_info=True)
                continue
            else:
                raise
def init_build(args):

    binstar = get_binstar()

    # Force user auth
    user = binstar.user()

    binstar_yml = join(args.path, '.binstar.yml')

    if os.path.exists(binstar_yml):
        result = bool_input("The file '%s' already exists. Would you like to overwrite it?" % binstar_yml,
                            default=False)
        if not result:
            log.error('goodbye')
            sys.exit(1)

    name = basename(abspath(args.path))
    package_name = input('Please choose a name for this package: (default %s)\n> ' % name)
    package_name = package_name or name


    with open(binstar_yml, 'w') as fd:
        fd.write(initial_build_config % dict(PACKAGE_NAME=package_name))
    log.info("Wrote file '%s'" % binstar_yml)

    try:
        _ = binstar.package(user['login'], package_name)
    except errors.NotFound:
        log.warn('The package %(username)s/%(name)s does not exist\n'
                 'Please run:\n   binstar package %(username)s/%(name)s --create' % dict(username=user['login'], name=package_name))
    log.info("Run 'binstar build --submit' to submit your first build")
    return
예제 #7
0
def try_replace_token(authenticate, **kwargs):
    """
    Authenticates using the given *authenticate*, retrying if the token needs
    to be replaced.
    """

    try:
        return authenticate(**kwargs)
    except errors.BinstarError as err:
        if kwargs.get('fail_if_already_exists') and len(
                err.args) > 1 and err.args[1] == 400:
            logger.warning(
                'It appears you are already logged in from host %s' %
                socket.gethostname())
            logger.warning(
                'Logging in again will remove the previous token. (This could cause troubles with virtual '
                'machines with the same hostname)')
            logger.warning(
                'Otherwise you can login again and specify a different hostname with "--hostname"'
            )

            if bool_input("Would you like to continue"):
                kwargs['fail_if_already_exists'] = False
                return authenticate(**kwargs)

        raise
예제 #8
0
def create_release_interactive(aserver_api, username, package_name, version):

    log.info('\nThe release %s/%s/%s does not exist' % (username, package_name, version))
    if not bool_input('Would you like to create it now?'):
        log.info('good-bye')
        raise SystemExit(-1)

    description = input('Enter a short description of the release:\n')
    log.info("\nAnnouncements are emailed to your package followers.")
    make_announcement = bool_input('Would you like to make an announcement to the package followers?', False)
    if make_announcement:
        announce = input('Markdown Announcement:\n')
    else:
        announce = ''

    aserver_api.add_release(username, package_name, version, [],
                        announce, description)
예제 #9
0
def create_package_interactive(binstar, username, package_name):
    
    print '\nThe package %s/%s does not exist' % (username, package_name)
    if not bool_input('Would you lke to create it now?'):
        print 'goodbbye'
        raise SystemExit(-1)
    
    summary = raw_input('Enter a short description of the package\nsummary: ')
    license = raw_input('Enter the name of the license (default:BSD)\nlicense: ')
    license_url = raw_input('Enter the url of the license (optional)\nlicense url: ')
    public = bool_input('\nDo you want to make this package public?')
    
    binstar.add_package(username, package_name,
                    summary,
                    license,
                    license_url,
                    public)
예제 #10
0
파일: login.py 프로젝트: Casolt/binstar
def interactive_get_token(args):
    bs = get_binstar(args)
    config = get_config(remote_site=args.site)

    url = config.get('url', 'https://api.binstar.org')

    token = None
    hostname = getattr(args, 'hostname', platform.node())
    username = input('Username: '******'binstar_client:'
    site = args.site or config.get('default_site')
    if site and site != 'binstar':
        # For testing with binstar alpha site
        auth_name += '%s:' % site

    auth_name += '%s@%s' % (getpass.getuser(), hostname)

    password = None
    for _ in range(3):
        try:
            sys.stderr.write("%s's " % username)

            if password is None:
                password = getpass.getpass(stream=sys.stderr)

            token = bs.authenticate(username, password, auth_name, url,
                                    created_with=' '.join(sys.argv),
                                    fail_if_already_exists=True,
                                    hostname=hostname)
            break

        except errors.Unauthorized:
            log.error('Invalid Username password combination, please try again')
            password = None
            continue

        except errors.BinstarError as err:
            if err.args[1] == 400:
                log.error('It appears you are already logged in from host %s' % socket.gethostname())
                log.error('Logging in again will remove the previous token.')
                log.error('Otherwise you can login again and specify a '
                          'different hostname with "--hostname"')
                if bool_input("Would you like to continue"):
                    bs.remove_authentication(auth_name)
                    continue
                else:
                    raise


    if token is None:
        msg = ('Sorry. Please try again '
               '(go to https://binstar.org/account/forgot_password '
               'to reset your password)')
        raise errors.BinstarError(msg)

    return token
예제 #11
0
def main(args):
    bs = get_binstar(args, cls=BinstarBuildAPI)

    if args.queue is None:
        username = queue_name = None
    elif args.queue.count('/') == 1:
        username, queue_name = args.queue.split('/', 1)
    elif args.queue.count('/') == 2:
        _, username, queue_name = args.queue.split('/', 2)
    elif args.queue.count('-') == 2:
        _, username, queue_name = args.queue.split('-', 2)
    else:
        raise errors.UserError(
            "Build queue must be of the form build-USERNAME-QUEUENAME or USERNAME/QUEUENAME"
        )

    if args.create:

        if queue_name is None:
            raise errors.BinstarError("Must specify a queue name to create")
        if not is_valid_name(queue_name):
            raise errors.BinstarError(
                'Invalid name for '
                'queue: {}.  Must start'
                ' with a letter and contain'
                ' only numbers, letters, -, and _'.format(queue_name))

        bs.add_build_queue(username, queue_name)
        print("Created queue %s" % queue_name)
        return

    if queue_name:
        queue = bs.build_queue(username, queue_name)

    if args.remove:
        if queue.get('workers'):
            prompt = ('This build queue still has workers attached. '
                      'Are you sure you want to remove it')
            if not bool_input(prompt, False):
                print("Not removing queue")
                return
        bs.remove_build_queue(username, queue_name)
        print("Removed queue %s" % queue_name)
        return

    if args.remove_worker:
        bs.remove_worker(username, queue_name, args.remove_worker)
        print("Removed worker %s from queue %s" %
              (args.remove_worker, queue_name))
        return

    if queue_name:
        print()
        show_queue(queue)
    else:
        show_queues(bs, username)
예제 #12
0
def main(args):
    bs = get_binstar(args, cls=BinstarBuildAPI)

    if args.queue is None:
        username = queue_name = None
    elif args.queue.count('/') == 1:
        username, queue_name = args.queue.split('/', 1)
    elif args.queue.count('/') == 2:
        _, username, queue_name = args.queue.split('/', 2)
    elif args.queue.count('-') == 2:
        _, username, queue_name = args.queue.split('-', 2)
    else:
        raise errors.UserError("Build queue must be of the form build-USERNAME-QUEUENAME or USERNAME/QUEUENAME")

    if args.create:

        if queue_name is None:
            raise errors.BinstarError("Must specify a queue name to create")
        if not is_valid_name(queue_name):
            raise errors.BinstarError('Invalid name for '
                                      'queue: {}.  Must start'
                                      ' with a letter and contain'
                                      ' only numbers, letters, -, and _'.format(queue_name))

        bs.add_build_queue(username, queue_name)
        print("Created queue %s" % queue_name)
        return

    if queue_name:
        queue = bs.build_queue(username, queue_name)

    if args.remove:
        if queue.get('workers'):
            prompt = ('This build queue still has workers attached. '
                      'Are you sure you want to remove it')
            if not bool_input(prompt, False):
                print("Not removing queue")
                return
        bs.remove_build_queue(username, queue_name)
        print("Removed queue %s" % queue_name)
        return

    if args.remove_worker:
        bs.remove_worker(username, queue_name, args.remove_worker)
        print("Removed worker %s from queue %s" % (args.remove_worker, queue_name))
        return


    if queue_name:
        print()
        show_queue(queue)
    else:
        show_queues(bs, username)
예제 #13
0
def main(args):
    
    binstar = get_binstar()
    
    for spec in args.specs:
        try:
            if not args.force and bool_input('Are you sure you want to remove file %s' % (spec,), False):
                binstar.remove_dist(spec.user, spec.package, spec.version, spec.basename)
            else:
                print 'Not removing file %s' %(spec)
        except NotFound:
            if args.force:
                continue
            else:
                raise
예제 #14
0
def create_package_interactive(binstar, username, package_name, public=True, publish=True):

    log.info('\nThe package %s/%s does not exist' % (username, package_name))
    if not bool_input('Would you lke to create it now?'):
        log.info('goodbbye')
        raise SystemExit(-1)

    summary = raw_input('Enter a short description of the package\nsummary: ')
    license = raw_input('Enter the name of the license (default:BSD)\nlicense: ')
    license_url = raw_input('Enter the url of the license (optional)\nlicense url: ')
    public = bool_input('\nDo you want to make this package public?', public)
    if public:
        publish = bool_input('\nDo you want to make publish this package?\n'
                             'When published it will be added to the global public repositories.',
                             public)
    else:
        publish = False

    binstar.add_package(username, package_name,
                    summary,
                    license,
                    license_url,
                    public=public,
                    publish=publish)
예제 #15
0
def remove_existing_file(aserver_api, args, username, package_name, version, file_attrs):
    try:
        aserver_api.distribution(username, package_name, version, file_attrs['basename'])
    except errors.NotFound:
        return False
    else:
        if args.mode == 'force':
            log.warning('Distribution %s already exists ... removing' % (file_attrs['basename'],))
            aserver_api.remove_dist(username, package_name, version, file_attrs['basename'])
        if args.mode == 'interactive':
            if bool_input('Distribution %s already exists. Would you like to replace it?' % (file_attrs['basename'],)):
                aserver_api.remove_dist(username, package_name, version, file_attrs['basename'])
            else:
                log.info('Not replacing distribution %s' % (file_attrs['basename'],))
                return True
예제 #16
0
def try_replace_token(authenticate, **kwargs):
    '''
    Authenticates using the given *authenticate*, retrying if the token needs
    to be replaced.
    '''

    try:
        return authenticate(**kwargs)
    except errors.BinstarError as err:
        if kwargs.get('fail_if_already_exists') and len(err.args) > 1 and err.args[1] == 400:
            log.warn('It appears you are already logged in from host %s' % socket.gethostname())
            log.warn('Logging in again will remove the previous token. '
                     ' (This could cause troubles with virtual machines with the same hostname)')
            log.warn('Otherwise you can login again and specify a '
                      'different hostname with "--hostname"')
            if bool_input("Would you like to continue"):
                kwargs['fail_if_already_exists'] = False
                return authenticate(**kwargs)

        raise
예제 #17
0
def init_build(args):

    binstar = get_binstar()

    # Force user auth
    user = binstar.user()

    binstar_yml = join(args.path, '.binstar.yml')

    if os.path.exists(binstar_yml):
        result = bool_input(
            "The file '%s' already exists. Would you like to overwrite it?" %
            binstar_yml,
            default=False)
        if not result:
            log.error('goodby')
            sys.exit(1)

    name = basename(abspath(args.path))
    package_name = input(
        'Please choose a name for this package: (default %s)\n> ' % name)
    package_name = package_name or name

    with open(binstar_yml, 'w') as fd:
        fd.write(initial_build_config % dict(PACKAGE_NAME=package_name))
    log.info("Wrote file '%s'" % binstar_yml)

    try:
        _ = binstar.package(user['login'], package_name)
    except errors.NotFound:
        log.warn(
            'The package %(username)s/%(name)s does not exist\n'
            'Please run:\n   binstar package %(username)s/%(name)s --create' %
            dict(username=user['login'], name=package_name))
    log.info("Run 'binstar build --submit' to submit your first build")
    return
예제 #18
0
def interactive_get_token(args, fail_if_already_exists=True):
    bs = get_server_api(args.token, args.site, args.log_level)
    config = get_config(remote_site=args.site)

    url = config.get('url', 'https://api.anaconda.org')
    parsed_url = urlparse(url)
    token = None
    hostname = getattr(args, 'hostname', platform.node())
    if getattr(args, 'login_username', None):
        username = args.login_username
    else:
        username = input('Username: '******'binstar_client:'
    site = args.site or config.get('default_site')
    if site and site != 'binstar':
        # For testing with binstar alpha site
        auth_name += '%s:' % site

    auth_name += '%s@%s' % (getpass.getuser(), hostname)

    password = getattr(args, 'login_password', None)

    for _ in range(3):
        try:
            sys.stderr.write("%s's " % username)

            if password is None:
                password = getpass.getpass(stream=sys.stderr)

            token = bs.authenticate(
                username,
                password,
                auth_name,
                url,
                created_with=' '.join(sys.argv),
                fail_if_already_exists=fail_if_already_exists,
                hostname=hostname)
            break

        except errors.Unauthorized:
            log.error(
                'Invalid Username password combination, please try again')
            password = None
            continue

        except errors.BinstarError as err:
            if fail_if_already_exists is True and err.args[1] == 400:
                log.warn('It appears you are already logged in from host %s' %
                         socket.gethostname())
                log.warn(
                    'Logging in again will remove the previous token. '
                    ' (This could cause troubles with virtual machines with the same hostname)'
                )
                log.warn('Otherwise you can login again and specify a '
                         'different hostname with "--hostname"')
                if bool_input("Would you like to continue"):
                    fail_if_already_exists = False
                    continue
                else:
                    raise

    if token is None:
        if parsed_url.netloc.startswith('api.anaconda.org'):
            netloc = 'anaconda.org'
        else:
            netloc = parsed_url.netloc
        hostparts = (parsed_url.scheme, netloc)
        msg = ('Sorry. Please try again ' + \
               '(go to %s://%s/account/forgot_password ' % hostparts + \
               'to reset your password)')
        raise errors.BinstarError(msg)

    return token
예제 #19
0
def main(args):

    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)
            log.info(package_type)

        get_attrs = detectors[package_type]

        if args.metadata:
            attrs = json.loads(args.metadata)
            package_name = args.package
            version = args.version
        else:
            log.info('extracting package attributes for upload ...')
            sys.stdout.flush()
            basefilename, package_name, version, attrs, summary, description, license = get_attrs(filename)
            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.mode == 'interactive':
                create_package_interactive(binstar, username, package_name,
                                           public=args.public,
                                           publish=args.publish)
            else:
                create_package(binstar, username, package_name, summary, license,
                               public=args.public,
                               publish=args.publish)


        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 == '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:
                binstar.upload(username, package_name, version, basefilename, fd, package_type, args.description, attrs=attrs,
                           callback=upload_print_callback())
            except Conflict:
                full_name = '%s/%s/%s/%s' % (username, package_name, version, basefilename)
                log.info('Distribution already exists. Please use the -i/--interactive option or `binstar delete %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))
예제 #20
0
파일: login.py 프로젝트: Vasyka/hat
def interactive_get_token(args, fail_if_already_exists=True):
    bs = get_binstar(args)
    config = get_config(remote_site=args.site)

    url = config.get('url', 'https://api.anaconda.org')
    parsed_url = urlparse(url)
    token = None
    hostname = getattr(args, 'hostname', platform.node())
    if getattr(args, 'login_username', None):
        username = args.login_username
    else:
        username = input('Username: '******'binstar_client:'
    site = args.site or config.get('default_site')
    if site and site != 'binstar':
        # For testing with binstar alpha site
        auth_name += '%s:' % site

    auth_name += '%s@%s' % (getpass.getuser(), hostname)

    password = getattr(args, 'login_password', None)

    for _ in range(3):
        try:
            sys.stderr.write("%s's " % username)

            if password is None:
                password = getpass.getpass(stream=sys.stderr)

            token = bs.authenticate(username, password, auth_name, url,
                                    created_with=' '.join(sys.argv),
                                    fail_if_already_exists=fail_if_already_exists,
                                    hostname=hostname)
            break

        except errors.Unauthorized:
            log.error('Invalid Username password combination, please try again')
            password = None
            continue

        except errors.BinstarError as err:
            if fail_if_already_exists is True and err.args[1] == 400:
                log.warn('It appears you are already logged in from host %s' % socket.gethostname())
                log.warn('Logging in again will remove the previous token. '
                         ' (This could cause troubles with virtual machines with the same hostname)')
                log.warn('Otherwise you can login again and specify a '
                          'different hostname with "--hostname"')
                if bool_input("Would you like to continue"):
                    fail_if_already_exists = False
                    continue
                else:
                    raise


    if token is None:
        if parsed_url.netloc.startswith('api.anaconda.org'):
            netloc = 'anaconda.org'
        else:
            netloc = parsed_url.netloc
        hostparts = (parsed_url.scheme, netloc)
        msg = ('Sorry. Please try again ' +\
               '(go to %s://%s/account/forgot_password ' % hostparts +\
               'to reset your password)')
        raise errors.BinstarError(msg)

    return token
예제 #21
0
def interactive_get_token(args, fail_if_already_exists=True):
    bs = get_binstar(args)
    config = get_config(remote_site=args.site)

    url = config.get("url", "https://api.anaconda.org")

    token = None
    hostname = getattr(args, "hostname", platform.node())
    if getattr(args, "login_username", None):
        username = args.login_username
    else:
        username = input("Username: "******"binstar_client:"
    site = args.site or config.get("default_site")
    if site and site != "binstar":
        # For testing with binstar alpha site
        auth_name += "%s:" % site

    auth_name += "%s@%s" % (getpass.getuser(), hostname)

    password = getattr(args, "login_password", None)

    for _ in range(3):
        try:
            sys.stderr.write("%s's " % username)

            if password is None:
                password = getpass.getpass(stream=sys.stderr)

            token = bs.authenticate(
                username,
                password,
                auth_name,
                url,
                created_with=" ".join(sys.argv),
                fail_if_already_exists=fail_if_already_exists,
                hostname=hostname,
            )
            break

        except errors.Unauthorized:
            log.error("Invalid Username password combination, please try again")
            password = None
            continue

        except errors.BinstarError as err:
            if fail_if_already_exists is True and err.args[1] == 400:
                log.warn("It appears you are already logged in from host %s" % socket.gethostname())
                log.warn(
                    "Logging in again will remove the previous token. "
                    " (This could cause troubles with virtual machines with the same hostname)"
                )
                log.warn("Otherwise you can login again and specify a " 'different hostname with "--hostname"')
                if bool_input("Would you like to continue"):
                    fail_if_already_exists = False
                    continue
                else:
                    raise

    if token is None:
        msg = (
            "Sorry. Please try again " "(go to https://anaconda.org/account/forgot_password " "to reset your password)"
        )
        raise errors.BinstarError(msg)

    return token
예제 #22
0
def main(args):

    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)
            log.info(package_type)

        get_attrs = detectors[package_type]

        if args.metadata:
            attrs = json.loads(args.metadata)
            package_name = args.package
            version = args.version
        else:
            log.info('extracting package attributes for upload ...')
            sys.stdout.flush()
            basefilename, package_name, version, attrs, summary, description, license = get_attrs(filename)
            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.mode == 'interactive':
                create_package_interactive(binstar, username, package_name,
                                           public=args.public,
                                           publish=args.publish)
            else:
                create_package(binstar, username, package_name, summary, license,
                               public=args.public,
                               publish=args.publish)


        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 == '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:
                binstar.upload(username, package_name, version, basefilename, fd, package_type, args.description, attrs=attrs,
                           callback=upload_print_callback())
            except Conflict:
                full_name = '%s/%s/%s/%s' % (username, package_name, version, basefilename)
                log.info('Distribution already exists. Please use the -i/--interactive option 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))
예제 #23
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))