-
Notifications
You must be signed in to change notification settings - Fork 1
/
esf.py
120 lines (114 loc) · 4.08 KB
/
esf.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# ______ _____ ______
# / ____// ___/ / ____/
# / __/ \__ \ / /_
# / /___ ___/ // __/
# /_____/ /____//_/
# The easiest way to save arrays on a file, saved on a .ESF format (;
import os
import engine
class EasySaveFunctions:
def __init__(self, filepath, name):
self.file_path_ = filepath
self.name_ = name
self.directory_ = os.path.join(self.file_path_, self.name_)
if not os.path.exists(self.file_path_):
os.makedirs(self.file_path_)
try:
f = open(self.directory_, 'r')
string = f.read()
f.close()
except FileNotFoundError:
f = open(self.directory_, 'w')
f.close()
def append(self, payload):
if check_format(self.directory_) == 'True':
if not os.path.exists(self.directory_):
f = open(self.directory_, 'w')
f.close()
else:
f = open(self.directory_, 'r')
string = f.read()
tmp = engine.decode(string)
f.close()
f = open(self.directory_, 'w')
tmp.append(payload)
f.write(engine.encode(tmp))
f.close()
def replace(self, item, payload):
if check_format(self.directory_) == 'True':
if not os.path.exists(self.directory_):
os.makedirs(self.directory_)
f = open(self.directory_, 'w')
f.close()
else:
f = open(self.directory_, 'r')
string = f.read()
f.close()
f = open(self.directory_, 'w')
tmp = engine.decode(string)
tmp.pop(item)
tmp.insert(item, payload)
f.write(engine.encode(tmp))
f.close()
def pop(self, item):
if check_format(self.directory_) == 'True':
if not os.path.exists(self.directory_):
os.makedirs(self.directory_)
f = open(self.directory_, 'w')
f.close()
else:
f = open(self.directory_, 'r')
string = f.read()
tmp = engine.decode(string)
tmp.pop(item)
f.close()
f = open(self.directory_, 'w')
f.write(engine.encode(tmp))
f.close()
def index(self, index):
if check_format(self.directory_) == 'True':
if not os.path.exists(self.directory_):
os.makedirs(self.directory_)
f = open(self.directory_, 'w')
f.close()
else:
f = open(self.directory_, 'r')
string = f.read()
tmp = engine.decode(string)
return tmp.index(index)
def delete(self):
if check_format(self.directory_) == 'True':
if not os.path.exists(self.directory_):
os.makedirs(self.directory_)
f = open(self.directory_, 'w')
f.close()
else:
os.remove(self.directory_)
def get_list(self):
if check_format(self.directory_) == 'True':
if not os.path.exists(self.directory_):
os.makedirs(self.directory_)
f = open(self.directory_, 'w')
f.close()
else:
f = open(self.directory_, "r")
string = f.read()
return engine.decode(string)
f.close()
def upload_list(self, list):
if check_format(self.directory_) == 'True':
if not os.path.exists(self.directory_):
os.makedirs(self.directory_)
f = open(self.directory_, 'w')
f.close()
else:
f = open(self.directory_, 'w')
f.write(engine.encode(list))
f.close()
def check_format(x):
e = x[len(x) - 3] + x[len(x) - 2] + x[len(x) - 1]
if e == 'esf':
return('True')
else:
return('False')
print('Not ESF FILE!')