Exemplo n.º 1
0
 def _handle_copy_items(self, kwargs):
     # Do not check if kwargs['filename'] is in self.databases, always clear
     # the table as the other functions rely on the table to be clear
     mem = core_api.get_memory_connection()
     cur = mem.cursor()
     cur.execute(queries.copyrules_delete)
     core_api.give_memory_connection(mem)
Exemplo n.º 2
0
def handle_copy_items(kwargs):
    # Do not check if kwargs['filename'] is in links.cdbs, always clear the
    # table as the other functions rely on the table to be clear
    mem = core_api.get_memory_connection()
    cur = mem.cursor()
    cur.execute(queries.copylinks_delete)
    core_api.give_memory_connection(mem)
Exemplo n.º 3
0
 def _handle_copy_items(self, kwargs):
     # Do not check if kwargs['filename'] is in self.databases, always clear
     # the table as the other functions rely on the table to be clear
     mem = core_api.get_memory_connection()
     cur = mem.cursor()
     cur.execute(queries.copyrules_delete)
     core_api.give_memory_connection(mem)
Exemplo n.º 4
0
def handle_copy_items(kwargs):
    # Do not check if kwargs['filename'] is in links.cdbs, always clear the
    # table as the other functions rely on the table to be clear
    mem = core_api.get_memory_connection()
    cur = mem.cursor()
    cur.execute(queries.copylinks_delete)
    core_api.give_memory_connection(mem)
Exemplo n.º 5
0
    def _handle_safe_paste_check(self, kwargs):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyalarms_select)
        core_api.give_memory_connection(mem)

        # Warn if CopyAlarms table has alarms but filename doesn't support them
        if curm.fetchone() and kwargs["filename"] not in self.databases:
            raise kwargs["exception"]()
Exemplo n.º 6
0
def can_paste_safely(filename, exception):
    mem = core_api.get_memory_connection()
    curm = mem.cursor()
    curm.execute(queries.copylinks_select)
    core_api.give_memory_connection(mem)

    # Warn if CopyLinks table has links but filename doesn't support them
    if curm.fetchone() and filename not in cdbs:
        raise exception()
Exemplo n.º 7
0
    def paste_alarms(self, id_, oldid):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyalarms_select_id, (oldid, ))
        core_api.give_memory_connection(mem)

        for occ in curm:
            self._insert_alarm(id_, occ['CA_start'], occ['CA_end'],
                                            occ['CA_alarm'], occ['CA_snooze'])
Exemplo n.º 8
0
def can_paste_safely(filename, exception):
    mem = core_api.get_memory_connection()
    curm = mem.cursor()
    curm.execute(queries.copylinks_select)
    core_api.give_memory_connection(mem)

    # Warn if CopyLinks table has links but filename doesn't support them
    if curm.fetchone() and filename not in cdbs:
        raise exception()
Exemplo n.º 9
0
def copy_link(filename, id_):
    if filename in cdbs:
        target = find_link_target(filename, id_)

        if target is not False:
            mem = core_api.get_memory_connection()
            curm = mem.cursor()
            curm.execute(queries.copylinks_insert, (id_, target))
            core_api.give_memory_connection(mem)
Exemplo n.º 10
0
    def _handle_safe_paste_check(self, kwargs):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyalarms_select)
        core_api.give_memory_connection(mem)

        # Warn if CopyAlarms table has alarms but filename doesn't support them
        if curm.fetchone() and kwargs['filename'] not in self.databases:
            raise kwargs['exception']()
Exemplo n.º 11
0
def copy_link(filename, id_):
    if filename in cdbs:
        target = find_link_target(filename, id_)

        if target is not False:
            mem = core_api.get_memory_connection()
            curm = mem.cursor()
            curm.execute(queries.copylinks_insert, (id_, target))
            core_api.give_memory_connection(mem)
Exemplo n.º 12
0
    def paste_alarms(self, id_, oldid):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyalarms_select_id, (oldid, ))
        core_api.give_memory_connection(mem)

        for occ in curm:
            self._insert_alarm(id_, occ['CA_start'], occ['CA_end'],
                               occ['CA_alarm'], occ['CA_snooze'])
Exemplo n.º 13
0
    def _handle_safe_paste_check(self, kwargs):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyrules_select,
                                        (items.Database.rules_to_string([]), ))
        core_api.give_memory_connection(mem)

        # Warn if CopyRules table has rules but filename doesn't support them
        if curm.fetchone() and kwargs['filename'] not in self.databases:
            raise kwargs['exception']()
Exemplo n.º 14
0
def has_copied_items(filename):
    qmemory = core_api.get_memory_connection()
    cursor = qmemory.cursor()
    cursor.execute(queries.copy_select_check)
    core_api.give_memory_connection(qmemory)

    if cursor.fetchone():
        return True
    else:
        return False
Exemplo n.º 15
0
def has_copied_items(filename):
    qmemory = core_api.get_memory_connection()
    cursor = qmemory.cursor()
    cursor.execute(queries.copy_select_check)
    core_api.give_memory_connection(qmemory)

    if cursor.fetchone():
        return True
    else:
        return False
Exemplo n.º 16
0
    def _handle_safe_paste_check(self, kwargs):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyrules_select,
                                        (items.Database.rules_to_string([]), ))
        core_api.give_memory_connection(mem)

        # Warn if CopyRules table has rules but filename doesn't support them
        if curm.fetchone() and kwargs['filename'] not in self.databases:
            raise kwargs['exception']()
Exemplo n.º 17
0
    def paste_item_rules(self, id_, oldid, group, description):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyrules_select_id, (oldid, ))
        core_api.give_memory_connection(mem)

        # Do not signal update_item_rules_conditional_event because it's
        # handled by organism_timer.timer.NextOccurrencesEngine, and it would
        # slow down the pasting of items a lot; NextOccurrencesEngine is bound
        # anyway to copypaste_api.bind_to_items_pasted
        self._update_item_rules_no_event(id_, curm.fetchone()['CR_rules'],
                                                            group, description)
Exemplo n.º 18
0
    def paste_item_rules(self, id_, oldid, group, description):
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyrules_select_id, (oldid, ))
        core_api.give_memory_connection(mem)

        # Do not signal update_item_rules_conditional_event because it's
        # handled by organism_timer.timer.NextOccurrencesEngine, and it would
        # slow down the pasting of items a lot; NextOccurrencesEngine is bound
        # anyway to copypaste_api.bind_to_items_pasted
        self._update_item_rules_no_event(id_, curm.fetchone()['CR_rules'],
                                                            group, description)
Exemplo n.º 19
0
def paste_items(filename, baseid, mode, group, description='Paste items'):
    qmemory = core_api.get_memory_connection()
    cursor = qmemory.cursor()
    cursor.execute(queries.copy_select_parent_roots)
    old_roots = cursor.fetchall()
    core_api.give_memory_connection(qmemory)

    old_to_new_ids = {}

    def recurse(baseid, previd):
        cursor.execute(queries.copy_select_parent, (baseid, previd))
        child = cursor.fetchone()

        if child:
            id_ = child['C_id']

            old_to_new_ids[id_] = core_api.append_item(
                                filename, old_to_new_ids[baseid], group=group,
                                text=child['C_text'], description=description)

            item_paste_event.signal(filename=filename, id_=old_to_new_ids[id_],
                                    oldid=id_, group=group,
                                    description=description)

            recurse(id_, 0)
            recurse(baseid, id_)

    if mode == 'siblings':
        old_roots.reverse()

    for root in old_roots:
        if mode == 'children':
            old_to_new_ids[root['C_id']] = core_api.append_item(
                                filename, baseid, group=group,
                                text=root['C_text'], description=description)
        elif mode == 'siblings':
            old_to_new_ids[root['C_id']] = core_api.insert_item_after(
                                filename, baseid, group=group,
                                text=root['C_text'], description=description)

        item_paste_event.signal(filename=filename,
                                            id_=old_to_new_ids[root['C_id']],
                                            oldid=root['C_id'], group=group,
                                            description=description)

        recurse(root['C_id'], 0)

    new_ids = old_to_new_ids.values()
    new_roots = [old_to_new_ids[root['C_id']] for root in old_roots]

    items_pasted_event.signal()

    return (new_roots, new_ids)
Exemplo n.º 20
0
def copy_items(filename, cids):
    qmemory = core_api.get_memory_connection()
    cursorm = qmemory.cursor()
    cursorm.execute(queries.copy_delete)
    core_api.give_memory_connection(qmemory)

    copy_items_event.signal()

    global origin_filename
    origin_filename = filename

    for id_ in cids:
        info = core_api.get_item_info(filename, id_)
        record = (id_, info['parent'], info['previous'], info['text'])

        qmemory = core_api.get_memory_connection()
        cursorm = qmemory.cursor()
        cursorm.execute(queries.copy_insert, record)
        core_api.give_memory_connection(qmemory)

        item_copy_event.signal(filename=filename, id_=id_)
