Skip to content

Commit 9ad0002

Browse files
ADFA-989 add tier 1 and tier 2 tooltips to new documentation sqlite db (#9)
* Snapshot of tooltips from Elissa * Support for import of Elissa's tooltip xlsx file; TODO: Alex's tooltips * Add tooltips to publish db workflow
1 parent 771cdd9 commit 9ad0002

10 files changed

Lines changed: 510 additions & 323 deletions

File tree

.github/workflows/publish-doc-db.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ jobs:
6060
PYTHONPATH=scripts uv run python scripts/ingest.py -p build/documentation-${{ github.ref_name }}.sqlite -d "$dir"
6161
done
6262
63+
- name: Store tooltips
64+
run: |
65+
PYTHONPATH=scripts uv run python scripts/import_tooltips.py -i SourceDocs/Tooltips/tooltips.xlsx -d build/documentation-${{ github.ref_name }}.sqlite
66+
6367
- name: Verify database
6468
run: |
6569
if [ ! -f "build/documentation-${{ github.ref_name }}.sqlite" ]; then

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ ProcessDocs/ProcessKotlinDocs/KotlinLLMScratch/openaikey.txt
99
ProcessDocs/ProcessAndroidDevSite/DevsiteLLMScratch/openaikey.txt
1010
__pycache__/
1111
*.py[cod]
12-
*$py.class
12+
*$py.class
13+
*.db
14+
*.sqlite

SourceDocs/Tooltips/tooltips.xlsx

32.9 KB
Binary file not shown.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ lxml
33
faker
44
brotli
55
Pillow
6+
openpyxl

scripts/DocumentationDatabase.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ class DocumentationDatabase:
5959
value TEXT NOT NULL UNIQUE,
6060
compression TEXT NOT NULL
6161
);
62-
63-
CREATE TABLE IF NOT EXISTS ide_tooltip_table (
64-
id INTEGER PRIMARY KEY AUTOINCREMENT,
65-
path TEXT NOT NULL,
66-
languageID INTEGER NOT NULL,
67-
content TEXT NOT NULL,
68-
FOREIGN KEY (languageID) REFERENCES Languages(id)
69-
);
7062
"""
7163

7264
def __init__(self, database_path):
@@ -87,12 +79,20 @@ def __init__(self, database_path):
8779
cursor = connection.cursor()
8880
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
8981
tables = cursor.fetchall()
90-
expected_tables = {'ide_tooltip_table', 'Content', 'Languages', 'ContentTypes'}
82+
# Core tables that must exist
83+
required_tables = {'Content', 'Languages', 'ContentTypes'}
84+
# Optional tables that may exist
85+
optional_tables = {'ide_tooltip_table'}
9186
existing_tables = {table[0] for table in tables}
9287
# Ignore any tables that start with 'sqlite_'
9388
filtered_tables = {table for table in existing_tables if not table.startswith('sqlite_')}
94-
if filtered_tables != expected_tables:
95-
raise ValueError("Database schema does not match the expected schema")
89+
# Check if all required tables exist
90+
if not required_tables.issubset(filtered_tables):
91+
raise ValueError("Database schema is missing required tables")
92+
# Check if there are any unexpected tables
93+
unexpected_tables = filtered_tables - required_tables - optional_tables
94+
if unexpected_tables:
95+
raise ValueError(f"Database schema contains unexpected tables: {unexpected_tables}")
9696

9797
@contextlib.contextmanager
9898
def get_connection(self):
@@ -131,12 +131,14 @@ def populate_languages(self, cursor):
131131
cursor.execute("INSERT INTO Languages (value) VALUES ('en-US');")
132132

133133
def normalize_path(self, path):
134-
"""Remove leading ../ and ./ sequences from a path."""
134+
"""Remove leading ../, ./ sequences and 'SourceDocs' from a path."""
135135
while path.startswith('../') or path.startswith('./'):
136136
if path.startswith('../'):
137137
path = path[3:]
138138
elif path.startswith('./'):
139139
path = path[2:]
140+
if path.startswith('SourceDocs/'):
141+
path = path[11:] # Remove 'SourceDocs/' (11 characters)
140142
return path
141143

142144
def add_file(self, path, content, language):

scripts/import_tooltips.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import os
5+
import argparse
6+
from tooltips import TooltipDatabase
7+
import openpyxl
8+
9+
def main():
10+
parser = argparse.ArgumentParser(
11+
description='Import tooltips from Excel file to SQLite database',
12+
formatter_class=argparse.ArgumentDefaultsHelpFormatter
13+
)
14+
15+
parser.add_argument('-i', '--import',
16+
dest='xlsx_file',
17+
required=True,
18+
help='Path to the Excel file containing tooltips')
19+
20+
parser.add_argument('-d', '--database',
21+
dest='sqlite_db',
22+
required=True,
23+
help='Path to the SQLite database file to create/update')
24+
25+
args = parser.parse_args()
26+
27+
# Validate input files
28+
if not os.path.exists(args.xlsx_file):
29+
parser.error(f"Excel file '{args.xlsx_file}' does not exist")
30+
31+
if not args.xlsx_file.endswith('.xlsx'):
32+
parser.error(f"'{args.xlsx_file}' is not an Excel file")
33+
34+
# Create database directory if it doesn't exist
35+
db_dir = os.path.dirname(args.sqlite_db)
36+
if db_dir and not os.path.exists(db_dir):
37+
os.makedirs(db_dir)
38+
39+
try:
40+
# Create database and import data
41+
db = TooltipDatabase(args.sqlite_db, args.xlsx_file)
42+
result = db.read_xlsx()
43+
44+
# Print summary
45+
print(f"\nImport Summary:")
46+
print(f"Total rows in Excel: {result['total_rows']}")
47+
print(f"Successfully processed: {result['processed_rows']}")
48+
print(f"Skipped rows: {len(result['skipped_rows'])}")
49+
50+
if result['skipped_rows']:
51+
print("\nSkipped rows details:")
52+
for row_num, error in result['skipped_rows']:
53+
print(f"Row {row_num}: {error}")
54+
55+
print(f"\nSuccessfully imported tooltips from '{args.xlsx_file}' to '{args.sqlite_db}'")
56+
57+
except Exception as e:
58+
parser.error(f"Error importing tooltips: {str(e)}")
59+
60+
if __name__ == '__main__':
61+
main()

scripts/put_content_in_database.py

Lines changed: 0 additions & 196 deletions
This file was deleted.

0 commit comments

Comments
 (0)