当前位置: 首页>>代码示例>>Python>>正文


Python database.DatabaseInterface类代码示例

本文整理汇总了Python中database.database.DatabaseInterface的典型用法代码示例。如果您正苦于以下问题:Python DatabaseInterface类的具体用法?Python DatabaseInterface怎么用?Python DatabaseInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DatabaseInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _initialize_system

def _initialize_system():
    # Authentication
    AuthenticationInterface.remove_all_authentication_methods()
    AuthenticationInterface.add_authentication_method(AuthenticationMethodBasic())

    # Database
    DatabaseInterface.load_database_plugin(DatabaseSqlite("database.db"))
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:7,代码来源:ut_user_management.py

示例2: read_tracker_by_id

    def read_tracker_by_id(tracker_id: int, max_revision_id=None) -> Optional[dict]:
        """
        Reads a tracker (active or inactive) that matches the specified tracker ID

        :param tracker_id:      ID of the tracker
        :param max_revision_id: Maximum revision ID for the search ("None" for latest revision)

        :return:    Tracker information object

        Returned dictionary contains items:

        - id
        - project_id
        - short_name
        - full_name
        - description
        - active
        - revision_id
        """
        connection = DatabaseInterface.create_connection()
        
        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)
        
        # Read a tracker that matches the specified tracker ID
        tracker = None
        
        if max_revision_id is not None:
            tracker = TrackerManagementInterface.__read_tracker_by_id(connection,
                                                                      tracker_id,
                                                                      max_revision_id)
        
        return tracker
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:34,代码来源:tracker_management.py

示例3: read_all_project_ids

    def read_all_project_ids(project_selection=ProjectSelection.Active,
                             max_revision_id=None) -> List[int]:
        """
        Reads all project IDs from the database

        :param project_selection:   Search for active, inactive or all project
        :param max_revision_id:     Maximum revision ID for the search ("None" for latest revision)

        :return:    List of project IDs
        """
        connection = DatabaseInterface.create_connection()

        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)

        # Reads all project IDs from the database
        projects = None

        if max_revision_id is not None:
            projects = DatabaseInterface.tables().project_information.read_all_project_ids(
                connection,
                project_selection,
                max_revision_id)

        return projects
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:26,代码来源:project_management.py

示例4: deactivate_project

    def deactivate_project(requested_by_user: int, project_id: int) -> bool:
        """
        Deactivates an active project

        :param requested_by_user:   ID of the user that requested modification of the user
        :param project_id: ID of the project that should be deactivated

        :return:    Success or failure
        """
        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Start a new revision
            revision_id = None

            if success:
                revision_id = DatabaseInterface.tables().revision.insert_row(
                    connection,
                    datetime.datetime.utcnow(),
                    requested_by_user)

                if revision_id is None:
                    success = False

            # Read project
            project = None

            if success:
                project = ProjectManagementInterface.__read_project_by_id(connection,
                                                                          project_id,
                                                                          revision_id)

                if project is None:
                    success = False
                elif not project["active"]:
                    # Error, project is already inactive
                    success = False

            # Deactivate project
            if success:
                success = DatabaseInterface.tables().project_information.insert_row(
                    connection,
                    project_id,
                    project["short_name"],
                    project["full_name"],
                    project["description"],
                    False,
                    revision_id)

            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise

        return success
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:60,代码来源:project_management.py

示例5: read_all_tracker_field_ids

    def read_all_tracker_field_ids(tracker_id: int,
                                   tracker_field_selection=TrackerFieldSelection.Active,
                                   max_revision_id=None) -> List[int]:
        """
        Reads all tracker field IDs from the database

        :param tracker_id:              ID of the tracker
        :param tracker_field_selection: Search for active, inactive or all tracker
        :param max_revision_id:         Maximum revision ID for the search ("None" for latest
                                        revision)

        :return:    List of tracker field IDs
        """
        connection = DatabaseInterface.create_connection()
        
        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)
        
        # Reads all tracker field IDs from the database
        tracker_fields = None
        
        if max_revision_id is not None:
            tracker_fields = \
                DatabaseInterface.tables().tracker_field_information.read_all_tracker_field_ids(
                    connection,
                    tracker_id,
                    tracker_field_selection,
                    max_revision_id)
        
        return tracker_fields
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:31,代码来源:tracker_field_management.py

示例6: activate_tracker

    def activate_tracker(requested_by_user: int, tracker_id: int) -> bool:
        """
        Activates an inactive tracker

        :param requested_by_user:   ID of the user that requested modification of the user
        :param tracker_id:          ID of the tracker that should be activated

        :return:    Success or failure
        """
        connection = DatabaseInterface.create_connection()
        
        try:
            success = connection.begin_transaction()
            
            # Start a new revision
            revision_id = None
            
            if success:
                revision_id = DatabaseInterface.tables().revision.insert_row(
                    connection,
                    datetime.datetime.utcnow(),
                    requested_by_user)
                
                if revision_id is None:
                    success = False
            
            # Read tracker
            tracker = None
            
            if success:
                tracker = TrackerManagementInterface.__read_tracker_by_id(connection,
                                                                          tracker_id,
                                                                          revision_id)
                
                if tracker is None:
                    success = False
                elif tracker["active"]:
                    # Error, tracker is already active
                    success = False
            
            # Activate tracker
            if success:
                success = DatabaseInterface.tables().tracker_information.insert_row(
                    connection,
                    tracker_id,
                    tracker["short_name"],
                    tracker["full_name"],
                    tracker["description"],
                    True,
                    revision_id)
            
            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise
        
        return success
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:60,代码来源:tracker_management.py

示例7: read_project_by_id

    def read_project_by_id(project_id: int, max_revision_id=None) -> Optional[dict]:
        """
        Reads a project (active or inactive) that matches the specified project ID

        :param project_id:      ID of the project
        :param max_revision_id: Maximum revision ID for the search ("None" for latest revision)

        :return:    Project information object

        Returned dictionary contains items:

        - id
        - short_name
        - full_name
        - description
        - active
        - revision_id
        """
        connection = DatabaseInterface.create_connection()

        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)

        # Read a project that matches the specified project ID
        project = None

        if max_revision_id is not None:
            project = ProjectManagementInterface.__read_project_by_id(connection,
                                                                      project_id,
                                                                      max_revision_id)

        return project
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:33,代码来源:project_management.py

示例8: update_user_information

    def update_user_information(user_to_modify: int,
                                user_name: str,
                                display_name: str,
                                email: str,
                                active: bool) -> bool:
        """
        Updates user's information

        :param user_to_modify:  ID of the user that should be modified
        :param user_name:       User's new user name
        :param display_name:    User's new display name
        :param email:           User's new email address
        :param active:          User's new state (active or inactive)

        :return:    Success or failure
        """
        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Check if there is already an existing user with the same user name
            if success:
                user = UserManagementInterface.__read_user_by_user_name(connection, user_name)

                if user is not None:
                    if user["id"] != user_to_modify:
                        success = False

            # Check if there is already an existing user with the same display name
            if success:
                user = UserManagementInterface.__read_user_by_display_name(connection,
                                                                           display_name)

                if user is not None:
                    if user["id"] != user_to_modify:
                        success = False

            # Update user's information
            if success:
                success = DatabaseInterface.tables().user.update_row(connection,
                                                                     user_to_modify,
                                                                     user_name,
                                                                     display_name,
                                                                     email,
                                                                     active)

            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise

        return success
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:56,代码来源:user_management.py

示例9: read_all_user_ids

    def read_all_user_ids(user_selection=UserSelection.Active) -> List[int]:
        """
        Reads all user IDs from the database

        :param user_selection:  Search for active, inactive or all users

        :return:    List of user IDs
        """
        connection = DatabaseInterface.create_connection()
        return DatabaseInterface.tables().user.read_all_ids(connection, user_selection)
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:10,代码来源:user_management.py

示例10: create_tracker

    def create_tracker(requested_by_user: int,
                       project_id: int,
                       short_name: str,
                       full_name: str,
                       description: str) -> Optional[int]:
        """
        Creates a new tracker

        :param requested_by_user:   ID of the user that requested creation of the new tracker
        :param project_id:          ID of the project
        :param short_name:          Tracker's short name
        :param full_name:           Tracker's full name
        :param description:         Tracker's description

        :return:    Tracker ID of the new tracker
        """
        tracker_id = None
        connection = DatabaseInterface.create_connection()
        
        try:
            success = connection.begin_transaction()
            
            # Start a new revision
            revision_id = None
            
            if success:
                revision_id = DatabaseInterface.tables().revision.insert_row(
                    connection,
                    datetime.datetime.utcnow(),
                    requested_by_user)
                
                if revision_id is None:
                    success = False
            
            # Create the tracker
            if success:
                tracker_id = TrackerManagementInterface.__create_tracker(connection,
                                                                         project_id,
                                                                         short_name,
                                                                         full_name,
                                                                         description,
                                                                         revision_id)
                
                if tracker_id is None:
                    success = False
            
            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise
        
        return tracker_id
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:55,代码来源:tracker_management.py

