-
Notifications
You must be signed in to change notification settings - Fork 1
/
device-dump.py
70 lines (52 loc) · 1.57 KB
/
device-dump.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import pathlib
from pathlib import Path
def safe_cat(file_name):
if isinstance(file_name, str):
file_name = pathlib.Path(file_name)
elif not isinstance(file_name, pathlib.PurePath):
raise ValueError(file_name)
if str(file_name).startswith('~/'):
file_name = file_name.expanduser()
if not file_name.is_file():
return ''
return file_name.read_text()
def safe_ls(path_name):
if isinstance(path_name, str):
path_name = pathlib.Path(path_name)
elif not isinstance(path_name, pathlib.PurePath):
raise ValueError(path_name)
if str(path_name).startswith('~/'):
path_name = path_name.expanduser()
if not path_name.is_dir():
return []
return [
str(file_name)
for file_name in path_name.iterdir()]
if __name__ == '__main__':
files = [
'/etc/os-release',
'/opt/.retrooz/device',
'~/.config/.OS_ARCH',
'~/.config/.DEVICE',
'~/.config/.OS',
'/usr/share/plymouth/themes/text.plymouth',
'/sys/firmware/devicetree/base/model',
'/sys/firmware/devicetree/base/compatible',
'/sys/class/dmi/id/sys_vendor',
'/sys/class/dmi/id/product_name',
]
dirs = [
'/dev/input/by-path',
'/boot/',
]
print("-- HARDWARE INFO --")
print("-" * 30)
for file in files:
print(f"{file}:")
print(safe_cat(file))
print("-" * 30)
for dir in dirs:
print(f"{dir}:")
print('\n'.join(safe_ls(dir)))
print("-" * 30)