[770c98]: / Tools / ModelUtilities / Python / ams_python_utils.py

Download this file

46 lines (32 with data), 1.2 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
import os
from pathlib import Path
from dataclasses import dataclass
from typing import Tuple
@dataclass
class AMSContext:
py_file: str
fun_name: str
anyfun_full_name: str
anyfunex_file: str
anyfunex_line: int
call_location_file: str
Ctx = Tuple[str, str, str, str, int, str]
def os_path_exists(context: Ctx, fpath: str) -> int:
context = AMSContext(*context)
fpath = Path(fpath)
if not fpath.is_absolute():
fpath = Path(context.call_location_file).parent.joinpath(fpath)
return int(os.path.exists(fpath))
def os_path_dirname(context: Ctx, fpath: str) -> str:
return os.path.dirname(fpath)
def os_path_abspath(context: Ctx, fpath: str) -> str:
context = AMSContext(*context)
fpath = Path(fpath)
if not fpath.is_absolute():
fpath = Path(context.call_location_file).parent.joinpath(fpath)
return os.path.abspath(fpath)
def os_path_basename(context: Ctx, fpath: str) -> str:
return os.path.basename(fpath)
def get_current_file(context: Ctx) -> str:
context = AMSContext(*context)
return context.call_location_file