-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
408 lines (372 loc) · 11.5 KB
/
main.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
import configparser, os, math, lang
cnf = configparser.ConfigParser()
#term vars
root = False
vrs = {}
#sys vars
ftps = ['other', 'xc', 'mn', 'mni']
tps = ['int', 'str', 'float', 'bool', 'list', 'dict']
utps = ['root', 'default', 'guest']
chrs = ['%n', '%s', '&', '||', '|', '!', '=?', '=>', '<=']
kw = ['@class', '@void', 'constructor', 'if' 'else', 'elseif', 'while', 'for', 'do']
errs = {'MathError': ['DivideByZero', 'FloatFactorial', 'NegativeFactorial'], 'FoundError': ['AppNoFound', 'AttribyteNoFound', 'VoidNoFound', 'ClassNoFound', 'LibNoFound', 'VarNoFound', 'TypeNoFound', 'UserNoFound', 'SystemVarNoFound', 'ErrorNoFound', 'CommandNoFound', 'FileNoFound', 'NoFoundSystemFile'], 'SyntaxError': '', 'ListDictError': ['IndexError', 'NameError', 'ValueError'], 'FormatError': ['IntToStr', 'FloatToStr', 'BoolToStr']}
prcs = {'lg': 'main.py/lg()'}
sh = {'name': '', 'ver': '', 'date': '', 'fs': ''}
cnf.read('mni.tc')
sh['name'] = cnf['sh']['nm']
sh['ver'] = cnf['sh']['ver']
sh['fs'] = cnf['sh']['fs']
cms = cnf['sh']['cms']
#methods for gen
def isfloat(what):
if what.replace('.', '', 1).isdigit():
return True
else:
return False
def spl(what):
return str(what).replace("'", '').replace('[', '').replace(']', '').replace('{', '').replace('}', '').replace('(', '').replace(')', '').replace(',', '')
def ibol(what):
if str(what).lower() == 'true' or str(what).lower() == 'false':
return True
else:
return False
def indot(what):
what = what.replace('"', "'")
if what.startswith("'") and what.endswith("'"):
return True
else:
return False
#main methods
def col(text, col='', eff='', w=''):
cols = {'r': '31', 'g': '32', 'y': '33', 'b': '34', 'v': '35', 'w': '37', 'bl': '30'}
effs = {'b': '1', 'i': '3'}
if text == 'pd':
pd = str(f'\033[31m\033[1mPermission Denied' + '\033[37m\033[0m ').replace('None', '')
if w == 'r':
return pd
else:
print(pd)
elif text == 'pa':
pa = str(f'\033[32m\033[1mPermission Access' + '\033[37m\033[0m ').replace('None', '')
if w == 'r':
return pa
else:
print(pa)
else:
txt = (f'\033[{cols[col]}m\033[{effs[eff]}m{text}\033[37m\033[0m')
if w == 'r':
return txt
else:
print(txt)
def er(nm, dic, w, a, n=''):
if a == 'w':
if nm in errs:
if w == 'p':
if n.strip() == '':
a = col(f'{nm} : {dic}', 'r', 'b', 'r')
else:
a = col(f'{nm}.{n} : {dic}', 'r', 'b', 'r')
print(a)
else:
return a
else:
if w == 'p':
a = col(errs[list(errs)[1]][9], 'r', 'b', 'r')
print(a)
else:
return a
elif a == 'm':
if nm in errs:
print(errs[nm])
else:
er('FoundError', nm, 'p', 'w', 'ErrorNoFound')
def wrt(what):
if what in vrs:
print(spl(vrs[what]).partition(':')[2])
else:
if what == '-sys -ftps':
print(spl(ftps))
elif what == '-sys -tps':
print(spl(tps))
elif what == '-sys -utps':
print(spl(utps))
elif what == '-sys -chrs':
print(spl(chrs))
elif what == '-sys -kw':
print(spl(kw))
elif what == '-sys -errs':
print(spl(errs))
elif what == '-sys -n':
print(sh['name'])
elif what == '-sys -v':
print(sh['ver'])
elif what == '-sys -date':
print(sh['date'])
elif root and what == '-sys -fs':
print(sh['fs'])
elif what == '-sys -cms':
print(spl(cms))
elif what == '-sys -root':
if root:
col('True', 'g', 'b', 'p')
if root == False:
col('False', 'r', 'b', 'p')
elif what == '-sys -vrs':
print(vrs)
elif what == '-sys -fs':
print(sh['fs'])
else:
print(what)
def wrts(what):
a = what.split(' ')
for c in a:
if c in vrs:
v = vrs[c]
if list(v.keys())[0] == 'str':
a[a.index(c)] = c.replace(c, list(v.values())[0])
if list(v.keys())[0] != 'str':
if list(v.keys())[0] == 'int':
er('FormatError', v, 'p', 'w', 'IntToStr')
break
elif list(v.keys())[0] == 'float':
er('FormatError', v, 'p', 'w', 'FloatToStr')
break
v = ' '.join(a)
try:
print(v)
except UnboundLocalError:
col('Print other var, if it not, then use comand wrt (man wrt)', 'r', 'b', 'p')
def usr(ind, what):
cnf.read('usr.tc')
usrn = cnf[ind]['nm']
usrt = cnf[ind]['tp']
usrp = cnf[ind]['ps']
if what == 'n':
return usrn
if what == 'p':
return usrp
if what == 't':
return usrt
def sudo(id, type):
global root
if type == 1:
nm = usr(id, 'n')
p = usr(id, 'p')
_p = input(f'Entry password from {nm}: ')
if root:
print('You a root')
else:
if _p == p:
col('pa', 'p')
root = True
return True
else:
col('pd', 'p')
root = False
return False
if type == 0:
nam = usr(id, 'n')
pas = usr(id, 'p')
_pas = input(f'Entry a password from {nam}: ')
if root:
return ''
else:
if _pas == pas:
root = True
return True
else:
root = False
return False
def lef(nm, vl, what=''):
t = ''
if vl.isdigit():
t = tps[0]
elif isfloat(vl):
t = tps[2]
elif ibol(vl):
t = tps[3]
else:
t = tps[1]
vrs[nm] = {t: vl}
if what == 't':
return t
elif what == 'vl':
return vl
elif what == 'tvl':
return t, vl
elif what == 'n':
return nm
else:
return ''
def tp(what):
if what in vrs:
print(spl(vrs[what]).partition(':')[0].strip())
else:
if what.isdigit():
print(tps[0])
elif isfloat(what):
print(tps[2])
elif ibol(what):
print(tps[3])
elif what.isdigit() == False and isfloat(what) == False and ibol(what) == False:
print(tps[1])
else:
er('FoundError', what, 'p', 'w', 'TypeNoFound')
def ex():
exit()
def ln(what):
if what:
print(f'{what} length : {len(what)}')
def fil(file, action, what=''):
try:
global f
f = open(file, 'r+')
except FileNotFoundError:
er('FoundError', file, 'p', 'w', 'FileNoFound')
if action == '-rd*':
print(f.read())
elif action == '-rdl':
h = f.readlines()
s = str(h[int(what) - 1])
if s.endswith('\n'):
s = s.replace('\n', '')
else:
s = s
print(s)
elif action == '-rdls':
h = f.readlines()
one = int(what.partition('-')[0]) -1
two = int(what.partition('-')[2])
#print(one, two)
s = [i for i in h[one:two]]
for u in s:
if u.endswith('\n'):
u = u.replace('\n', '')
else:
u = u
print(u)
elif action == '-n':
print(os.path.splitext(file)[0])
elif action == '-e':
print(os.path.splitext(file)[1])
def cls():
os.system('clear')
def manual(what):
if what in cms:
cnf.read('help.tc')
base = cnf[what]['base']
main = cnf[what]['1']
print(f'EXAMPLE COMMAND: {base}\n{main}')
def mnt(frm, what, new):
global root
if root:
if frm == '-sys':
if what == '-fs':
sh['fs'] = new
elif what == '-n':
sh['name'] = new
elif what == '-v':
sh['ver'] = new
elif what == '-root':
if new.lower() == 'true':
root = True
else:
root = False
elif what == '-tps':
if new.startswith('-a'):
tps.append(new.replace('-a', '').strip())
elif what == '-utps':
if new.startswith('-a'):
utps.append(new.replace('-a', '').strip())
elif what == '-ftps':
if new.startswith('-a'):
ftps.append(new.replace('-a', '').strip())
else:
er(list(errs)[1], f'{frm} {what}', 'p', 'w', errs[list(errs)[1]][8])
else:
col('pd')
def conv(to, what):
if what in vrs:
if to == 'str':
vrs[what] = {'str': spl(vrs[what]).partition(':')[2].strip()}
elif to == 'int':
vrs[what] = {'int': spl(vrs[what]).partition(':')[2].strip()}
elif to == 'float':
vrs[what] = {'float': spl(vrs[what]).partition(':')[2].strip()}
else:
if to == 'str':
print(str(what))
return str(what)
elif to == 'int':
print(int(what))
return int(what)
elif to == 'float':
print(float(what))
return float(what)
def mah(mod, ex):
a = list(ex)
for i in a:
if i in vrs:
c = vrs[i]
if list(c.keys())[0] == 'int' or list(c.keys())[0] == 'float':
a[a.index(i)] = i.replace(i, list(c.values())[0])
c = ''.join(a)
try:
v = str(eval(compile(c, 'string', 'eval')))
if v.endswith('.0'):
v = v.replace('.0', '')
else:
v = v
if mod == 'fact':
try:
print(math.factorial(int(v)))
except ValueError:
if isfloat(v):
er('MathError', v, 'p', 'w', 'FloatFactorial')
elif v.startswith('-'):
er('MathError', v, 'p', 'w', 'NegativeFactorial')
elif mod == 'def':
print(v)
except ZeroDivisionError:
er('MathError', c, 'p', 'w', 'DivideByZero')
def cut(i1, i2, what):
print(what[int(i1) - 1:int(i2)])
def logs(what):
logs = open('logs.tc', 'a+')
logs.seek(0)
if logs.readline().startswith('#tc/logs'):
logs.write(what + '\n')
else:
er('FoundError', 'logs.tc', 'p', 'w', 'NoFoundSystemFile')
def traim(frm, what):
if frm == '-l':
if what in vrs:
print(spl(str(list(vrs.values())[0])).partition(':')[2].lstrip())
else:
print(what.lstrip())
elif frm == '-r':
if what in vrs:
print(spl(str(list(vrs.values())[0])).partition(':')[2].rstrip())
else:
print(what.rstrip())
elif frm == '-a':
if what in vrs:
print(spl(str(list(vrs.values())[0])).partition(':')[2].strip())
else:
print(what.strip())
else:
er('FoundError', frm, 'p', 'w', errs['FoundError'][1])
def xc(whatst, name, act):
if whatst == '-void':
os.chdir('./funcs/')
info = open(name, 'r')
info.seek(0)
name = info.readline().partition(' = ')[2]
version = info.readline().partition(' = ')[2]
file = info.readline().partition(' = ')[2]
if act == 'st':
if file.endswith('.py'):
os.system(f'python {file}')
elif file.endswith('.tcy'):
lang.lag(file)
os.chdir('..')