Browse Source

searcher class in TODO mode

general structure is there
master
Raphael Roberts 7 years ago
parent
commit
b1782b6c53
  1. 2
      .gitignore
  2. 35
      load_save.py
  3. 23
      searcher.py

2
.gitignore

@ -51,7 +51,7 @@ coverage.xml
# Django stuff:
*.log
*.db
# Sphinx documentation
docs/_build/

35
load_save.py

@ -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

23
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
Loading…
Cancel
Save