Esempio n. 1
0
    def insert_item(self, id_, group, description='Insert item'):
        srules = self.rules_to_string([])

        qconn = core_api.get_connection(self.filename)
        cursor = qconn.cursor()
        cursor.execute(queries.rules_insert, (id_, srules, ))
        core_api.give_connection(self.filename, qconn)

        core_api.insert_history(self.filename, group, id_, 'rules_insert',
                                                    description, srules, None)
Esempio n. 2
0
    def insert_item(self, id_, group, description='Insert item'):
        srules = self.rules_to_string([])

        qconn = core_api.get_connection(self.filename)
        cursor = qconn.cursor()
        cursor.execute(queries.rules_insert, (id_, srules, ))
        core_api.give_connection(self.filename, qconn)

        core_api.insert_history(self.filename, group, id_, 'rules_insert',
                                                    description, srules, None)
Esempio n. 3
0
    def delete_item_rules(self, id_, text, group,
                                            description='Delete item rules'):
        qconn = core_api.get_connection(self.filename)
        cursor = qconn.cursor()

        cursor.execute(queries.rules_select_id, (id_, ))
        sel = cursor.fetchone()

        # The query should always return a result, so sel should never be None
        current_rules = sel['R_rules']

        cursor.execute(queries.rules_delete_id, (id_, ))

        core_api.give_connection(self.filename, qconn)

        core_api.insert_history(self.filename, group, id_, 'rules_delete',
                                            description, None, current_rules)

        delete_item_rules_event.signal(filename=self.filename, id_=id_,
                                                                    text=text)
Esempio n. 4
0
    def _update_item_rules_no_event(self, id_, rules, group,
                                            description='Update item rules'):
        if isinstance(rules, list):
            rules = self.rules_to_string(rules)

        qconn = core_api.get_connection(self.filename)
        cursor = qconn.cursor()

        cursor.execute(queries.rules_select_id, (id_, ))
        sel = cursor.fetchone()

        # The query should always return a result, so sel should never be None
        unrules = sel['R_rules']

        cursor.execute(queries.rules_update_id, (rules, id_))

        core_api.give_connection(self.filename, qconn)

        core_api.insert_history(self.filename, group, id_, 'rules_update',
                                                description, rules, unrules)
Esempio n. 5
0
    def delete_item_rules(self, id_, text, group,
                                            description='Delete item rules'):
        qconn = core_api.get_connection(self.filename)
        cursor = qconn.cursor()

        cursor.execute(queries.rules_select_id, (id_, ))
        sel = cursor.fetchone()

        # The query should always return a result, so sel should never be None
        current_rules = sel['R_rules']

        cursor.execute(queries.rules_delete_id, (id_, ))

        core_api.give_connection(self.filename, qconn)

        core_api.insert_history(self.filename, group, id_, 'rules_delete',
                                            description, None, current_rules)

        delete_item_rules_event.signal(filename=self.filename, id_=id_,
                                                                    text=text)
Esempio n. 6
0
def delete_link(filename, id_, group, description='Delete link'):
    qconn = core_api.get_connection(filename)
    cursor = qconn.cursor()

    cursor.execute(queries.links_select_id, (id_, ))
    res = cursor.fetchone()

    if res:
        target = res['L_target']

        do_delete_link(cursor, id_)

        core_api.give_connection(filename, qconn)

        core_api.insert_history(filename, group, id_, 'link_delete',
                description, None, str(target) if target is not None else None)

        delete_link_event.signal(filename=filename, id_=id_, oldtarget=target)
    else:
        core_api.give_connection(filename, qconn)
Esempio n. 7
0
    def _update_item_rules_no_event(self, id_, rules, group,
                                            description='Update item rules'):
        if isinstance(rules, list):
            rules = self.rules_to_string(rules)

        qconn = core_api.get_connection(self.filename)
        cursor = qconn.cursor()

        cursor.execute(queries.rules_select_id, (id_, ))
        sel = cursor.fetchone()

        # The query should always return a result, so sel should never be None
        unrules = sel['R_rules']

        cursor.execute(queries.rules_update_id, (rules, id_))

        core_api.give_connection(self.filename, qconn)

        core_api.insert_history(self.filename, group, id_, 'rules_update',
                                                description, rules, unrules)
Esempio n. 8
0
def delete_link(filename, id_, group, description='Delete link'):
    qconn = core_api.get_connection(filename)
    cursor = qconn.cursor()

    cursor.execute(queries.links_select_id, (id_, ))
    res = cursor.fetchone()

    if res:
        target = res['L_target']

        do_delete_link(cursor, id_)

        core_api.give_connection(filename, qconn)

        core_api.insert_history(filename, group, id_, 'link_delete',
                                description, None,
                                str(target) if target is not None else None)

        delete_link_event.signal(filename=filename, id_=id_, oldtarget=target)
    else:
        core_api.give_connection(filename, qconn)
Esempio n. 9
0
def break_links(filename, id_, group, description='Break links'):
    # Break any links that point to the item
    # Don't just delete those links, as it would leave their associated
    # items in an unexpected state for the user (back to normal,
    # undistinguished items); also this further action should be handled
    # properly by the interface somehow
    # Don't try to delete the links and their associated items, because
    # silently deleting items that were not selected would be confusing;
    # furthermore, theoretically link items are allowed (at least in the
    # back-end) to have their own children, which should be deleted too
    qconn = core_api.get_connection(filename)
    cursor = qconn.cursor()
    cursor.execute(queries.links_select_target, (id_, ))

    ids = set()
    rows = cursor.fetchall()

    if rows:
        for row in rows:
            linkid = row['L_id']
            ids.add(linkid)

            do_update_link(filename, cursor, None, linkid)

            core_api.give_connection(filename, qconn)

            core_api.insert_history(filename, group, linkid, 'link_update',
                                                description, None, str(id_))

            qconn = core_api.get_connection(filename)
            cursor = qconn.cursor()

        core_api.give_connection(filename, qconn)

        break_link_event.signal(filename=filename, ids=ids, oldtarget=id_)
    else:
        core_api.give_connection(filename, qconn)
