예제 #1
0
    def create(self, name=None):
        """Creates a new workspace.

        The default invnetory file (local_hosts) will be aslo created.
        """

        name = name or "workspace_" + datetime.datetime.fromtimestamp(
            time.time()).strftime(TIME_FORMAT)
        path = os.path.join(self.workspace_dir, name)
        if os.path.exists(path):
            raise exceptions.IRWorkspaceExists(workspace=name)
        if path == self.active_path:
            raise exceptions.IRWorkspaceInvalidName(workspace=name)
        os.makedirs(path)
        LOG.debug("Workspace {} created in {}".format(name, path))
        workspace = Workspace(name, path)
        return workspace
예제 #2
0
    def activate(self, name):
        """Activates the workspace.

        :param name: Name of the workspace to activate
        """

        if os.environ.get(ACTIVE_WORKSPACE_ENV_NAME):
            raise exceptions.IRException(
                message="'workspace checkout' command is disabled while "
                "{} environment variable is set.".format(
                    ACTIVE_WORKSPACE_ENV_NAME))

        if name == self.active_basename:
            raise exceptions.IRWorkspaceInvalidName(workspace=name)

        if self.has_workspace(name):
            self._create_active_path(name)
            LOG.debug("Activating workspace %s in %s", name,
                      os.path.join(self.workspace_dir, name))
        else:
            raise exceptions.IRWorkspaceMissing(workspace=name)