소스 검색

Use DB for list_tables().

scossu 9 달 전
부모
커밋
9577312600
1개의 변경된 파일16개의 추가작업 그리고 2개의 파일을 삭제
  1. 16 2
      scriptshifter/tables/__init__.py

+ 16 - 2
scriptshifter/tables/__init__.py

@@ -277,8 +277,22 @@ def list_tables():
     Note that this may not correspond to all the table files in the data
     Note that this may not correspond to all the table files in the data
     folder, but only those exposed in the index.
     folder, but only those exposed in the index.
     """
     """
-    with open(path.join(TABLE_DIR, "index.yml")) as fh:
-        tdata = load(fh, Loader=Loader)
+    conn = sqlite3.connect(DB_PATH)
+
+    with conn:
+        data = conn.execute(
+                """SELECT name, label, features, marc_code, description
+                FROM tbl_language""")
+        tdata = {
+            row[0]: {
+                "label": row[1],
+                "has_s2r": bool(row[2] & FEAT_S2R),
+                "has_r2s": bool(row[2] & FEAT_R2S),
+                "case_sensitive": not (row[2] & FEAT_CASEI),
+                "marc_code": row[3],
+                "description": row[4],
+            } for row in data
+        }
 
 
     return tdata
     return tdata