Advertisement
FranzVuttke

inxiinfogatter.py

Jul 31st, 2024 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | Source Code | 0 0
  1. #!/home/ounis/pyapps/bin/python
  2.  
  3. # pastebin: https://pastebin.com/jynp5sBE
  4.  
  5. #
  6. # created by OuNiS 07.2024
  7. #
  8.  
  9. TEMP_FILE="inxi-v8azy~"
  10. #BATT_CAPTION="Battery:"
  11.  
  12. import os
  13. import sys
  14. import re
  15. import tqdm
  16.  
  17. def genTempFile(aFileName):
  18.     print("Preparing data...")
  19.     os.system(f'sudo inxi -v8azy > {aFileName}')
  20.     return aFileName
  21.  
  22. def getInfo(aCaptionName):
  23.     print("Please wait while extracting data...")
  24.     aFile = TEMP_FILE
  25.     if not os.path.isfile(f'./{TEMP_FILE}'):
  26.         aFile = genTempFile(TEMP_FILE)
  27.    
  28.     # os.system(f"sudo inxi -v8azy > {TEMP_FE}")
  29.     with open(aFile) as file:
  30.         can_print = False
  31.         for line in file:
  32.             if line.lower().startswith(aCaptionName.lower()):
  33.                 print(line, end="")
  34.                 can_print = True
  35.                 continue
  36.             if can_print and not line[0].isalnum():
  37.                 print(line, end="")
  38.  
  39.             if can_print and not line.startswith("  "):
  40.                 break
  41.     ...
  42.  
  43.  
  44. def extractSections(aFileName):
  45.     result = ()
  46.     lineSectF = re.compile(r'^[a-zA-Z]+\:')
  47.     with open(aFileName) as file:
  48.         for line in file:
  49.             if flc := lineSectF.search(line):
  50.                 result += (flc.group(), )
  51.     return result
  52.     ...
  53.  
  54.  
  55. def main(args):
  56.     # test tqdm
  57.     # for i in tqdm.trange(1000):
  58.     #     pass
  59.     # print(extractSections("./inxi-v8azy~"))
  60.     if len(args) > 1:
  61.         getInfo(args[1])
  62.     else:
  63.         print("Available sections:\n--------------------")
  64.         for sect in extractSections(TEMP_FILE):
  65.             print(sect, end=" ")
  66.         print()
  67.         selSect = input("Select: ")
  68.         getInfo(selSect)
  69.         # print("ERR: lack of parameter caption name (eg. Battery, Memory)")
  70.     ...
  71.  
  72. if __name__ == "__main__":
  73.     sys.exit(main(sys.argv))
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement