-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathhelpers.py
More file actions
42 lines (32 loc) · 1.07 KB
/
helpers.py
File metadata and controls
42 lines (32 loc) · 1.07 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
from pathlib import Path
from typing import List, Union
PathStr = Union[Path, str]
def _openscad_library_paths() -> List[Path]:
"""
Return system-dependent OpenSCAD library paths or paths defined in os.environ['OPENSCADPATH']
"""
import platform
import os
import re
paths = [Path('.')]
user_path = os.environ.get('OPENSCADPATH')
if user_path:
for s in re.split(r'\s*[;:]\s*', user_path):
paths.append(Path(s))
default_paths = {
'Linux': Path.home() / '.local/share/OpenSCAD/libraries',
'Darwin': Path.home() / 'Documents/OpenSCAD/libraries',
'Windows': Path('My Documents\OpenSCAD\libraries')
}
paths.append(default_paths[platform.system()])
return paths
def _find_library(library_name: PathStr) -> Path:
result = Path(library_name)
if not result.is_absolute():
paths = _openscad_library_paths()
for p in paths:
f = p / result
# print(f'Checking {f} -> {f.exists()}')
if f.exists():
result = f
return result