-
Notifications
You must be signed in to change notification settings - Fork 1
/
public_path.py
53 lines (35 loc) · 1.28 KB
/
public_path.py
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
import json
import os
from pathlib import Path
from enum import Enum
from typing import Union
class AssetDir(Enum):
CONFIG = 'config'
SCRIPTS = 'scripts'
class ConfigFiles(Enum):
DEFAULT = 'default.json'
class ScriptType(Enum):
pre_script = 'pre_script'
post_script = 'post_script'
foreach_pre_script = 'foreach_pre_script'
foreach_post_script = 'foreach_post_script'
def get_AssetDir_path(subpath: AssetDir) -> Path:
return Path(__file__).parent.joinpath('asset', subpath.value)
def get_ConfigDir() -> Path:
return get_AssetDir_path(AssetDir.CONFIG)
def get_ConfigFile(filename=ConfigFiles.DEFAULT.value) -> Path:
return get_AssetDir_path(AssetDir.CONFIG).joinpath(filename)
def save_ConfigFile(filename=ConfigFiles.DEFAULT.value, data: dict = None):
if not data: return
path = get_ConfigFile(filename)
with open(path, 'w', encoding='utf-8') as f:
json.dump(data, fp=f)
def get_ScriptDir() -> Path:
return get_AssetDir_path(AssetDir.SCRIPTS)
def get_ScriptFile(filename) -> Union[Path, None]:
# walk through all files in the script directory
for root, dirs, files in os.walk(get_ScriptDir()):
for file in files:
if file == filename:
return Path(root).joinpath(file)
return None