Advertisement
delvin-fil

IceWM menu

Apr 24th, 2017
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #!/usr/bin/env python3.6
  2. # -*- coding: utf-8 -*-
  3. import re
  4. import os
  5. import glob
  6. import sys
  7.  
  8. directory = '/usr/share/applications/'
  9.  
  10. with open('menu.test', 'w') as f_cl:
  11.     clear = 'menu "TEST" - {\n'
  12.     f_cl.write(clear)
  13.  
  14. def parse_file():
  15.     for f in glob.glob(f'{directory}*.desktop'):
  16.         with open(f, 'r', encoding="utf-8") as f_in,  open('menu.test', 'a') as f_out:
  17.             found = str(f_in.read())
  18.             Name = re.findall('\nName=(.*\w+)', found)
  19.             Icon = re.findall('\nIcon=(.*\w+)', found)
  20.             Exec = re.findall('\nExec=(.*\w+)', found)
  21.             menu = (f'prog "{str(Name)}" {Icon} {Exec}')
  22.             menu = re.sub(r'\[|\(|\'|\]|\)|\,|\\', '', str(menu))
  23.             print(menu)
  24.             f_out.write(f'{menu}\n')
  25.  
  26. def out_file():
  27.     with open('menu.test', 'a') as f_fn:
  28.         clear = '}\n'
  29.         f_fn.write(clear)        
  30. #print (len(files))
  31. if __name__ == '__main__':
  32.     parse_file()
  33.     out_file()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement