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)
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)
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"]()
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()
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'])
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)
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']()
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']()
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
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)
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)
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)
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)
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)
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)
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_)
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)
def create_copy_table(): mem = core_api.get_memory_connection() cur = mem.cursor() cur.execute(queries.copylinks_create) core_api.give_memory_connection(mem)
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)
def main(): qmemory = core_api.get_memory_connection() cursor = qmemory.cursor() cursor.execute(queries.copy_create) core_api.give_memory_connection(qmemory)
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)