-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
35 lines (35 loc) · 1.3 KB
/
util.py
File metadata and controls
35 lines (35 loc) · 1.3 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
def get_path(name='log', abspath=None, relative_path=None,
_file=None, parent=False):
"""Create path if path don't exist
Args:
name: folder name
abspath: absolute path to be prefix
relative_path: relative path that can be convert into absolute path
_file: use directory based on _file
parent: whether the path is in the parent folder
Returns: Path of the folder
"""
import os
if abspath:
directory = os.path.abspath(os.path.join(abspath, name))
elif relative_path:
directory = os.path.abspath(os.path.join(
os.path.abspath(relative_path), name))
else:
if _file:
if parent:
directory = os.path.abspath(
os.path.join(os.path.dirname(_file), os.pardir, name))
else:
directory = os.path.abspath(
os.path.join(os.path.dirname(_file), name))
else:
if parent:
directory = os.path.abspath(
os.path.join(os.path.dirname(__file__), os.pardir, name))
else:
directory = os.path.abspath(
os.path.join(os.path.dirname(__file__), name))
if not os.path.exists(directory):
os.makedirs(directory)
return directory