Esempio n. 10
0
def break_links(filename, id_, group, description='Break links'):
    # Break any links that point to the item
    # Don't just delete those links, as it would leave their associated
    # items in an unexpected state for the user (back to normal,
    # undistinguished items); also this further action should be handled
    # properly by the interface somehow
    # Don't try to delete the links and their associated items, because
    # silently deleting items that were not selected would be confusing;
    # furthermore, theoretically link items are allowed (at least in the
    # back-end) to have their own children, which should be deleted too
    qconn = core_api.get_connection(filename)
    cursor = qconn.cursor()
    cursor.execute(queries.links_select_target, (id_, ))

    ids = set()
    rows = cursor.fetchall()

    if rows:
        for row in rows:
            linkid = row['L_id']
            ids.add(linkid)

            do_update_link(filename, cursor, None, linkid)

            core_api.give_connection(filename, qconn)

            core_api.insert_history(filename, group, linkid, 'link_update',
                                    description, None, str(id_))

            qconn = core_api.get_connection(filename)
            cursor = qconn.cursor()

        core_api.give_connection(filename, qconn)

        break_link_event.signal(filename=filename, ids=ids, oldtarget=id_)
    else:
        core_api.give_connection(filename, qconn)
Esempio n. 11
0
def upsert_link(filename, id_, target, group, description='Insert link'):
    # target could be None (creating a broken link) or could be a no-longer
    # existing item
    if core_api.is_item(filename, target):
        # Forbid circular links (including links to self), as it could generate
        # unexpected infinite recursions (e.g. with synchronize_links_text)
        if id_ in find_links_chain(filename, target):
            raise exceptions.CircularLinksError()
        else:
            # Sync text
            tgttext = core_api.get_item_text(filename, target)
            core_api.update_item_text(filename, id_, tgttext, group=group,
                                                description=description)

            # Drop any rules
            if organism_api and filename in \
                                organism_api.get_supported_open_databases():
                organism_api.update_item_rules(filename, id_, [], group=group,
                                                    description=description)
    else:
        # Force target = None if the given target no longer exists
        target = None

        # Drop any rules
        if organism_api and filename in \
                                organism_api.get_supported_open_databases():
            organism_api.update_item_rules(filename, id_, [], group=group,
                                                    description=description)

    # Note that exceptions.CircularLinksError could be raised before getting
    # here
    qconn = core_api.get_connection(filename)
    cursor = qconn.cursor()

    cursor.execute(queries.links_select_id, (id_, ))
    res = cursor.fetchone()

    # Do not allow creating more than one link per item
    if res:
        oldtarget = res['L_target']

        do_update_link(filename, cursor, target, id_)

        core_api.give_connection(filename, qconn)

        core_api.insert_history(filename, group, id_, 'link_update',
                    description, str(target) if target is not None else None,
                    oldtarget if str(oldtarget) is not None else None)
    else:
        oldtarget = False

        # 'target' can be None, thus allowing the creation of a broken link
        do_insert_link(filename, cursor, id_, target)

        core_api.give_connection(filename, qconn)

        core_api.insert_history(filename, group, id_, 'link_insert',
                    description, str(target) if target is not None else None,
                    None)

    upsert_link_event.signal(filename=filename, id_=id_, target=target,
                                                        oldtarget=oldtarget)
Esempio n. 12
0
def upsert_link(filename, id_, target, group, description='Insert link'):
    # target could be None (creating a broken link) or could be a no-longer
    # existing item
    if core_api.is_item(filename, target):
        # Forbid circular links (including links to self), as it could generate
        # unexpected infinite recursions (e.g. with synchronize_links_text)
        if id_ in find_links_chain(filename, target):
            raise exceptions.CircularLinksError()
        else:
            # Sync text
            tgttext = core_api.get_item_text(filename, target)
            core_api.update_item_text(filename,
                                      id_,
                                      tgttext,
                                      group=group,
                                      description=description)

            # Drop any rules
            if organism_api and filename in \
                                organism_api.get_supported_open_databases():
                organism_api.update_item_rules(filename,
                                               id_, [],
                                               group=group,
                                               description=description)
    else:
        # Force target = None if the given target no longer exists
        target = None

        # Drop any rules
        if organism_api and filename in \
                                organism_api.get_supported_open_databases():
            organism_api.update_item_rules(filename,
                                           id_, [],
                                           group=group,
                                           description=description)

    # Note that exceptions.CircularLinksError could be raised before getting
    # here
    qconn = core_api.get_connection(filename)
    cursor = qconn.cursor()

    cursor.execute(queries.links_select_id, (id_, ))
    res = cursor.fetchone()

    # Do not allow creating more than one link per item
    if res:
        oldtarget = res['L_target']

        do_update_link(filename, cursor, target, id_)

        core_api.give_connection(filename, qconn)

        core_api.insert_history(
            filename, group, id_, 'link_update', description,
            str(target) if target is not None else None,
            oldtarget if str(oldtarget) is not None else None)
    else:
        oldtarget = False

        # 'target' can be None, thus allowing the creation of a broken link
        do_insert_link(filename, cursor, id_, target)

        core_api.give_connection(filename, qconn)

        core_api.insert_history(filename, group, id_, 'link_insert',
                                description,
                                str(target) if target is not None else None,
                                None)

    upsert_link_event.signal(filename=filename,
                             id_=id_,
                             target=target,
                             oldtarget=oldtarget)