From b1782b6c53380d7a38b767ae924a71a4cf9bd8b7 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Thu, 25 Oct 2018 00:06:07 -0500 Subject: [PATCH] searcher class in TODO mode general structure is there --- .gitignore | 2 +- load_save.py | 35 ----------------------------------- searcher.py | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 36 deletions(-) delete mode 100644 load_save.py create mode 100644 searcher.py diff --git a/.gitignore b/.gitignore index d441544..5bd0189 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,7 @@ coverage.xml # Django stuff: *.log - +*.db # Sphinx documentation docs/_build/ diff --git a/load_save.py b/load_save.py deleted file mode 100644 index e7dc475..0000000 --- a/load_save.py +++ /dev/null @@ -1,35 +0,0 @@ -import json -from build import build, build_ext_list -import time -def full(ext,*starts): - stime = time.time() - paths = build(0,*starts) - names = build_ext_list(ext,paths) - return { - "meta" : { - "ext" : ext, - "time": stime, - }, - "data": names - } - -def save(ext_map): - ext = ext_map["meta"]["ext"] - with open(f"{ext}-cache.json","w") as file: - json.dump(ext_map,file) - -def load(ext): - with open(f"{ext}-cache.json") as file: - return json.load(file) - -def update(ext,*starts): - ext_map = load(ext) - prev_time = ext_map["meta"]["time"] - stime = time.time() - paths = build(prev_time,*starts) - names = build_ext_list(ext,paths) - ext_map.update(names) - ext_map["meta"]["time"] = stime - save(ext_map) - return ext_map - \ No newline at end of file diff --git a/searcher.py b/searcher.py new file mode 100644 index 0000000..5dddaba --- /dev/null +++ b/searcher.py @@ -0,0 +1,23 @@ +import sqlite3 +import os +osp = os.path +DB_PATH = osp.join(osp.dirname(__file__),'ext.db') +ext_database = sqlite3.connect(DB_PATH) +def init_table(): + cur = ext_database.cursor() + cur.execute('CREATE TABLE "update_times" ( `ext` TEXT, `update_times` INTEGER, PRIMARY KEY(`ext`) )') +class Searcher: + def __init__(self,ext): + self.cur = ext_database.cursor() + self.ext = ext + self.index = '{}_index'.format(ext) + def __init_table__(self): + self.cur.execute('CREATE TABLE IF NOT EXISTS ? (`name` TEXT,`fullpath` TEXT,UNIQUE(name,fullpath));',[self.ext]) + self.cur.execute('CREATE INDEX IF NOT EXISTS ? ON ? ( `name`, `fullpath` )',[self.index,self.ext]) + def _update_(self): + # update logic + self.cur.executemany('INSERT OR IGNORE INTO ? VALUES (?,?)',params) + def _commit_(self): + ext_database.commit() + def search(query,regex=False): + pass \ No newline at end of file