-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
39 lines (31 loc) · 1 KB
/
tools.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
import re, os
def clearScreen():
os.system("clear")
def validateText(text):
return bool(re.match("^[a-zA-Z0-9_-]{3,15}$", text))
def splitCommand(command):
return command.split() if command.strip() else []
def readInfoFile(filepath):
try:
with open(filepath, 'r') as file:
lines = file.readlines()
info = {}
for line in lines:
if ' = ' in line:
key, value = line.strip().split(' = ', 1)
info[key] = value
return info
except Exception as e:
print(f"Error: {e}")
return {}
def writeInfoFile(filepath, username, hostname):
try:
with open(filepath, 'w') as file:
file.write(f"username = {username}\n")
file.write(f"hostname = {hostname}\n")
except Exception as e:
print(f"Error: {e}")
def sanitizeFilename(filename):
return re.sub(r'[\\/:*?"<>|]', "", filename)
def ensureUnixPath(path):
return path.replace("\\", "/")