Exemple #1
0
    def run(self, args):

        cli.echo()

        # Get repo
        if args.to_repo:
            to_repo = api.get_repo(name=args.to_repo)
        else:
            to_repo = prompt_for_repo(
                api.get_repos(),
                'Choose a repo to publish to',
                default_repo_name='home',
            )

        # Resolve module
        resolver = Resolver(api.get_repos())
        module_spec = resolver.resolve([args.module])[0]
        cli.echo()

        # Confirm publication
        choice = cli.prompt('Publish module to %s?[y/n] ' % to_repo.name)
        if choice.lower() not in ['y', 'yes', 'yup']:
            cli.echo('Aborted.')
            sys.exit(1)

        # Publish
        module = Module(module_spec.path)
        published = to_repo.upload(module, args.overwrite)
        cli.echo()

        cli.echo('Activate your module:')
        cli.echo('  cpenv activate %s' % published.real_name)
        cli.echo()
Exemple #2
0
    def run(self, args):
        where = paths.normalize(args.where)
        if os.path.isdir(where):
            cli.echo()
            cli.echo('Error: Can not create module in existing directory.')
            sys.exit(1)

        default_name, default_version = parse_module_path(where)

        cli.echo()
        cli.echo('This command will guide you through creating a new module.')
        cli.echo()
        name = cli.prompt('  Module Name [%s]: ' % default_name)
        version = cli.prompt('  Version [%s]: ' % default_version.string)
        description = cli.prompt('  Description []: ')
        author = cli.prompt('  Author []: ')
        email = cli.prompt('  Email []: ')

        cli.echo()
        cli.echo('- Creating your new Module...', end='')
        module = api.create(
            where=where,
            name=name or default_name,
            version=version or default_version.string,
            description=description,
            author=author,
            email=email,
        )
        cli.echo('OK!')

        cli.echo()
        cli.echo('  ' + module.path)

        cli.echo()
        cli.echo('Steps you might take before publishing...')
        cli.echo()
        cli.echo('  - Include binaries your module depends on')
        cli.echo('  - Edit the module.yml file')
        cli.echo('    - Add variables to the environment section')
        cli.echo('    - Add other modules to the requires section')
        cli.echo('  - Add python hooks like post_activate')
        cli.echo()
Exemple #3
0
def prompt_for_repo(repos, message, default_repo_name='home'):
    '''Prompt a user to select a repository'''

    default = 0
    for i, from_repo in enumerate(repos):
        if from_repo.name == default_repo_name:
            default = i
        if from_repo.name == from_repo.path:
            line = '  [{}] {}'.format(i, from_repo.path)
        else:
            line = '  [{}] {} - {}'.format(
                i,
                from_repo.name,
                from_repo.path,
            )
        cli.echo(line)

    # Prompt user to choose a repo defaults to home
    cli.echo()
    choice = cli.prompt('{} [{}]: '.format(message, default))

    if not choice:
        choice = default
        cli.echo()
        return repos[choice]

    try:
        choice = int(choice)
        value_error = False
    except ValueError:
        value_error = True

    if value_error or choice > len(repos) - 1:
        cli.echo()
        cli.echo('Error: {!r} is not a valid choice'.format(choice))
        sys.exit(1)

    cli.echo()

    # Get the repo the user chose
    return repos[choice]
Exemple #4
0
    def run(self, args):

        cli.echo()

        if args.from_repo:
            from_repo = api.get_repo(name=args.from_repo)
        else:
            from_repo = prompt_for_repo(
                api.get_repos(),
                'Choose a repo to remove module from',
                default_repo_name='home',
            )

        cli.echo('- Finding modules in %s...' % from_repo.name)
        cli.echo()
        modules_to_remove = []
        for requirement in args.modules:
            module = best_match(requirement, from_repo.find(requirement))
            if not module:
                cli.echo('Error: %s not found...' % requirement)
                sys.exit(1)
            cli.echo('  %s - %s' % (module.real_name, module.path))
            modules_to_remove.append(module)

        cli.echo()
        choice = cli.prompt('Delete these modules?[y/n] ')
        if choice.lower() not in ['y', 'yes', 'yup']:
            cli.echo('Aborted.')
            sys.exit(1)

        cli.echo()
        cli.echo('- Removing modules...')
        cli.echo()
        for module in modules_to_remove:
            cli.echo('  ' + module.real_name)
            api.remove(module, from_repo)

        cli.echo()
        cli.echo('Successfully removed modules.')
        cli.echo()
Exemple #5
0
    def run(self, args):

        cli.echo()

        if args.from_repo:
            from_repo = api.get_repo(args.from_repo)
        else:
            from_repo = prompt_for_repo(
                api.get_repos(),
                'Download from',
                default_repo_name='home',
            )

        if args.to_repo:
            to_repo = api.get_repo(args.to_repo)
        else:
            repos = api.get_repos()
            repos.remove(from_repo)
            to_repo = prompt_for_repo(
                repos,
                'Upload to',
                default_repo_name='home',
            )

        resolver = Resolver([from_repo])
        module_specs = resolver.resolve(args.modules)
        cli.echo()

        choice = cli.prompt('Copy these modules to %s?[y/n] ' % to_repo.name)
        if choice.lower() not in ['y', 'yes', 'yup']:
            cli.echo('Aborted.')
            sys.exit(1)
        cli.echo()

        copier = Copier(to_repo)
        copier.copy(module_specs, args.overwrite)