Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quotes parsing in startmenu.source #297

Open
savchenko opened this issue Dec 29, 2024 · 3 comments
Open

Quotes parsing in startmenu.source #297

savchenko opened this issue Dec 29, 2024 · 3 comments

Comments

@savchenko
Copy link
Contributor

Debian testing (13)
sfwbar 1.0~beta13-1+b2

Looks like an escaping issue (?), stdout:

16:54:57.56 python3 << END
import string, sys, fileinput, getopt, os, glob

def main():
  # Use categories from XDG spec
  catmap = {
  'Development': 'Development',
  'Education': 'Education',
  'Game': 'Games',
  'Graphics': 'Graphics',
  'Internet': 'Internet',
  'Settings': 'Settings',
  'Screensaver': 'Settings',
  'System': 'System',
  'Emulator': 'System',
  'Network': 'Internet',
  'AudioVideo': 'Multimedia',
  'Audio': 'Multimedia',
  'Video': 'Multimedia',
  'Utility': 'Accessories',
  'Accessibility': 'Accessories',
  'Core': 'Accessories',
  'Office': 'Office'}

  cats = list()
  outp = list()
  print ('MenuClear(\'Menugen_Applications\')')
  dirlist = os.environ.get('XDG_DATA_DIRS')
  if not dirlist:
    dirlist = '/usr/share'
  dhome = os.environ.get('XDG_DATA_HOME')
  if not dhome:
    dhome = os.environ.get('HOME')
    if dhome:
      dhome = dhome + '/.local/share'
  if dhome:
    dirlist = dirlist + ':' + dhome
  dlist = []
  for dir in dirlist.split(':'):
    dlist = dlist + sorted(glob.glob(dir + '/applications/*.desktop'))
  for dfile in dlist:
    de_name = de_icon = de_exec = de_cat = de_disp = ''
    fchan = open(dfile)
    for dline in fchan.readlines():
      try:
        (tag, value) = dline.strip().split('=',1)
        if tag.strip() == 'Name' and not de_name: # Grab first name
          de_name = value.strip()
        if tag.strip() == 'Icon':
          de_icon = value.strip()
        if tag.strip() == 'Exec':
          de_exec = value.strip()
        if tag.strip() == 'Categories':
          de_cat = value.strip()
        if tag.strip() == 'NoDisplay':
          de_disp = value.strip()
      except:
        pass
    fchan.close()
    if (de_name != '') and (de_exec != '') and (de_disp.lower() != 'true'):
      de_cat = map_category ( catmap, de_cat )
      de_exec = de_exec.replace(' %f','').replace(' %F','').replace(' %u','')
      de_exec = de_exec.replace(' %U','').replace(' %c',' '+de_name)
      de_exec = de_exec.replace(' %k',' '+dfile).replace(' %i',' '+de_icon)
      if not (de_cat in cats):
        cats.append(de_cat)
        print ('MenuClear(\'Menugen_' + de_cat + '\')')
        sub_icon = '%applications-' + de_cat.lower()
        if (de_cat.lower() == 'settings'): # these is no applications-settings icon
            sub_icon = '%preferences-system'
        outp.append('Menu(\'Menugen_Applications\') { SubMenu(\'' + de_cat +
        sub_icon + '\',\'Menugen_' + de_cat + '\') }')
      outp.append('Menu(\'Menugen_' + de_cat + '\') { Item(\'' + de_name + '%' +
      de_icon + '\',Exec \'' + de_exec +'\') }')
  for token in sorted(outp):
    print(token)

def map_category ( catmap, catlist ):
  for cat in catlist.strip().split(';'):
    try:
      mycat = catmap[cat]
    except LookupError:
      mycat = ''
    if mycat != '':
      return mycat
  return 'Other'

if __name__ == '__main__':
  main()
END:37: missing ')' after 'item'
@LBCrion
Copy link
Owner

LBCrion commented Dec 29, 2024 via email

@savchenko
Copy link
Contributor Author

Think I know why it's not updated in testing: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1091451

Do you plan to tag stable/release version in Q1 2025?

@LBCrion
Copy link
Owner

LBCrion commented Dec 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants