Example #1
0
    def run(self, args):
        cli.echo()
        try:
            module_specs = api.resolve(args.modules)
        except ResolveError:
            sys.exit(1)

        cli.echo()
        for spec in module_specs:
            cli.echo(
                cli.format_section(
                    spec.real_name,
                    [(k, str(v)) for k, v in sorted(spec._asdict().items())]))
            cli.echo()
Example #2
0
    def run(self, args):
        cli.echo()
        if args.env:
            return self.run_env(args.module_or_environment)

        try:
            module_spec = api.resolve([args.module_or_environment])[0]
        except ResolveError:
            sys.exit(1)

        if not isinstance(module_spec.repo, LocalRepo):
            cli.echo('%s - %s' % (module_spec.qual_name, module_spec.path))
            cli.echo('Error: Can only edit modules in local repositories.')
            sys.exit(1)

        editor = os.getenv('CPENV_EDITOR', os.getenv('EDITOR', 'subl'))
        cli.echo('Opening %s in %s.' % (module_spec.path, editor))
        shell.run(editor, module_spec.path)
Example #3
0
File: edit.py Project: cpenv/cpenv
    def run(self, args):
        core.echo()
        if args.env:
            return self.run_env(args.module_or_environment)

        try:
            module_spec = api.resolve([args.module_or_environment])[0]
        except ResolveError:
            sys.exit(1)

        if not isinstance(module_spec.repo, repos.LocalRepo):
            core.echo("%s - %s" % (module_spec.qual_name, module_spec.path))
            core.echo("Error: Can only edit modules in local repositories.")
            sys.exit(1)

        editor = os.getenv("CPENV_EDITOR", os.getenv("EDITOR", "subl"))
        core.echo("Opening %s in %s." % (module_spec.path, editor))
        shell.run(editor, module_spec.path)
Example #4
0
File: clone.py Project: cpenv/cpenv
    def run(self, args):

        try:
            if not args.from_repo:
                module_spec = api.resolve([args.module])[0]
            else:
                from_repo = api.get_repo(args.from_repo)
                module_spec = from_repo.find(args.module)[0]
        except Exception:
            core.echo()
            core.echo("Error: Failed to resolve " + args.module)
            core.exit(1)

        where = paths.normalize(args.where or ".", module_spec.real_name)
        if os.path.isdir(where):
            core.echo("Error: Directory already exists - " + where)
            core.exit(1)

        core.echo("- Cloning %s..." % module_spec.real_name)
        core.echo()
        try:
            module = module_spec.repo.download(
                module_spec,
                where=where,
                overwrite=args.overwrite,
            )
        except Exception as e:
            core.echo()
            core.echo("Error: " + str(e))
            core.exit(1)

        core.echo()
        core.echo("Navigate to the following folder to make changes:")
        core.echo("  " + module.path)
        core.echo()
        core.echo("Use one of the following commands to publish your changes:")
        core.echo("  cpenv publish .")
        core.echo('  cpenv publish . --to_repo="repo_name"')
Example #5
0
    def run(self, args):

        cli.echo()

        if args.to_repo:
            to_repo = api.get_repo(name=args.to_repo)
        else:
            repos = [r for r in api.get_repos() if isinstance(r, LocalRepo)]
            to_repo = prompt_for_repo(
                repos,
                'Choose a repo to localize to',
                default_repo_name='home',
            )

        # Resolve modules
        try:
            resolved = api.resolve(args.modules)
        except ResolveError:
            sys.exit(1)

        # Localize modules from remote repos
        remote_modules = [
            spec for spec in resolved if not isinstance(spec.repo, LocalRepo)
        ]

        if not len(remote_modules):
            cli.echo('All modules are already local...')
            sys.exit()

        try:
            localizer = Localizer(to_repo)
            localizer.localize(
                remote_modules,
                overwrite=args.overwrite,
            )
        except Exception as e:
            cli.echo('Error: ' + str(e))
            sys.exit(1)
Example #6
0
    def run(self, args):
        if args.home:
            cli.echo(cpenv.get_home_path())
            return

        if args.cache:
            cli.echo(cpenv.get_cache_path())
            return

        # Key mode - print a key's value of a module or repo.
        if args.key:
            cpenv.set_reporter(Reporter())
            if args.repo:
                objects = []
                for repo_name in args.modules:
                    repo = api.get_repo(repo_name)
                    if repo is None:
                        cli.echo('Could not find repo %s' % repo_name)
                        sys.exit(1)
                    objects.append(repo)
            else:
                try:
                    objects = api.resolve(args.modules)
                except ResolveError:
                    sys.exit(1)

            value = self._get_key(objects[0], args.key)
            cli.echo(value)
            return

        # Normal mode - resolve repos or modules and show info.
        cli.echo()
        if args.repo:
            repos = []
            for repo_name in args.modules:
                repo = api.get_repo(repo_name)
                if repo is None:
                    cli.echo('Could not find repo %s' % repo_name)
                    sys.exit(1)
                repos.append(repo)

            for repo in repos:
                cli.echo(
                    cli.format_section(repo.name, [
                        ('name', repo.name),
                        ('path', repo.path),
                        ('type', str(type(repo))),
                        ('type_name', repo.type_name),
                    ]))
                cli.echo()
            return
        else:
            try:
                module_specs = api.resolve(args.modules)
            except ResolveError:
                sys.exit(1)

            cli.echo()
            for spec in module_specs:
                cli.echo(
                    cli.format_section(
                        spec.qual_name,
                        [(k, str(v))
                         for k, v in sorted(spec._asdict().items())],
                    ))
                cli.echo()
            return