Skip to content

Commit

Permalink
hotfix/GADEV-86:replace multi ifs to if dict
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jan 21, 2024
1 parent 145a0ff commit 053e9ef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
35 changes: 5 additions & 30 deletions menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from os import system, remove, path
from categorias import categorias
from instalacao import instalacao_de_pacotes
from menu_subfunctions import *
import distro

def banner():
Expand All @@ -19,8 +20,6 @@ def banner():
''')


def clear():
system('clear')

# configuração do gerenciador de pacotes referente a distribuição linux
def exibicao_de_categorias():
Expand Down Expand Up @@ -87,7 +86,7 @@ def menu():
opcao_escolhida = inquirer.prompt(inquirer_lista_incial)['lista_inicial']
clear()

while opcao_escolhida == 1:
while opcao_escolhida == 1 and escolha_repositorios != 5:
banner()
inquirer_lista_repositorio = [
inquirer.List(
Expand All @@ -105,35 +104,11 @@ def menu():
]
escolha_repositorios = inquirer.prompt(inquirer_lista_repositorio)['lista_repositorio']

if escolha_repositorios == 1:
chave_apt = system("apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ED444FF07D8D0BF6")
repositorio_adicionado = system("echo '# Repositórios Kali Linux\ndeb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware' >> /etc/apt/sources.list.d/infosectools.list")
clear()
elif escolha_repositorios == 2:
atualizacao_de_sistema = system("apt-get update -m")
clear()
elif escolha_repositorios == 3:
source_list = "/etc/apt/sources.list.d/infosectools.list"
if path.exists(source_list):
clear()
remove(source_list)
print("\033[1;31m\nRepositório infosectools.list removido!\n\033[1;m")
else:
clear()
print("\033[1;31m\nRepositório infosectools.list já foi removido!\n\033[1;m")

elif escolha_repositorios == 4:
try:
clear()
arquivo = open('/etc/apt/sources.list.d/infosectools.list', 'r')
print(arquivo.read())
except FileNotFoundError as error:
print('\033[1;31m\nRepositório infosectools.list não existe!\n\033[1;m')
elif escolha_repositorios == 5:
clear()
break
if escolha_repositorios in dict_choices_infosectools_list:
dict_choices_infosectools_list[escolha_repositorios]()
else:
print("\033[1;31mDesculpe, esse foi um comando inválido!\033[1;m")

if opcao_escolhida == 2:
clear()
exibicao_de_categorias()
Expand Down
40 changes: 40 additions & 0 deletions menu_subfunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from os import system, remove, path

def clear():
system('clear')

def add_repo_to_infosectools_list():
system("apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ED444FF07D8D0BF6")
system("echo '# Repositórios Kali Linux\ndeb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware' >> /etc/apt/sources.list.d/infosectools.list")
clear()

def update_repo_list():
system("apt-get update -m")
clear()

def remove_infosectool_list():
source_list = "/etc/apt/sources.list.d/infosectools.list"
if path.exists(source_list):
clear()
remove(source_list)
print("\033[1;31m\nRepositório infosectools.list removido!\n\033[1;m")
else:
clear()
print("\033[1;31m\nRepositório infosectools.list já foi removido!\n\033[1;m")

def get_infosectool_list():
try:
clear()
with open('/etc/apt/sources.list.d/infosectools.list', mode='r', encoding='utf-8') as file:
print(file.read())
except FileNotFoundError as error:
print('\033[1;31m\nRepositório infosectools.list não existe!\n\033[1;m')

def return_menu():
clear()

dict_choices_infosectools_list = {1:add_repo_to_infosectools_list,
2:update_repo_list,
3:remove_infosectool_list,
4:get_infosectool_list,
5: clear}

0 comments on commit 053e9ef

Please sign in to comment.