def delete(url, table=control.bookmarksFile): try: data = json.loads(url) dbid = hashlib.md5() for i in data['delbookmark']: dbid.update(str(i)) for i in data['action']: dbid.update(str(i)) dbid = str(dbid.hexdigest()) control.makeFile(control.dataPath) dbcon = database.connect(table) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS bookmark (""dbid TEXT, ""item TEXT, ""UNIQUE(dbid)"");") dbcur.execute("DELETE FROM bookmark WHERE dbid = '{}'".format(dbid)) dbcon.commit() control.refresh() except Exception: pass
def timeout(function_, *args, **table): try: response = None f = repr(function_) f = re.sub(r'.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f) a = hashlib.md5() for i in args: a.update(str(i)) a = str(a.hexdigest()) except Exception: pass try: table = table['table'] except Exception: table = 'rel_list' try: control.makeFile(control.dataPath) dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM {tn} WHERE func = '{f}' AND args = '{a}'".format(tn=table, f=f, a=a)) match = dbcur.fetchone() return int(match[3]) except Exception: return
def add(url, table=control.bookmarksFile): try: data = json.loads(url) dbid = hashlib.md5() for i in data['bookmark']: dbid.update(str(i)) for i in data['action']: dbid.update(str(i)) dbid = str(dbid.hexdigest()) item = dict((k,v) for k, v in iteritems(data) if not k == 'bookmark') item = repr(item) control.makeFile(control.dataPath) dbcon = database.connect(table) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS bookmark (""dbid TEXT, ""item TEXT, ""UNIQUE(dbid)"");") dbcur.execute("DELETE FROM bookmark WHERE dbid = '{}'".format(dbid)) dbcur.execute("INSERT INTO bookmark Values (?, ?)", (dbid, item)) dbcon.commit() except Exception: pass
def clear(table=None, withyes=False, notify=True, file_=None, label_yes_no=30401, label_success=30402): if file_ is None: if control: file_ = control.cacheFile else: file_ = os.path.join(os.path.curdir, 'cache.db') try: if control: control.idle() if table is None: table = ['rel_list', 'rel_lib'] elif not type(table) == list: table = [table] if withyes and control: try: yes = control.yesnoDialog( control.lang(label_yes_no).encode('utf-8'), '', '') except Exception: yes = control.yesnoDialog(control.lang(label_yes_no), '', '') if not yes: return dbcon = database.connect(file_) dbcur = dbcon.cursor() for t in table: try: dbcur.execute("DROP TABLE IF EXISTS {0}".format(t)) dbcur.execute("VACUUM") dbcon.commit() except Exception: pass if control and notify: control.infoDialog(control.lang(label_success).encode('utf-8')) except Exception: pass
def get(table=control.bookmarksFile): try: control.makeFile(control.dataPath) dbcon = database.connect(table) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM bookmark") items = dbcur.fetchall() try: items = [evaluate(i[1].encode('utf-8')) for i in items] except Exception: items = [evaluate(i[1]) for i in items] return items except Exception: pass
def clear(table=None, withyes=True): try: control.idle() if table is None: table = ['rel_list', 'rel_lib'] elif not type(table) == list: table = [table] if withyes: try: yes = control.yesnoDialog(control.lang(30401).encode('utf-8'), '', '') except Exception: yes = control.yesnoDialog(control.lang(30401), '', '') if not yes: return else: pass dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() for t in table: try: dbcur.execute("DROP TABLE IF EXISTS {0}".format(t)) dbcur.execute("VACUUM") dbcon.commit() except Exception: pass control.infoDialog(control.lang(30402).encode('utf-8')) except Exception: pass
def get(function_, time_out, *args, **table): try: response = None f = repr(function_) f = re.sub('.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f) a = hashlib.md5() for i in args: a.update(str(i)) a = str(a.hexdigest()) except Exception: pass try: table = table['table'] except Exception: table = 'rel_list' try: control.makeFile(control.dataPath) dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM {tn} WHERE func = '{f}' AND args = '{a}'".format(tn=table, f=f, a=a)) match = dbcur.fetchone() try: response = evaluate(match[2].encode('utf-8')) except AttributeError: response = evaluate(match[2]) t1 = int(match[3]) t2 = int(time.time()) update = (abs(t2 - t1) / 3600) >= int(time_out) if not update: return response except Exception: pass try: r = function_(*args) if (r is None or r == []) and response is not None: return response elif r is None or r == []: return r except Exception: return try: r = repr(r) t = int(time.time()) dbcur.execute("CREATE TABLE IF NOT EXISTS {} (""func TEXT, ""args TEXT, ""response TEXT, ""added TEXT, ""UNIQUE(func, args)"");".format(table)) dbcur.execute("DELETE FROM {0} WHERE func = '{1}' AND args = '{2}'".format(table, f, a)) dbcur.execute("INSERT INTO {} Values (?, ?, ?, ?)".format(table), (f, a, r, t)) dbcon.commit() except Exception: pass try: return evaluate(r.encode('utf-8')) except Exception: return evaluate(r)