-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
executable file
·72 lines (53 loc) · 1.72 KB
/
util.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
71
72
import json
import sys
from ctypes import c_byte
from xml.dom import minidom
sys.stdout = open("misc/log", 'w')
def pretty_print_xml(s):
return minidom.parseString(s).toprettyxml(indent=' ', encoding='utf-8').decode()
def data_len_for_file(file):
data = file.read()
if isinstance(data, str):
raise TypeError("File must be opened in binary mode!")
b = bytearray(data)
buffertype = c_byte * len(b)
buffer = buffertype(*b)
return buffer, len(b)
def readsettings(filename):
with open(filename, 'r') as f:
settings = json.loads(f.read())
f.close()
if type(settings) != dict:
settings = {}
if 'files' not in settings:
settings['files'] = {}
if 'hotkeys' not in settings:
settings['hotkeys'] = {}
return settings
def writesettings(settings, filename):
if type(settings) != dict:
settings = {}
if 'files' not in settings:
settings['files'] = {}
if 'hotkeys' not in settings:
settings['hotkeys'] = {}
with open(filename, 'w') as f:
f.write(json.dumps(settings))
f.close()
def abort_error(message):
prompt = "press ENTER to exit."
print(message)
print('-' * (max(len(prompt), len(message)) + 1))
print(prompt)
input()
exit()
def leftallignindex(textlen=0, maxx=80, minx=0):
return minx
def rightallignindex(textlen=0, maxx=80, minx=0):
return max(maxx - textlen, minx)
def centerallignindex(textlen=0, maxx=80, minx=0):
return max(((maxx - minx) // 2 + minx) - textlen // 2, minx)
def columnallignindex(i=0, n=2, maxx=80):
if i < 0 or i >= n:
return 0
return i * (maxx // n)