Exemplo n.º 21
0
def copy_items(filename, cids):
    qmemory = core_api.get_memory_connection()
    cursorm = qmemory.cursor()
    cursorm.execute(queries.copy_delete)
    core_api.give_memory_connection(qmemory)

    copy_items_event.signal()

    global origin_filename
    origin_filename = filename

    for id_ in cids:
        info = core_api.get_item_info(filename, id_)
        record = (id_, info['parent'], info['previous'], info['text'])

        qmemory = core_api.get_memory_connection()
        cursorm = qmemory.cursor()
        cursorm.execute(queries.copy_insert, record)
        core_api.give_memory_connection(qmemory)

        item_copy_event.signal(filename=filename, id_=id_)
Exemplo n.º 22
0
def paste_items(filename, baseid, mode, group, description='Paste items'):
    qmemory = core_api.get_memory_connection()
    cursor = qmemory.cursor()
    cursor.execute(queries.copy_select_parent_roots)
    old_roots = cursor.fetchall()
    core_api.give_memory_connection(qmemory)

    old_to_new_ids = {}

    def recurse(baseid, previd):
        cursor.execute(queries.copy_select_parent, (baseid, previd))
        child = cursor.fetchone()

        if child:
            id_ = child['C_id']

            old_to_new_ids[id_] = core_api.append_item(
                                filename, old_to_new_ids[baseid], group=group,
                                text=child['C_text'], description=description)

            item_paste_event.signal(filename=filename, id_=old_to_new_ids[id_],
                                    oldid=id_, group=group,
                                    description=description)

            recurse(id_, 0)
            recurse(baseid, id_)

    if mode == 'siblings':
        old_roots.reverse()

    for root in old_roots:
        if mode == 'children':
            old_to_new_ids[root['C_id']] = core_api.append_item(
                                filename, baseid, group=group,
                                text=root['C_text'], description=description)
        elif mode == 'siblings':
            old_to_new_ids[root['C_id']] = core_api.insert_item_after(
                                filename, baseid, group=group,
                                text=root['C_text'], description=description)

        item_paste_event.signal(filename=filename,
                                            id_=old_to_new_ids[root['C_id']],
                                            oldid=root['C_id'], group=group,
                                            description=description)

        recurse(root['C_id'], 0)

    new_ids = old_to_new_ids.values()
    new_roots = [old_to_new_ids[root['C_id']] for root in old_roots]

    items_pasted_event.signal()

    return (new_roots, new_ids)
Exemplo n.º 23
0
def break_copied_links(filename, id_):
    # Breaking links in the CopyLinks table will not be stored in the history,
    # so this is useful only if undoing/redoing changes will warn the user and
    # break all the copied links
    if copypaste_api.get_copy_origin_filename() == filename:
        mconn = core_api.get_memory_connection()
        curm = mconn.cursor()

        curm.execute(queries.copylinks_select_target, (id_, ))

        for row in curm.fetchall():
            curm.execute(queries.copylinks_update_id, (row['CL_id'], ))

        core_api.give_memory_connection(mconn)
Exemplo n.º 24
0
def break_copied_links(filename, id_):
    # Breaking links in the CopyLinks table will not be stored in the history,
    # so this is useful only if undoing/redoing changes will warn the user and
    # break all the copied links
    if copypaste_api.get_copy_origin_filename() == filename:
        mconn = core_api.get_memory_connection()
        curm = mconn.cursor()

        curm.execute(queries.copylinks_select_target, (id_, ))

        for row in curm.fetchall():
            curm.execute(queries.copylinks_update_id, (row['CL_id'], ))

        core_api.give_memory_connection(mconn)
Exemplo n.º 25
0
    def _handle_copy_item(self, kwargs):
        filename = kwargs['filename']
        id_ = kwargs['id_']
        record = [id_, ]

        try:
            db = self.databases[filename]
        except KeyError:
            # Even if the database doesn't support rules, create a correct
            # table that can be safely used when pasting
            record.append(items.Database.rules_to_string([]))
        else:
            record.extend(db.copy_item_rules(id_))

        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyrules_insert, record)
        core_api.give_memory_connection(mem)
Exemplo n.º 26
0
    def _handle_copy_item(self, kwargs):
        filename = kwargs['filename']
        id_ = kwargs['id_']
        record = [id_, ]

        try:
            db = self.databases[filename]
        except KeyError:
            # Even if the database doesn't support rules, create a correct
            # table that can be safely used when pasting
            record.append(items.Database.rules_to_string([]))
        else:
            record.extend(db.copy_item_rules(id_))

        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copyrules_insert, record)
        core_api.give_memory_connection(mem)
Exemplo n.º 27
0
    def copy_alarms(self, id_):
        occs = []

        conn = core_api.get_connection(self.filename)
        cur = conn.cursor()
        cur.execute(queries.alarms_select_item, (id_, ))

        for row in cur:
            occs.append(row)

        core_api.give_connection(self.filename, conn)

        mem = core_api.get_memory_connection()
        curm = mem.cursor()

        for o in occs:
            curm.execute(queries.copyalarms_insert, (o['A_id'], id_,
                        o['A_start'], o['A_end'], o['A_alarm'], o['A_snooze']))

        core_api.give_memory_connection(mem)
Exemplo n.º 28
0
def paste_link(filename, id_, oldid, group, description):
    if filename in cdbs:
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copylinks_select_id, (oldid, ))
        core_api.give_memory_connection(mem)
        row = curm.fetchone()

        if row:
            # Item is a link
            if copypaste_api.get_copy_origin_filename() == filename:
                # Pasting on the same database is always safe, although the
                # link could have been broken by a deletion or a history change
                target = row['CL_target']
            else:
                # If pasting on a different database, the link must be broken,
                # in fact even if the target is pasted too there's not a simple
                # way of retrieving its new id
                target = None

            upsert_link(filename, id_, target, group, description)
Exemplo n.º 29
0
    def copy_alarms(self, id_):
        occs = []

        conn = core_api.get_connection(self.filename)
        cur = conn.cursor()
        cur.execute(queries.alarms_select_item, (id_, ))

        for row in cur:
            occs.append(row)

        core_api.give_connection(self.filename, conn)

        mem = core_api.get_memory_connection()
        curm = mem.cursor()

        for o in occs:
            curm.execute(queries.copyalarms_insert,
                         (o['A_id'], id_, o['A_start'], o['A_end'],
                          o['A_alarm'], o['A_snooze']))

        core_api.give_memory_connection(mem)
Exemplo n.º 30
0
def paste_link(filename, id_, oldid, group, description):
    if filename in cdbs:
        mem = core_api.get_memory_connection()
        curm = mem.cursor()
        curm.execute(queries.copylinks_select_id, (oldid, ))
        core_api.give_memory_connection(mem)
        row = curm.fetchone()

        if row:
            # Item is a link
            if copypaste_api.get_copy_origin_filename() == filename:
                # Pasting on the same database is always safe, although the
                # link could have been broken by a deletion or a history change
                target = row['CL_target']
            else:
                # If pasting on a different database, the link must be broken,
                # in fact even if the target is pasted too there's not a simple
                # way of retrieving its new id
                target = None

            upsert_link(filename, id_, target, group, description)
Exemplo n.º 31
0
def break_all_copied_links(filename):
    if copypaste_api.get_copy_origin_filename() == filename:
        mconn = core_api.get_memory_connection()
        curm = mconn.cursor()
        curm.execute(queries.copylinks_update_id_break)
        core_api.give_memory_connection(mconn)
Exemplo n.º 32
0
def create_copy_table():
    mem = core_api.get_memory_connection()
    cur = mem.cursor()
    cur.execute(queries.copylinks_create)
    core_api.give_memory_connection(mem)
Exemplo n.º 33
0
 def _create_copy_table(self):
     mem = core_api.get_memory_connection()
     cur = mem.cursor()
     cur.execute(queries.copyalarms_create)
     core_api.give_memory_connection(mem)
Exemplo n.º 34
0
def main():
    qmemory = core_api.get_memory_connection()
    cursor = qmemory.cursor()
    cursor.execute(queries.copy_create)
    core_api.give_memory_connection(qmemory)
Exemplo n.º 35
0
def main():
    qmemory = core_api.get_memory_connection()
    cursor = qmemory.cursor()
    cursor.execute(queries.copy_create)
    core_api.give_memory_connection(qmemory)
Exemplo n.º 36
0
 def _create_copy_table(self):
     mem = core_api.get_memory_connection()
     cur = mem.cursor()
     cur.execute(queries.copyrules_create)
     core_api.give_memory_connection(mem)
Exemplo n.º 37
0
def break_all_copied_links(filename):
    if copypaste_api.get_copy_origin_filename() == filename:
        mconn = core_api.get_memory_connection()
        curm = mconn.cursor()
        curm.execute(queries.copylinks_update_id_break)
        core_api.give_memory_connection(mconn)