示例11: __create_tracker

    def __create_tracker(connection: Connection,
                         project_id: int,
                         short_name: str,
                         full_name: str,
                         description: str,
                         revision_id: int) -> Optional[int]:
        """
        Creates a new tracker

        :param connection:  Database connection
        :param project_id:  ID of the project
        :param short_name:  Tracker's short name
        :param full_name:   Tracker's full name
        :param description: Tracker's description
        :param revision_id: Revision ID

        :return:    Tracker ID of the newly created tracker
        """
        # Check if a tracker with the same short name already exists
        tracker = TrackerManagementInterface.__read_tracker_by_short_name(connection,
                                                                          short_name,
                                                                          revision_id)
        
        if tracker is not None:
            return None
        
        # Check if a tracker with the same full name already exists
        tracker = TrackerManagementInterface.__read_tracker_by_full_name(connection,
                                                                         full_name,
                                                                         revision_id)
        
        if tracker is not None:
            return None
        
        # Create the tracker in the new revision
        tracker_id = DatabaseInterface.tables().tracker.insert_row(connection, project_id)
        
        if tracker_id is None:
            return None
        
        # Add tracker information to the tracker
        tracker_information_id = DatabaseInterface.tables().tracker_information.insert_row(
            connection,
            tracker_id,
            short_name,
            full_name,
            description,
            True,
            revision_id)
        
        if tracker_information_id is None:
            return None
        
        return tracker_id
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:54,代码来源:tracker_management.py

示例12: setUp

    def setUp(self):
        # Authentication
        AuthenticationInterface.remove_all_authentication_methods()
        AuthenticationInterface.add_authentication_method(AuthenticationMethodBasic())

        # Database
        DatabaseInterface.load_database_plugin(DatabaseSqlite("database.db"))
        DatabaseInterface.create_new_database()

        # Data members
        self.__admin_user_id = 1
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:11,代码来源:ut_tracker_field_management.py

示例13: __create_project

    def __create_project(connection: Connection,
                         short_name: str,
                         full_name: str,
                         description: str,
                         revision_id: int) -> Optional[int]:
        """
        Creates a new project

        :param connection:  Database connection
        :param short_name:  Project's short name
        :param full_name:   Project's full name
        :param description: Project's description
        :param revision_id: Revision ID

        :return:    Project ID of the newly created project
        """
        # Check if a project with the same short name already exists
        project = ProjectManagementInterface.__read_project_by_short_name(connection,
                                                                          short_name,
                                                                          revision_id)

        if project is not None:
            return None

        # Check if a project with the same full name already exists
        project = ProjectManagementInterface.__read_project_by_full_name(connection,
                                                                         full_name,
                                                                         revision_id)

        if project is not None:
            return None

        # Create the project in the new revision
        project_id = DatabaseInterface.tables().project.insert_row(connection)

        if project_id is None:
            return None

        # Add project information to the project
        project_information_id = DatabaseInterface.tables().project_information.insert_row(
            connection,
            project_id,
            short_name,
            full_name,
            description,
            True,
            revision_id)

        if project_information_id is None:
            return None

        return project_id
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:52,代码来源:project_management.py

示例14: read_user_by_id

    def read_user_by_id(connection: Connection, user_id: int) -> Optional[dict]:
        """
        Reads a user (active or inactive) that matches the specified user ID

        :param connection:  Database connection
        :param user_id:     ID of the user

        :return:    User information object

        Returned dictionary contains items:

        - id
        - user_name
        - display_name
        - email
        - active
        """
        # Read the users that match the search attribute
        users = DatabaseInterface.tables().user.read_users_by_attribute(connection,
                                                                        "id",
                                                                        user_id,
                                                                        UserSelection.All)

        # Return a user only if exactly one was found
        user = None

        if users is not None:
            if len(users) == 1:
                user = users[0]

        return user
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:31,代码来源:user_management.py

示例15: __read_user_by_display_name

    def __read_user_by_display_name(connection: Connection, display_name: str) -> Optional[dict]:
        """
        Reads an active user that matches the specified display name

        :param display_name:    User's display name

        :return:    User information object

        Returned dictionary contains items:

        - id
        - user_name
        - display_name
        - email
        - active
        """
        # Read the users that match the search attribute
        users = DatabaseInterface.tables().user.read_users_by_attribute(connection,
                                                                        "display_name",
                                                                        display_name,
                                                                        UserSelection.Active)

        # Return a user only if exactly one was found
        user = None

        if users is not None:
            if len(users) == 1:
                user = users[0]

        return user
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:30,代码来源:user_management.py


注:本文中的database.database.DatabaseInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。