コード例 #1
0
ファイル: workspace_test.py プロジェクト: hackolite/yoda
 def test_not_exists(self):
     """Test workspace doesn't exists."""
     config_mock_data = {
         "workspaces": {"foo": {"path": "/foo", "repositories": {}}}}
     self.config.update(config_mock_data)
     ws = Workspace(self.config)
     self.assertFalse(ws.exists("bar"))
コード例 #2
0
ファイル: workspace_test.py プロジェクト: hackolite/yoda
 def test_exists(self):
     """Test exists workspace."""
     config_mock_data = {
         "workspaces": {"foo": {"path": "/foo", "repositories": {}}}}
     self.config.update(config_mock_data)
     ws = Workspace(self.config)
     self.assertTrue(ws.exists("foo"))
コード例 #3
0
ファイル: show.py プロジェクト: hackolite/yoda
class Show(Subcommand, object):

    workspace = None
    logger = None

    def setup(self, name, config, subparser):
        self.workspace = Workspace(config)
        self.subparser = subparser
        self.logger = logging.getLogger(__name__)
        super(Show, self).setup(name, config, subparser)

    def parse(self):
        """Parse show subcommand."""
        parser = self.subparser.add_parser(
            "show",
            help="Show workspace details",
            description="Show workspace details.")

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument('--all', action='store_true', help="All workspaces")
        group.add_argument('name', type=str, help="Workspace name", nargs='?')

    def execute(self, args):
        """Execute show subcommand."""
        if args.name is not None:
            self.show_workspace(args.name)
        elif args.all is not None:
            self.show_all()

    def show_workspace(self, name):
        """Show specific workspace."""
        if not self.workspace.exists(name):
            raise ValueError("Workspace `%s` doesn't exists." % name)

        color = Color()
        workspaces = self.workspace.list()

        self.logger.info("<== %s workspace ==>" % color.colored(name, "green"))
        self.logger.info("\tPath: %s" % workspaces[name]["path"])
        self.logger.info("\tNumber of repositories: %s"
                         % color.colored(
                             len(workspaces[name]["repositories"]),
                             "yellow"))

        repo_colored = color.colored("Repositories", "blue")
        path_colored = color.colored("Path", "blue")
        trepositories = PrettyTable(
            [repo_colored, path_colored, color.colored("+", "blue")])
        trepositories.align[repo_colored] = "l"
        trepositories.align[path_colored] = "l"

        for repo_name in workspaces[name]["repositories"]:
            fullname = "%s/%s" % (name, repo_name)
            fullpath = find_path(fullname, self.config)[fullname]
            try:
                repo = Repository(fullpath)
                repo_scm = repo.get_scm()
            except RepositoryAdapterNotFound:
                repo_scm = None
            trepositories.add_row(
                [color.colored(repo_name, "cyan"), fullpath, repo_scm])

        self.logger.info(trepositories)

    def show_all(self):
        """Show details for all workspaces."""
        for ws in self.workspace.list().keys():
            self.show_workspace(ws)
            self.logger.info("\n\n")