-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtestund.py
More file actions
61 lines (47 loc) · 1.52 KB
/
testund.py
File metadata and controls
61 lines (47 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import sys
import os
import understand
def check_for_classes(db_path):
"""
Check if an Understand database contains any classes.
Args:
db_path (str): Path to the .und database file
Returns:
bool: True if classes exist, False otherwise
"""
try:
# Open the database
db = understand.open(db_path)
# Get all entities of kind "class"
classes = db.ents("class")
# Print the number of classes found
print(f"Found {len(classes)} classes in the database.")
# Print each class if any exist
if classes:
print("\nClasses found:")
for cls in classes:
print(f" - {cls.longname()} [{cls.language()}]")
return True
else:
print("No classes found in the database.")
return False
except understand.UnderstandError as e:
print(f"Error: {e}")
return False
finally:
# Close the database if it was opened
if 'db' in locals() and db:
db.close()
if __name__ == "__main__":
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <path_to_und_file>")
sys.exit(1)
db_path = sys.argv[1]
# Check if the file exists and is a .und file
if not os.path.exists(db_path):
print(f"Error: File {db_path} does not exist.")
sys.exit(1)
if not db_path.endswith('.und'):
print(f"Warning: File {db_path} does not have a .und extension.")
check_for_classes(db_path)