Comm4nd0

Untitled

Apr 8th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import os
  4. import time
  5. import sys
  6. import subprocess
  7. import getpass
  8. import pexpect
  9.  
  10. def print_menu():
  11.     print("""
  12.       _____                                        _______        _        
  13.      / ____|                                      |__   __|      | |        
  14.     | |     ___  _ __ ___  _ __ ___   ___  _ __      | | __ _ ___| | _____  
  15.     | |    / _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \    | |/ _` / __| |/ / __|
  16.     | |___| (_) | | | | | | | | | | | (_) | | | |    | | (_| \__ \  <\__ \
  17.      \_____\___/|_| |_| |_|_| |_| |_|\___/|_| |_|    |_|\__,_|___/_|\_\___/
  18.                                                                            
  19.                                                                            
  20.    [0] - Restart Network-Manager
  21.    [1] - Start PyCharm
  22.    [99]- Exit
  23.    """)
  24.  
  25. def restart_nm():
  26.     pswd = getpass.getpass('sudo password:')
  27.     child = pexpect.spawn('sudo systemctl restart network-manager.service')
  28.     child.expect(':')
  29.     child.sendline(pswd)
  30.     child.interact()
  31.  
  32. def pycharm():
  33.     file_path = '{}/software/pycharm-community-2017.3.3/bin/pycharm.sh'.format(os.getcwd())
  34.     subprocess.Popen(['bash', file_path, '&'])
  35.  
  36. def main():
  37.     while True:
  38.         os.system('clear')
  39.         print_menu()
  40.         option = input("Selection: ")
  41.  
  42.         try:
  43.             option = int(option)
  44.             return option
  45.         except:
  46.             print("Not a valid option")
  47.             time.sleep(2)
  48.  
  49. if __name__ == '__main__':
  50.     while True:
  51.         option = main()
  52.         if option == 99:
  53.             sys.exit()
  54.         elif option == 0:
  55.             restart_nm()
  56.         elif option == 1:
  57.             pycharm()
Advertisement
Add Comment
Please, Sign In to add comment