forked from cselab/aphros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindpath.py
42 lines (38 loc) · 1.27 KB
/
findpath.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
from sphinx.util import logging
import os
def Error(msg, location):
logger = logging.getLogger(__name__)
logger.error(msg, location=location)
def Assert(flag, msg, location=None):
if not flag:
Error(msg, location=location)
def FindPath(relpath, location):
"""
relpath: path to file relative to repository root
or relative to predefined locations, see Try(...)
location: caller location (docname, lineno)
Returns:
abspath: absolute path to file
relpath: update path relative to repository root
"""
def Try(abspath, *path):
s = os.path.abspath(os.path.join(*path))
if os.path.exists(s):
Assert(not abspath,
"Ambiguous path: target found in '{:}' and '{:}'".format(
abspath, s), location)
return s
return abspath
r = relpath
repo = os.path.abspath(os.path.join(os.getcwd(), "../../"))
a = "" # absolute path
a = Try(a, repo, r)
a = Try(a, repo, "deploy", r)
a = Try(a, repo, "doc/sphinx/src/log", r)
a = Try(a, repo, "deploy/lib", r)
a = Try(a, repo, "deploy/scripts", r)
a = Try(a, repo, "deploy/scripts_gen", r)
a = Try(a, repo, "src", r)
if not a:
return a, a
return a, os.path.relpath(a, repo)