Example #1
0
 def update_tasks_states(self):
     """Updates states for this tasks and all dependencies.
     If a task state is set, other depending tasks may be ready to start.
     This method update tose and also the database entries.
     """
     with session_scope() as session:
         self._update_self(session=session)
         self.update_depender(session=session)
Example #2
0
 def state(self):
     """The current state of the task.
     Returns:
         str: current state
     """
     with session_scope() as session:
         task_data = session.query(TaskData).filter(
             TaskData.id == self.id).first()
         return task_data.state
Example #3
0
def get_all_users():
    """ Returns all users in the database.

    Returns:
        list(User): all users in the database

    """
    with session_scope() as session:
        users = [User(data) for data in session.query(UserData).all()]
        return users
Example #4
0
    def layouts(self):
        """Get the layouts associated with this project.

        Returns:
            list(Layouts): layout instances for all layouts in the current project.

        """
        with session_scope() as session:
            layouts = session.query(LayoutData).filter(
                LayoutData.project_id == self.id)
            return [Layout(layout_data) for layout_data in layouts]
Example #5
0
    def shots(self):
        """Get the shots associated with this project.

        Returns:
            list(Shot): Shot instances for all shots in the current project.

        """
        with session_scope() as session:
            shots = session.query(ShotData).filter(
                ShotData.project_id == self.id)
            return [Shot(shot_data) for shot_data in shots]
Example #6
0
    def assets(self):
        """Gets the assets associated with the current project.

        Returns:
            list(Asset): A list of Asset instances for the current project.

        """
        with session_scope() as session:
            assets = session.query(AssetData).filter(
                AssetData.project_id == self.id)
            return [Asset(asset_data) for asset_data in assets]
Example #7
0
    def tasks(self):
        """Get all tasks for the user.

        Returns:
            list(Task): all tasks which are associated with the user.

        """
        with session_scope() as session:
            tasksData = session.query(TaskData).filter(
                TaskData.user_id == self.id).all()
            return [Task(taskData) for taskData in tasksData]
Example #8
0
    def comments(self):
        """All comments associated with this tasks. Normaly entered during state changes.

        Returns:
            list(Comment): All comments for this task.

        """
        with session_scope() as session:
            comments = session.query(CommentData).filter(
                CommentData.task_id == self.id).all()
            return [Comment(c) for c in comments]
Example #9
0
    def child_tasks(self):
        """All child / subtasks which belong to this task.

        Returns:
             list(Task): all child tasks

        """
        with session_scope() as session:
            children_task_data = session.query(TaskData).filter(
                TaskData.parent_task_id == self.id).all()
            return [Task(child_task) for child_task in children_task_data]
Example #10
0
    def tasks(self):
        """All tasks for this item.
        Queries the database for all tasks associated with this item and returns them.

        Returns:
            list(Task): all tasks for this item.

        """
        with session_scope() as session:
            item = session.query(
                self.model_type).filter(self.model_type.id == self.id).first()
            return [Task(task) for task in item.tasks if not task.parent_task]
Example #11
0
    def add_comment(self, text):
        """Associates a new comment with this task.

        Args:
            text (str): comment for this task

        """
        time = datetime.datetime.now()
        with session_scope() as session:
            task_data = session.query(TaskData).filter(
                TaskData.id == self.id).first()
            task_data.comments.append(CommentData(text=text, datetime=time))
Example #12
0
 def parent(self):
     with session_scope() as session:
         task = session.query(TaskData).filter(
             TaskData.id == self.id).first()
         parent = task.parent
         if not parent:
             log.debug('No parent for {task}'.format(task=task.name))
             return None
         if isinstance(parent, AssetData):
             return Asset(parent)
         if isinstance(parent, ShotData):
             return Shot(parent)
Example #13
0
def get_all_projects():
    """All projects available in the database.

    Returns:
        list(Project): all projects available in the database

    """
    with session_scope() as session:
        project_models = session.query(ProjectData).all()
        return [
            Project(model=project_model) for project_model in project_models
        ]
Example #14
0
def get_project_by_name(name):
    """Returns a project instance for the given name if it exists in the database.

    Args:
        name (str): project to find and return

    Returns:
        Project: instance for the given name if exists. Otherwise None
    """
    with session_scope() as session:
        project_model = session.query(ProjectData).filter_by(name=name).first()
        return Project(model=project_model)
Example #15
0
 def _are_dependencies_fulfilled(self):
     """Checks if all dependencies (other tasks) for this task are done."""
     with session_scope() as session:
         task = session.query(TaskData).filter(
             TaskData.id == self.id).first()
         dependencies = task.dependencies
         if any(dependency.state != State.done
                for dependency in dependencies):
             log.warning(
                 'State set not allowed for {task}. Dependend tasks are not done.'
                 .format(task=self.name))
             return False
         return True
