forked from ImL1s/termux-flutter-wsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
91 lines (70 loc) · 2.27 KB
/
utils.py
File metadata and controls
91 lines (70 loc) · 2.27 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import sys
import git
import inspect
from loguru import logger
from functools import wraps
__ARCH__ = dict(arm='arm', arm64='aarch64', x64='x86_64', x86='i686')
__MODE__ = ('debug', 'release', 'profile')
if os.environ.get('PREFIX') == '/data/data/com.termux/files/usr':
__TERMUX__ = 'true'
else:
__TERMUX__ = 'false'
def termux_arch(arch: str):
if arch in __ARCH__:
return __ARCH__[arch]
if arch in __ARCH__.values():
return arch
raise ValueError(f'unknown arch: "{arch}"')
def target_output(root: str, arch: str, mode: str, opted: bool = True):
root = os.path.abspath(os.path.expanduser(root))
if opted:
dest = f'linux_{mode}_{arch}'
else:
dest = f'linux_{mode}_unopt_{arch}'
return os.path.join(root, 'engine', 'src', 'out', dest)
def flutter_tag(root: str):
if not os.path.isdir(root):
return None
try:
return git.Repo(root).git.describe('--tag', '--abbrev=0')
except git.exc.GitCommandError:
return None
# TODO: see bin/internal/update_engine_version.sh
def engine_version(root: str):
root = os.path.join(root, 'bin/internal/engine.version')
with open(root) as f:
return f.read()
def recordm(func):
@wraps(func)
def wrapper(*args, **kwargs):
if os.environ.get('NO_RECORD'):
return func(*args, **kwargs)
if args and inspect.isclass(type(args[0])):
class_name = args[0].__class__.__name__
logged_args = args[1:]
else:
class_name = ''
logged_args = args
method = func.__name__
if class_name:
method = f'{class_name}.{method}'
logged_args = [str(it) for it in logged_args]
for k, v in kwargs.items():
logged_args.append(f'{k}={v}')
logged_args = ', '.join(logged_args)
logger.debug(f'{method}({logged_args})')
try:
return func(*args, **kwargs)
except Exception as e:
logger.exception(e)
sys.exit(1)
return wrapper
def record(cls):
for name, method in vars(cls).items():
if callable(method) and not name.startswith('__'):
setattr(cls, name, recordm(method))
return cls
if __name__ == '__main__':
import fire
fire.Fire()