sysinfo.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #Sysinfo.py - Get info about computer and OS
  2. #Only works if you run this program on Linux since this program calls a bash script
  3. #This code has only been tested on Ubuntu 20.04 LTS and may not work on any other distros of Linux
  4. #Import all required libraries/modules
  5. import subprocess as sp
  6. import platform
  7. import os
  8. import sys
  9. import time
  10. #Create timer to get execution time
  11. start = time.time()
  12. #Ask user if they have the Linux command line tool figlet installed
  13. figlet_install = input("Do you have figlet installed on your linux terminal (Y/N)? ")
  14. #If they already have it installed, don't do anything and move on to the next part in the code
  15. if figlet_install.upper() == "Y":
  16. pass
  17. #If user does not have figlet installed, in the background the program runs the Linux command for installing figlet
  18. elif figlet_install.upper() == "N":
  19. print("Installing figlet...")
  20. os.system("sudo apt-get install figlet")
  21. #If user doesn't enter y or n, throw an error exiting the program
  22. elif figlet_install.upper() != "Y" and "N":
  23. sys.exit("Invalid input. Your input must either be Y or N (uppercase is not mandatory).")
  24. #Run figlet and get the name of the user's computer
  25. os.system("figlet %s" %(platform.node()))
  26. #Execute bash script sysinfo.sh
  27. sp.call("/mnt/e/bash/welcomewagon.sh")
  28. #End timer for finding execution time of program
  29. end = time.time()
  30. #Display execution time - Important: Sometimes the execution time might be a bit big but that would be because the user takes long to enter input
  31. print("Program execution time: %s seconds" %(end - start))