Example #16
0
    def user(self):
        """ The user assigned to this task.

        Returns:
            User: which is assigned to this task

        """
        with session_scope() as session:
            task = session.query(TaskData).filter(
                TaskData.id == self.id).first()
            if task.user:
                return User(task.user)
            return None
Example #17
0
def new_project(name):
    """Creates a new project with the given name.

    Create a project to hold tasks, assets and shots.
    Args:
        name (str): name of the new project
    """
    project = ProjectData(name=name)
    with session_scope() as session:
        exists = session.query(ProjectData).filter_by(name=name).first()
        if exists:
            log.warning('Project already exists. Skipping creation.')
            return None
        log.info('Creating new Project {name}'.format(name=name))
        session.add(project)
Example #18
0
    def state(self, state):
        """Change the state of this task.

        Args:
            state (str): name of the state to set this tasks state to.

        """
        with session_scope() as session:
            task_data = session.query(TaskData).filter(
                TaskData.id == self.id).first()
            log.info('{task} set to {state}'.format(task=self.name,
                                                    state=state))
            task_data.state = state
            self._update_self(session=session)
            self.update_depender(session=session)
Example #19
0
def new_user(name):
    """Creates a new user in the databse.
    Creates a new user with the given name in the database. If a user with this name exists already creation is skipped.
    Args:
        name (str): name of the new user.

    """
    user = UserData(name=name)
    with session_scope() as session:
        exists = session.query(UserData).filter_by(name=name).first()
        if exists:
            log.warning('User already exists. Skipping creation.')
            return
        log.info('Created new User {name}'.format(name=name))
        session.add(user)
Example #20
0
    def new_asset(self, name, template):
        """ Creates a new asset with the given name in the project.
        The new shot will use the provided template to generate tasks and dependenciesfor itself.

        Args:
            name (str): name of the new asset. Aborts if an asset with this name already exists.
            template (dict): A configuration file to generate tasks and dependencies for the new asset from.
        """
        log.info('New Asset {name}'.format(name=name))
        asset = AssetData(name=name,
                          tasks=tasks_from_template(template=template))
        with session_scope() as session:
            project = session.query(ProjectData).filter(
                ProjectData.id == self.id).first()
            project.assets.append(asset)
Example #21
0
    def delete(self):
        """Removes this asset from the database and deassociates all asset tasks from the assigned user.

        Returns:
            bool: True if deleteoin was successfull, False otherwise.

        """
        tasks = self.tasks
        for task in tasks:
            task.user = None

        with session_scope() as session:
            item = session.query(
                self.model_type).filter(self.model_type.id == self.id)
            item.delete(synchronize_session=False)
            return True
Example #22
0
def get_user_by_name(name):
    """Find a user in the database by it's name.
    Queries the database for the username. If it exists it's returned otherwise a ValueError is raised.
    Args:
        name (str): username to search for

    Returns:
        User: the user with the given name.

    """
    with session_scope() as session:
        user = session.query(UserData).filter_by(name=name).first()
        if not user:
            raise ValueError(
                'Username {user} not in database'.format(user=name))
        return User(model=user)
Example #23
0
    def user(self, user):
        """Assigns an user to this task.

        Args:
            user(User): the new user which should be assigned to this task.

        """
        with session_scope() as session:
            task_data = session.query(TaskData).filter(
                TaskData.id == self.id).first()
            user_data = None
            if user:
                user_data = session.query(UserData).filter(
                    UserData.id == user.id).first()
                log.debug('{user} assigned to {task}'.format(
                    user=user_data.name, task=task_data.name))
            task_data.user = user_data
Example #24
0
def get_all_tasks(user=None, state=None):
    """All tasks in the database. Optional for the given user and/or state.

    Args:
        user (User): tasks must be assigned to this user to be returned.
        state (str): tasks must have this state to be returned.

    Returns:
        list(Task): all task matching the criteria.

    """
    with session_scope() as session:
        tasks_models = session.query(TaskData)
        if user:
            tasks_models = tasks_models.filter(UserData.id == user.id)
        if state:
            tasks_models = tasks_models.filter_by(state=state)
        tasks_models = tasks_models.all()
        return [Task(model=task_model) for task_model in tasks_models]
Example #25
0
 def get_assets(self):
     with session_scope() as session:
         assets = session.query(AssetData).filter(
             AssetData.layouts_id == self.id)