Gorcupt

3-1

Mar 28th, 2022
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. import os
  2. import time
  3. import shutil
  4. from termcolor import cprint, colored
  5.  
  6. _help = False
  7.  
  8.  
  9. def main():
  10. cprint('Введите help - для получения справки\n')
  11. db = loadPass()
  12. flagAuth = False
  13. while True:
  14. inp = input()
  15. x = inp.split()
  16. cprint('Введите help - для получения справки\n')
  17. print(inp, '\n')
  18. if x[0] == 'help':
  19. help_m()
  20. elif x[0] == 'auth':
  21. flagAuth = auth_m(db, x)
  22. elif x[0] == 'exit':
  23. cprint('До свидания!\n')
  24. break
  25. elif checkAuth(flagAuth):
  26. if x[0] == 'list':
  27. list_m()
  28. elif x[0] == 'info':
  29. info_m(x)
  30. elif x[0] == 'retr':
  31. retr_m(x)
  32. else:
  33. cprint('Ошибка: Неизвестная команда\n')
  34.  
  35.  
  36. def checkAuth(flag):
  37. if flag:
  38. return True
  39. else:
  40. if _help:
  41. help_m()
  42. cprint('Ошибка: Сначала авторизуйтесь\n', 'red')
  43. return False
  44.  
  45.  
  46. def help_m():
  47. global _help
  48. _help = True
  49. cprint('auth user pass - авторизоваться, user - логин, pass - пароль', 'yellow')
  50. cprint('list — показать список файлов в каталоге запуска программы', 'yellow')
  51. cprint('info file — напечатать сведения о файле, тип, размер, время создания', 'yellow')
  52. cprint('retr file1 file2 file_n — передать файлы, указанные в строке.', 'yellow')
  53. cprint('exit — выход\n', 'yellow')
  54.  
  55.  
  56. def retr_m(x):
  57. if not _help:
  58. help_m()
  59. if len(x) == 1:
  60. cprint('Ошибка: Введите файл(ы)\n', 'red')
  61. return
  62. for i in range(1, len(x)):
  63. shutil.copy(x[i], 'C:\\Users\\dotav\\Desktop\\task3-1\\CopyFolder')
  64. print(colored(x[i], 'white'), colored('скопирован', 'white'))
  65. cprint('Копирование закончено\n', 'blue')
  66.  
  67.  
  68. def info_m(x):
  69. if not _help:
  70. help_m()
  71. if len(x) == 1:
  72. cprint('Ошибка: Введите файл\n', 'red')
  73. return
  74. if os.path.exists(x[1]):
  75. print(colored('файл:', 'white'), colored(x[1], 'white'))
  76. print(colored('тип:', 'white'), colored(x[1].split('.')[1], 'white'))
  77. print(colored('размер:', 'white'), colored(os.path.getsize(x[1]), 'white'), colored('bytes', 'white'))
  78. print(colored('дата создания:', 'white'), colored(time.ctime(os.path.getctime(x[1])), 'white'))
  79. print()
  80. else:
  81. cprint('Ошибка: Файл не существует!\n', 'red')
  82.  
  83.  
  84. def list_m():
  85. if not _help:
  86. help_m()
  87. for file in os.listdir('.'):
  88. if os.path.isfile(os.path.join('.', file)):
  89. print(file)
  90. print()
  91.  
  92.  
  93. def auth_m(db, x):
  94. global _help
  95. if not _help:
  96. help_m()
  97. if len(x) < 3:
  98. cprint('Ошибка: Введите логин и пароль\n', 'red')
  99. return
  100. flagAuth = False
  101. for user in db:
  102. if user == x[1]:
  103. if db.get(user) == x[2]:
  104. cprint('Авторизация прошла успешно\n', 'blue')
  105. flagAuth = True
  106. break
  107. else:
  108. cprint('Ошибка: Неверный логин или пароль\n', 'red')
  109. return flagAuth
  110.  
  111.  
  112. def loadPass():
  113. db = {}
  114. with open("pass.txt") as file:
  115. for line in file:
  116. key, value = line.split()
  117. db[key] = value
  118. return db
  119.  
  120.  
  121. main()
  122.  
Advertisement
Add Comment
Please, Sign In to add comment