-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.py
More file actions
99 lines (81 loc) · 2.68 KB
/
scripts.py
File metadata and controls
99 lines (81 loc) · 2.68 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Helper scripts for Poe the Poet tasks.
These functions work cross-platform (Windows, Linux, macOS).
"""
import os
import sys
import subprocess
from pathlib import Path
def generate_pg():
"""Generate shaclrules/_PG.py from profileguard.ttl"""
print("Generating _PG.py from profileguard.ttl...")
# Find the rdflib defined_namespace_creator.py
# Use site module to find site-packages location
import site
site_packages = site.getsitepackages()
creator_script = None
for site_pkg in site_packages:
path_script = "rdflib/tools/defined_namespace_creator.py"
potential_script = Path(site_pkg) / path_script
if potential_script.exists():
creator_script = potential_script
break
if not creator_script:
print("Error: Could not find defined_namespace_creator.py")
print(f"Searched in: {site_packages}")
sys.exit(1)
print(f"Using: {creator_script}")
# Change to shaclrules directory and run the script
original_dir = os.getcwd()
os.chdir("shaclrules")
try:
subprocess.run([
sys.executable,
str(creator_script),
"profileguard.ttl",
"http://data.europa.eu/semic/ns/profileguard#",
"PG"
], check=True)
print("✓ Successfully generated _PG.py")
except subprocess.CalledProcessError as e:
print(f"✗ Error generating _PG.py: {e}")
sys.exit(1)
finally:
os.chdir(original_dir)
def run_pguard():
"""Run pguard to generate dcat-ap-rules.ttl"""
print("Generating dcat-ap-rules.ttl...")
# pguard is a Python script without extension
pguard_script = Path("pguard")
if not pguard_script.exists():
print("Error: Could not find pguard script")
sys.exit(1)
try:
# Run pguard as a Python script
subprocess.run([
sys.executable,
str(pguard_script),
"dcat-ap-SHACL.ttl",
"--self-check",
"--output",
"dcat-ap-rules.ttl"
], check=True)
print("✓ Successfully generated dcat-ap-rules.ttl")
except subprocess.CalledProcessError as e:
print(f"✗ Error running pguard: {e}")
sys.exit(1)
def clean_files():
"""Clean generated files (cross-platform)"""
print("Cleaning generated files...")
files_to_remove = [
"dcat-ap-rules.ttl",
"shaclrules/_PG.py",
]
for file_path in files_to_remove:
path = Path(file_path)
if path.exists():
path.unlink()
print(f"✓ Removed {file_path}")
else:
print(f" {file_path} (not found)")
print("✓ Cleanup complete")