예제 #1
0
    def createProject(self,
                      name,
                      description="",
                      tags=(),
                      visibility='private',
                      localRoot='',
                      namespace=''):
        """Returns a PavloviaProject object (derived from a gitlab.project)

        Parameters
        ----------
        name
        description
        tags
        visibility
        local

        Returns
        -------
        a PavloviaProject object

        """
        if not self.user:
            raise exceptions.NoUserError(
                "Tried to create project with no user logged in")
        # NB gitlab also supports "internal" (public to registered users)
        if type(visibility) == bool and visibility:
            visibility = 'public'
        elif type(visibility) == bool and not visibility:
            visibility = 'private'

        projDict = {}
        projDict['name'] = name
        projDict['description'] = description
        projDict['issues_enabled'] = True
        projDict['visibility'] = visibility
        projDict['wiki_enabled'] = True
        if namespace and namespace != self.username:
            namespaceRaw = self.getNamespace(namespace)
            if namespaceRaw:
                projDict['namespace_id'] = namespaceRaw.id
            else:
                raise ValueError("PavloviaSession.createProject was given a "
                                 "namespace that couldn't be found on gitlab.")
        # TODO: add avatar option?
        # TODO: add namespace option?
        try:
            gitlabProj = self.gitlab.projects.create(projDict)
        except gitlab.exceptions.GitlabCreateError as e:
            if 'has already been taken' in str(e.error_message):
                gitlabProj = "{}/{}".format(namespace, name)
            else:
                raise e
        pavProject = PavloviaProject(gitlabProj, localRoot=localRoot)
        return pavProject
예제 #2
0
    def createProject(self,
                      name,
                      description="",
                      tags=(),
                      visibility='private',
                      localRoot='',
                      namespace=''):
        """Returns a PavloviaProject object (derived from a gitlab.project)

        Parameters
        ----------
        name
        description
        tags
        visibility
        local

        Returns
        -------
        a PavloviaProject object

        """
        if not self.user:
            raise exceptions.NoUserError(
                "Tried to create project with no user logged in")
        # NB gitlab also supports "internal" (public to registered users)
        if type(visibility) == bool and visibility:
            visibility = 'public'
        elif type(visibility) == bool and not visibility:
            visibility = 'private'

        projDict = {}
        projDict['name'] = name
        projDict['description'] = description
        projDict['issues_enabled'] = True
        projDict['visibility'] = visibility
        projDict['wiki_enabled'] = True
        if namespace and namespace != self.username:
            namespaceRaw = self.getNamespace(namespace)
            if namespaceRaw:
                projDict['namespace_id'] = namespaceRaw.id
            else:
                dlg = wx.MessageDialog(
                    None,
                    message=_translate(
                        f"PavloviaSession.createProject was given a namespace ({namespace}) that couldn't be found "
                        f"on gitlab."),
                    style=wx.ICON_WARNING)
                dlg.ShowModal()
                return
        # Create project on GitLab
        try:
            gitlabProj = self.gitlab.projects.create(projDict)
        except gitlab.exceptions.GitlabCreateError as e:
            if 'has already been taken' in str(e.error_message):
                dlg = wx.MessageDialog(
                    None,
                    message=_translate(
                        f"Project `{namespace}/{name}` already exists, please choose another name."
                    ),
                    style=wx.ICON_WARNING)
                dlg.ShowModal()
                return
            else:
                raise e

        # Create pavlovia project object
        pavProject = PavloviaProject(gitlabProj.get_id(), localRoot=localRoot)
        return pavProject