From 9f762a02306d0ffdfafede473086850980ae6718 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Fri, 18 Aug 2017 14:43:28 +0200 Subject: [PATCH] Bootstrapper use python date functions instead of sqlite --- plugins/disabled-Bootstrapper/BootstrapperDb.py | 8 +++++--- src/Site/SiteStorage.py | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/disabled-Bootstrapper/BootstrapperDb.py b/plugins/disabled-Bootstrapper/BootstrapperDb.py index a3a91589..e9f690c6 100644 --- a/plugins/disabled-Bootstrapper/BootstrapperDb.py +++ b/plugins/disabled-Bootstrapper/BootstrapperDb.py @@ -20,8 +20,9 @@ class BootstrapperDb(Db): def cleanup(self): while 1: - self.execute("DELETE FROM peer WHERE date_announced < DATETIME('now', '-40 minute')") time.sleep(4*60) + timeout = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() - 60 * 40)) + self.execute("DELETE FROM peer WHERE date_announced < ?", [timeout]) def updateHashCache(self): res = self.execute("SELECT * FROM hash") @@ -96,14 +97,15 @@ class BootstrapperDb(Db): res = self.execute("SELECT * FROM peer WHERE ? LIMIT 1", {"ip4": ip4, "port": port}) user_row = res.fetchone() + now = time.strftime("%Y-%m-%d %H:%M:%S") if user_row: peer_id = user_row["peer_id"] - self.execute("UPDATE peer SET date_announced = DATETIME('now') WHERE ?", {"peer_id": peer_id}) + self.execute("UPDATE peer SET date_announced = ? WHERE peer_id = ?", (now, peer_id)) else: self.log.debug("New peer: %s %s signed: %s" % (ip4, onion, onion_signed)) if onion and not onion_signed: return len(hashes) - self.execute("INSERT INTO peer ?", {"ip4": ip4, "onion": onion, "port": port}) + self.execute("INSERT INTO peer ?", {"ip4": ip4, "onion": onion, "port": port, "date_announced": now}) peer_id = self.cur.cursor.lastrowid # Check user's hashes diff --git a/src/Site/SiteStorage.py b/src/Site/SiteStorage.py index bfdd7840..e1caabbc 100644 --- a/src/Site/SiteStorage.py +++ b/src/Site/SiteStorage.py @@ -163,8 +163,13 @@ class SiteStorage(object): return res # Open file object - def open(self, inner_path, mode="rb"): - return open(self.getPath(inner_path), mode) + def open(self, inner_path, mode="rb", create_dirs=False): + file_path = self.getPath(inner_path) + if create_dirs: + file_dir = os.path.dirname(file_path) + if not os.path.isdir(file_dir): + os.makedirs(file_dir) + return open(file_path, mode) # Open file object def read(self, inner_path, mode="r"):