Small fixes, still need to change the right config file

parent 0c1222eb
......@@ -13,21 +13,24 @@ def find_desktop(name):
name = '{}.desktop'.format(name)
if os.path.exists(name):
return name
output = subprocess.run(['locate', name], stdout=subprocess.PIPE).stdout.decode()
return output.replace("\n", "")
output = subprocess.run(['find', '/usr/share', '-name', name], stdout=subprocess.PIPE).stdout.decode()
return output.split("\n")[0]
def parse_desktop(desktop):
out = {}
with open(desktop) as f:
text = "\n".join(f.readlines())
p = re.compile(r'((Exec|Icon|Name\[fr\]|GenericName\[fr\]).*)')
p = re.compile(r'((Exec|Icon|Name=|Name\[fr\]|GenericName\[fr\]).*)')
matches = p.findall(text)
return {k: m.split("=")[1] for m, k in matches}
def add_to_handymenu(user, cmd, category):
path = '/home/{}/.config/handymenu/conf.default.yml'.format(user)
# TODO : change path
path = '/home/{}/.config/handymenu/conf.default.yaml'.format(user)
subprocess.run(['sed', '-i', '-e', 's/!!python\/str//g', path])
print(path)
with open(path) as stream:
try:
yml = yaml.safe_load(stream)
......@@ -65,12 +68,20 @@ if __name__ == '__main__':
desktop = find_desktop(args.app[0])
values = parse_desktop(desktop)
cmd = {
'cmd': values['Exec'],
'generic': values['GenericName[fr]'],
'name': values['Name[fr]'],
'icon': values['Icon'],
}
links = {
'Exec' : 'cmd',
'GenericName': 'generic',
'GenericName[fr]': 'generic',
'Name[fr]': 'name',
'Name': 'name',
'Icon': 'icon',
}
cmd = {}
for k,v in links.items():
try:
cmd[v] = values[k]
except KeyError:
pass
for user in args.users:
add_to_handymenu(user, cmd, args.category[0])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment