def execute(self): _LOGGER_.debug("Executing GetAction") items = [] exists = 0 for row in self.db.execute_statement( "SELECT key, value, tags from KV where key like '%{}%' or tags like '%{}%'".format(self.text, self.text)): exists = 1 key = row[0] value = row[1] value_fix = value.strip().replace('$', '\$').replace('"', '\\"').replace('`', '\\`') + '\n' script_action = 'sleep 0.01m && echo -n "' + value_fix + \ '" | xclip -i -selection clipboard && sleep 0.01m && xdotool key --clearmodifiers ctrl+v &' item = ExtensionResultItem( icon=ICON, name="{} = {}".format(key, value.replace('&', '&')), description="Press enter or click to copy '{}' to clipboard or type 'unset' to unset from db".format( value), on_alt_enter=RunScriptAction(script_action, []), on_enter=CopyToClipboardAction(value)) items.append(item) if not exists: item = ExtensionResultItem(icon=ICON, name=NAME) if self.text == "": item._description = "It looks like you have nothing stored" else: item._description = "No VALUE for KEY: '{}'".format(self.text) items.append(item) return items
def execute(self): _LOGGER_.debug("Executing GetAction") items = [] exists = 0 for row in self.db.execute_statement( "SELECT key, value from KV where key like '%{}%'".format( self.text)): exists = 1 key = row[0] value = row[1] item = ExtensionResultItem( icon=ICON, name="{} = {}".format(key, value), description= "Press enter or click to copy '{}' to clipboard or type 'unset' to unset from db" .format(value), on_enter=CopyToClipboardAction(value)) items.append(item) if not exists: item = ExtensionResultItem(icon=ICON, name=NAME) if self.text == "": item._description = "It looks like you have nothing stored" else: item._description = "No VALUE for KEY: '{}'".format(self.text) items.append(item) return items
def get_action(self, key_filter): connection = sqlite3.connect(_db_) items = [] exists = 0 statement = "SELECT key, value from KV where key like '%{}%'".format(key_filter) for row in connection.execute(statement): exists = 1 key = row[0] value = row[1] item = ExtensionResultItem( icon=_icon_, name="{} = {}".format(key, value), description="Press enter or click to copy '{}' to clipboard or type 'unset' to unset from db".format(value), on_enter=CopyToClipboardAction(value)) items.append(item) if not exists: item = ExtensionResultItem(icon=_icon_, name=_name_) if key_filter == "": item._description = "It looks like you have nothing stored" else: item._description = "No VALUE for KEY: '{}'".format(key_filter) items.append(item) return items
def set_action(self, key, value): connection = sqlite3.connect(_db_) item = ExtensionResultItem(icon=_icon_, name="{} = {}".format(key, value)) cursor = connection.execute("SELECT key, value from KV where key = '{}'".format(key)) exists = 0 for _ in cursor: exists = 1 break if exists: statement = "UPDATE KV SET VALUE = '{}' WHERE KEY = '{}'".format(value, key) item._description = "Update '{}' with '{}'".format(key, value) else: statement = "INSERT INTO KV (KEY,VALUE) VALUES ('{}', '{}')".format(key, value) item._description = "Insert '{}' with '{}'".format(key, value) connection.execute(statement) connection.commit() return [item]
def execute(self): _LOGGER_.debug("==== Executing UnsetAction") exists = 0 statement = "SELECT key, value, tags from KV where key = '{}'".format(self.key_filter) key = "" value = "" for row in self.db.execute_statement(statement): exists = 1 key = row[0] value = row[1] item = ExtensionResultItem(icon=ICON, name=NAME) if exists: item._description = "Key '{}' of Value '{}' unset".format(key, value) statement = "DELETE FROM KV WHERE KEY = '{}'".format(key) self.db.execute_statement(statement) else: item._description = "'{}' not found to unset".format(self.key_filter) return [item]
def get_unset_action(self, key_filter): connection = sqlite3.connect(_db_) exists = 0 statement = "SELECT key, value from KV where key = '{}'".format(key_filter) key = "" value = "" for row in connection.execute(statement): exists = 1 key = row[0] value = row[1] item = ExtensionResultItem(icon=_icon_, name=_name_) if exists: item._description = "Key '{}' of Value '{}' unset".format(key, value) statement = "DELETE FROM KV WHERE KEY = '{}'".format(key) connection.execute(statement) connection.commit() else: item._description = "'{}' not found to unset".format(key_filter) return [item]
def execute(self): _LOGGER_.debug("==== Executing SetAction") item = ExtensionResultItem( icon=ICON, name="{} = {}".format(self.key, self.value.replace('&', '&')), description="") cursor = self.db.execute_statement("SELECT key, value, tags from KV where key = '{}'".format(self.key)) exists = 0 for _ in cursor: exists = 1 break if exists: statement = "UPDATE KV SET VALUE = '{}' WHERE KEY = '{}'".format(self.value, self.key) item._description = "Update '{}' with '{}'".format(self.key, self.value) else: statement = "INSERT INTO KV (KEY,VALUE) VALUES ('{}', '{}')".format(self.key, self.value) item._description = "Insert '{}' with '{}'".format(self.key, self.value) self.db.execute_statement(statement) _LOGGER_.debug("Insert '{}' with '{}'".format(self.key, self.value)) return [item]