Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3.6
- # -*- coding: utf-8 -*-
- import re
- import os
- import glob
- import sys
- directory = '/usr/share/applications/'
- with open('menu.test', 'w') as f_cl:
- clear = 'menu "TEST" - {\n'
- f_cl.write(clear)
- def parse_file():
- for f in glob.glob(f'{directory}*.desktop'):
- with open(f, 'r', encoding="utf-8") as f_in, open('menu.test', 'a') as f_out:
- found = str(f_in.read())
- Name = re.findall('\nName=(.*\w+)', found)
- Icon = re.findall('\nIcon=(.*\w+)', found)
- Exec = re.findall('\nExec=(.*\w+)', found)
- menu = (f'prog "{str(Name)}" {Icon} {Exec}')
- menu = re.sub(r'\[|\(|\'|\]|\)|\,|\\', '', str(menu))
- print(menu)
- f_out.write(f'{menu}\n')
- def out_file():
- with open('menu.test', 'a') as f_fn:
- clear = '}\n'
- f_fn.write(clear)
- #print (len(files))
- if __name__ == '__main__':
- parse_file()
- out_file()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement