-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathutils.py
More file actions
78 lines (61 loc) · 1.86 KB
/
utils.py
File metadata and controls
78 lines (61 loc) · 1.86 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
import subprocess
import os
import pathlib
import glob
import logging
import shutil
from config import config
from model.defs import *
logger = logging.getLogger("Utils")
def check_deps():
cl = config.get("path_cl")
if shutil.which(cl) == None:
logger.error("Missing dependency: " + cl)
logger.error("See README for fix")
exit(1)
ml = config.get("path_ml64")
if shutil.which(ml) == None:
logger.error("Missing dependency: " + ml)
logger.error("See README for fix")
exit(1)
def command_exists(cmd):
try:
# Use the "where" command to check if the command is in the PATH
result = subprocess.run(
["where", cmd],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=True
)
return result.returncode == 0
except Exception:
return False
def delete_all_files_in_directory(directory_path):
files = glob.glob(os.path.join(directory_path, '*'))
for file_path in files:
try:
os.remove(file_path)
#logger.info(f"Deleted {file_path}")
except Exception as e:
logger.info(f"Error deleting {file_path}: {e}")
def hexdump(data, addr = 0, num = 0):
s = ''
n = 0
lines = []
if num == 0: num = len(data)
if len(data) == 0:
return '<empty>'
for i in range(0, num, 16):
line = ''
line += '%04x | ' % (addr + i)
n += 16
for j in range(n-16, n):
if j >= len(data): break
line += '%02x ' % (data[j] & 0xff)
line += ' ' * (3 * 16 + 7 - len(line)) + ' | '
for j in range(n-16, n):
if j >= len(data): break
c = data[j] if not (data[j] < 0x20 or data[j] > 0x7e) else '.'
line += '%c' % c
lines.append(line)
return '\n'.join(lines)