-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (39 loc) · 1.81 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
import sys
import os
from GerenciadorArquivo import GerenciadorArquivo
def main():
if len(sys.argv) < 2:
print("Argumentos Insuficientes")
sys.exit()
if not os.path.exists("./dados.dat"):
print("Erro: Arquivo dados.dat não encontrado")
sys.exit()
else:
gerenciador = GerenciadorArquivo('dados.dat')
gerenciador.abrirArquivo()
if len(sys.argv) == 2 and sys.argv[1] == "-p":
gerenciador.imprimirLED()
gerenciador.fecharArquivo()
elif len(sys.argv) == 3 and sys.argv[1] == "-e":
gerenciador.abrirArquivoOperacoes(sys.argv[2])
operacao, dados = gerenciador.lerArquivoOperacoes()
while operacao != "Fim das operações" and dados != "Acabou":
identificador = int(dados[1].split("|")[0])
match (operacao):
case 'b':
print(f"Busca pelo registro de chave \"{identificador}\"")
retornoFuncao = gerenciador.buscarRegistro(identificador)
if retornoFuncao[1] == 0:
print(retornoFuncao[0])
else:
print(f"{retornoFuncao[1]} ({retornoFuncao[3]} bytes)")
print(f"Local: offset = {retornoFuncao[2]} bytes ({hex(retornoFuncao[2])})\n")
case 'i':
gerenciador.inserirRegistro(dados[1])
case 'r':
gerenciador.removerRegistro(identificador)
operacao, dados = gerenciador.lerArquivoOperacoes()
gerenciador.fecharArquivoOperacoes()
gerenciador.fecharArquivo()
if __name__ == '__main__':
main()