예제 #1
0
def get_project(user, owner, project_name, create=False, clean=False):
    """Create a project object that provides an appropriate view
    of the project for the given user. A project is identified by
    the 'owner' of the project and by the project name. If
    create is True, the project will be created if it does not
    already exist. If clean is True, the project will be deleted
    and recreated if it already exists."""

    _check_identifiers("Project names", project_name)

    if user != owner:
        if not owner.is_project_shared(project_name, user):
            raise NotAuthorized("User %s is not allowed to access project %s" % (user, project_name))

    # a request for a clean project also implies that creating it
    # is okay
    if clean:
        create = True

    location = owner.get_location() / project_name
    if location.exists():
        project = ProjectView(user, owner, project_name, location)
        if clean:
            location.rmtree()
            location.makedirs()
    else:
        if not create:
            raise FileNotFound("Project %s not found" % project_name)
        log.debug("Creating new project %s", project_name)
        location.makedirs()
        project = ProjectView(user, owner, project_name, location)
        config.c.stats.incr("projects")
    return project
예제 #2
0
def get_project(user, owner, project_name, create=False, clean=False):
    """Create a project object that provides an appropriate view
    of the project for the given user. A project is identified by
    the 'owner' of the project and by the project name. If
    create is True, the project will be created if it does not
    already exist. If clean is True, the project will be deleted
    and recreated if it already exists."""
    log.debug("get_project user="******" owner=" + owner.username + " project=" + project_name)

    _check_identifiers("Project names", project_name)

    if user != owner:
        if not owner.is_project_shared(project_name, user):
            raise NotAuthorized("User %s is not allowed to access project %s" %
                                (user, project_name))

    # a request for a clean project also implies that creating it
    # is okay
    if clean:
        create = True

    location = owner.get_location() / project_name
    if location.exists():
        project = ProjectView(user, owner, project_name, location)
        if clean:
            location.rmtree()
            location.makedirs()
    else:
        if not create:
            raise FileNotFound("Project %s not found" % project_name)
        log.debug("Creating new project %s", project_name)
        location.makedirs()
        project = ProjectView(user, owner, project_name, location)
        config.c.stats.incr("projects")
    return project
 def rename(self, new_name):
     """Renames this project to new_name, assuming there is
     not already another project with that name."""
     _check_identifiers("Project name", new_name)
     old_location = self.location
     new_location = self.location.parent / new_name
     self.metadata.rename(new_name)
     if new_location.exists():
         raise FileConflict("Cannot rename project %s to %s, because"
                            " a project with the new name already exists." %
                            (self.name, new_name))
     old_location.rename(new_location)
     self.name = new_name
     self.location = new_location
예제 #4
0
파일: filesystem.py 프로젝트: Jangts/bespin
 def rename(self, new_name):
     """Renames this project to new_name, assuming there is
     not already another project with that name."""
     _check_identifiers("Project name", new_name)
     old_location = self.location
     new_location = self.location.parent / new_name
     self.metadata.rename(new_name)
     if new_location.exists():
         raise FileConflict("Cannot rename project %s to %s, because"
             " a project with the new name already exists."
             % (self.name, new_name))
     old_location.rename(new_location)
     self.name = new_name
     self.location = new_location
예제 #5
0
    def create_user(cls, username, password, email, override_location=None):
        """Adds a new user with the given username and password.
        This raises a ConflictError is the user already
        exists."""
        _check_identifiers("Usernames", username)

        log.debug("Creating user %s", username)
        password = User.generate_password(password)
        
        user = cls(username, password, email)
        if override_location is not None:
            user.file_location = override_location
        _get_session().add(user)
        # flush to ensure that the user is unique
        try:
            _get_session().flush()
        except DBAPIError, e:
            raise ConflictError("Username %s is already in use" % username)
예제 #6
0
파일: database.py 프로젝트: iNeft/bespin
    def create_user(cls, username, password, email, override_location=None):
        """Adds a new user with the given username and password.
        This raises a ConflictError is the user already
        exists."""
        _check_identifiers("Usernames", username)

        log.debug("Creating user %s", username)
        password = User.generate_password(password)
        
        user = cls(username, password, email)
        if override_location is not None:
            user.file_location = override_location
        _get_session().add(user)
        # flush to ensure that the user is unique
        try:
            _get_session().flush()
        except DBAPIError, e:
            raise ConflictError("Username %s is already in use" % username)