Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. def Edita(user, id, idgroup, nome, home, shell):
  2.  
  3. while(True):
  4. user_id = input("Digite o ID do usuario: ")
  5. if(user_id in id):
  6. aux = id.index(user_id)
  7. print("Usuario: ", user[aux], "\nID: ", id[aux], "\nId group: ", idgroup[aux], "\nNome: " ,nome[aux], "\nHome: ", home[aux], "\nShell: ", shell[aux])
  8. user[aux]= input("Novo Usuario: ")
  9. id[aux] = input("Novo Id: ")
  10. idgroup[aux] = input("Novo Id de grupo:")
  11. nome[aux] = input("Novo nome:")
  12. home[aux] = input("Nova home")
  13. shell[aux] = input("Novo Shell")
  14. break
  15. else:
  16. print("Id não encontrado")
  17. def Mostra(user, id, idgroup, nome, home, shell,lines):
  18. c = 0
  19.  
  20. for aux in user:
  21. print("\nUsuario: ", user[c], "\nID: ", id[c], "\nId de grupo: ", idgroup[c], "\nNome: ", nome[c], "\nHome: ", home[c], "\nShell: ", shell[c] )
  22. c += 1
  23.  
  24. def Add(user, id, idgroup, nome, home, shell):
  25. user.append(input("Novo Usuario"))
  26. id.append(input("Novo id"))
  27. idgroup.append(input("Novo id de grupo"))
  28. nome.append(input("Novo nome"))
  29. home.append(input("Nova home "))
  30. shell.append(input("Novo shell"))
  31.  
  32.  
  33.  
  34.  
  35. def Save(user, id, idgroup, nome, home, shell):
  36.  
  37. new_file = open("New_file.txt", "w")
  38. for i in range(0, len(user)):
  39. new_file.write(user[i]+":x:"+id[i]+":"+idgroup[i]+":"+nome[i]+":"+home[i]+":"+shell[i]+"\n")
  40.  
  41.  
  42.  
  43.  
  44.  
  45. arquivo = open('odin.txt', 'r')
  46.  
  47. lines = arquivo.readlines()
  48. arquivo.close()
  49. arquivo = open('odin.txt', 'r')
  50.  
  51. user = []
  52. id = []
  53. idgroup = []
  54. nome = []
  55. home = []
  56. shell = []
  57.  
  58.  
  59.  
  60. for c in range(0, len(lines)):
  61. line = arquivo.readline()
  62. aux = line.split(':')
  63. user.append(aux[0])
  64. id.append(aux[2])
  65. idgroup.append(aux[3])
  66. nome.append(aux[4])
  67. home.append(aux[5])
  68. shell.append(aux[6])
  69.  
  70.  
  71. def Escolha(menssagem):
  72.  
  73. escolha = int(input(menssagem))
  74. return (escolha)
  75.  
  76.  
  77.  
  78. escolha = Escolha("Config PassWD Python\nEscolha uma opção:\n1-Alterar usuário\n2-Mostrar usuários\n3-Adicionar usuário\n4-Salvar e Sair\n5"
  79. "-Sair\n")
  80.  
  81. while(True):
  82. if escolha == 1:
  83. Edita(user, id, idgroup, nome, home, shell)
  84. escolha = 0
  85. elif escolha == 2:
  86. Mostra(user, id, idgroup, nome, home, shell, len(lines))
  87. escolha = 0
  88. elif escolha == 3:
  89. Add(user, id, idgroup, nome, home, shell)
  90. escolha = 0
  91.  
  92. elif escolha == 5:
  93. Save(user, id, idgroup, nome, home, shell)
  94. break
  95. elif escolha == 6:
  96. break
  97. escolha = Escolha("Config PassWD Python\nEscolha uma opção:\n1-Alterar usuário\n2-Mostrar usuários\n3-Adicionar usuário\n5-Salvar e Sair\n6-Sair\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement