-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathutil.py
More file actions
71 lines (63 loc) · 2.04 KB
/
util.py
File metadata and controls
71 lines (63 loc) · 2.04 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
import lvgl as lv
import os
def urldecode(s):
result = ""
i = 0
while i < len(s):
if s[i] == '%':
result += chr(int(s[i+1:i+3], 16))
i += 3
else:
result += s[i]
i += 1
return result
def print_lvgl_widget(obj, depth=0):
if obj:
label = ""
hidden = ""
editable = "editable"
obj_area = lv.area_t()
obj.get_coords(obj_area)
if obj.has_flag(lv.obj.FLAG.HIDDEN):
hidden = "hidden "
if not obj.is_editable():
editable = "not editable "
if isinstance(obj,lv.label):
label = f" with label '{obj.get_text()}'"
padding = " " * depth
print(f"{padding}{obj} pos:{obj_area.x1}x{obj_area.y1} size:{obj_area.get_width()}x{obj_area.get_height()} {hidden}{editable} {label}")
for childnr in range(obj.get_child_count()):
print_lvgl_widget(obj.get_child(childnr), depth+1)
else:
print("print_lvgl_widget called on 'None'")
def mkdir_parents(path):
"""
Create directory and all parent directories like `mkdir -p`.
Creates intermediate directories as needed, does nothing if the path
already exists, and raises if any component exists as a non-directory.
"""
if not path:
return
def _is_dir(stat_result):
return (stat_result[0] & 0x4000) != 0
parts = path.split("/")
current = "/" if path.startswith("/") else ""
for part in parts:
if not part:
continue
if current in ("", "/"):
current = f"{current}{part}"
else:
current = f"{current}/{part}"
try:
stat_result = os.stat(current)
except OSError:
try:
os.mkdir(current)
except OSError:
stat_result = os.stat(current)
if not _is_dir(stat_result):
raise
else:
if not _is_dir(stat_result):
raise OSError("Path component exists and is not a directory")