ソースを参照

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