Esempio n. 1
0
 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"))
Esempio n. 2
0
 def test_repository_exists_invalid_workspace(self):
     """Test workspace has not repository."""
     config_mock_data = {"workspaces": {
         "foo": {"path": "/foo", "repositories": {"repo1": "/foo/repo1"}}}}
     self.config.update(config_mock_data)
     ws = Workspace(self.config)
     self.assertFalse(ws.repository_exists("bar", "repo1"))
Esempio n. 3
0
 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"))
Esempio n. 4
0
    def test_get_workspace(self):
        """Test get workspace from name."""
        config_mock_data = {"workspaces": {
            "foo": {"path": "/foo", "repositories": {}}}}
        self.config.update(config_mock_data)

        ws = Workspace(self.config)
        self.assertEqual({
            "name": "foo",
            "path": "/foo",
            "repositories": {}}, ws.get("foo"))
Esempio n. 5
0
    def test_list(self):
        """Test list workspace."""
        config_mock_data = {"workspaces": {
            "foo": {"path": "/foo", "repositories": {}},
            "bar": {"path": "/bar", "repositories": {}}}}
        self.config.update(config_mock_data)

        ws = Workspace(self.config)
        list = ws.list()
        self.assertIn("foo", list)
        self.assertIn("bar", list)
        self.assertEqual(
            {"name": "foo",
             "path": "/foo",
             "repositories": {}}, list["foo"])
        self.assertEqual(
            {"name": "bar",
             "path": "/bar",
             "repositories": {}}, list["bar"])
Esempio n. 6
0
class Workspace(Subcommand, object):
    ws = None
    subparser = None

    def setup(self, name, config, subparser):
        self.ws = Ws(config)
        self.subparser = subparser
        super(Workspace, self).setup(name, config, subparser)

    def parse(self):
        parser = self.subparser.add_parser(
            "workspace",
            help="Workspace managment",
            description="Manage repository's workspace")
        subparser = parser.add_subparsers(
            dest="workspace_subcommand")

        add_parser = subparser.add_parser(
            "add", help="Add workspace")
        rm_parser = subparser.add_parser(
            "remove", help="Remove existing workspace")
        subparser.add_parser(
            "list", help="Show registered workspace")

        add_parser.add_argument("name", type=str, help="Workspace name")
        add_parser.add_argument("path", type=str, help="Workspace path")
        rm_parser.add_argument("name", type=str, help="Workspace name")

    def execute(self, args):
        logger = logging.getLogger(__name__)
        if args.workspace_subcommand is None:
            self.parser.print_help()
            return None

        color = Color()
        if (args.workspace_subcommand == "add"):
            ws_name = slashes2dash(args.name)
            self.ws.add(ws_name, args.path)
            logger.info(color.colored(
                "Workspace `%s` successfuly added" % ws_name, "green"))
        elif (args.workspace_subcommand == "remove"):
            ws_name = slashes2dash(args.name)
            self.ws.remove(ws_name)
            logger.info(color.colored(
                "Workspace `%s` successfuly removed" % ws_name, "green"))
        elif (args.workspace_subcommand == "list"):
            table = PrettyTable(["Name", "Path"])
            table.align["Name"] = "l"
            table.align["Path"] = "l"
            for key, ws in sorted(self.ws.list().items()):
                table.add_row([key, ws["path"]])

            logger.info(table)

    def load_workspaces_subcommands(self, subcmd):
        for key, value in self.ws.list().items():
            ws_subcmds = WorkspaceSubcommands(key, self.subparser, self.config)
            subcmd.commands[key] = ws_subcmds
Esempio n. 7
0
    def execute(self, args):
        logger = logging.getLogger(__name__)
        ws = Ws(self.config)

        if (args.action == "add"):
            repo_name = slashes2dash(args.repo_name)
            ws.add_repo(args.subcommand, repo_name, args.url, args.path)
            logger.info("Repository `%s` added to `%s` workspace." %
                        (repo_name, args.subcommand))
        elif (args.action == "remove"):
            repo_name = slashes2dash(args.repo_name)
            ws.rm_repo(args.subcommand, repo_name)
            logger.info("Repository `%s` removed from `%s` workspace." %
                        (repo_name, args.subcommand))
        elif (args.action == "sync"):
            ws.sync(args.subcommand)
            logger.info("Workspace `%s` synchronized." % args.subcommand)
Esempio n. 8
0
 def setup(self, name, config, subparser):
     self.ws = Ws(config)
     self.subparser = subparser
     self.logger = logging.getLogger(__name__)
     super(Workspace, self).setup(name, config, subparser)
Esempio n. 9
0
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")
Esempio n. 10
0
 def test_remove(self):
     """Test remove workspace."""
     self.config.update({
         "workspaces": {"foo": {"path": "/foo", "repositories": {}}}})
     ws = Workspace(self.config)
     ws.remove("foo")
Esempio n. 11
0
 def test_add(self):
     """Test add workspace."""
     self.config.update({
         "workspaces": {"foo": {"path": "/foo", "repositories": {}}}})
     ws = Workspace(self.config)
     ws.add("bar", os.path.realpath(__file__))
Esempio n. 12
0
 def test_get_workspace_none(self):
     """Test get workspace that doesn't exists."""
     ws = Workspace(self.config)
     self.assertIsNone(ws.get("foo"))
Esempio n. 13
0
 def setup(self, name, config, subparser):
     self.ws = Ws(config)
     self.subparser = subparser
     super(Workspace, self).setup(name, config, subparser)