Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import os
  2.  
  3.  
  4. def check_file(dir):
  5.     files = os.listdir(os.getcwd() + '/' + dir)
  6.  
  7.     configs = []
  8.  
  9.     for file in files:
  10.         if dir != file.split('.txt')[0]:
  11.             configs.append(file.split('.txt')[0])
  12.  
  13.     return configs
  14.  
  15.  
  16. def config_file(data, domain):
  17.     data = data.replace('%domain%', domain)
  18.  
  19.     new_file = open(domain + '.conf', 'w')
  20.     new_file.write(data)
  21.     new_file.close()
  22.  
  23.  
  24. def read_file(server, type):
  25.     f = open(os.getcwd() + '/' + type + '/'+ server + '.txt', 'r')
  26.     data = f.read()
  27.     f.close()
  28.  
  29.     return data
  30.  
  31.  
  32. if __name__ == '__main__':
  33.  
  34.     server = input('Выберите сервер: 1 Apache, 2 Nginx: ')
  35.     domain = input('Введите домен сайта: ')
  36.  
  37.     if int(server) == 1:
  38.         if len(check_file('apache')) == 0:
  39.             config_file(read_file('apache', 'apache'), domain)
  40.         else:
  41.             configs = input('У нас есть несколько кофигов на Apache Выберите, пожалуйста: '+','.join(check_file('apache')))
  42.             config_file(read_file(configs, 'apache'), domain)
  43.  
  44.     else:
  45.         if len(check_file('nginx')) == 0:
  46.             config_file(read_file('nginx', 'nginx'), domain)
  47.         else:
  48.             configs = input('У нас есть несколько кофигов на Nginx Выберите, пожалуйста: '+','.join(check_file('nginx'))+' ')
  49.             config_file(read_file(configs, 'nginx'), domain)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement