Ticket #272: load_desktop_menus - use ConfigParser.patch
File load_desktop_menus - use ConfigParser.patch, 3.8 KB (added by , 9 years ago) |
---|
-
winswitch/util/load_desktop_menus.py
7 7 import os.path 8 8 import hashlib 9 9 import re 10 import ConfigParser 11 10 12 from winswitch.util.which import which 11 13 12 14 from winswitch.util.simple_logger import Logger, msig … … 17 19 debug_import("common") 18 20 from winswitch.util.common import csv_list, visible_command, load_binary_file, is_valid_file, delete_if_exists 19 21 debug_import("file_io") 20 from winswitch.util.file_io import get_menu_dir, get_xsessions_dir, get_actions_dir, load_properties,save_properties22 from winswitch.util.file_io import get_menu_dir, get_xsessions_dir, get_actions_dir, save_properties 21 23 debug_import("paths") 22 24 from winswitch.util.paths import XSESSION_DIRS, WINSWITCH_COMMAND_WRAPPER, PREFIX_SEARCH_ORDER 23 25 debug_import("consts") … … 361 363 sig = msig(menu_dir, filename, req_cmd, ignored_commands, whitelist_commands, ignored_in, skipped, disabled_categories, file_type) 362 364 short_sig = msig(menu_dir, filename, req_cmd, "[..]", "[..]") 363 365 full_path = os.path.join(menu_dir, filename) 364 desktop_info = load_properties(full_path, False)365 if not desktop_info :366 desktop_info = ConfigParser.ConfigParser() 367 if not desktop_info.read(full_path): 366 368 logger.debug(short_sig+" failed to load '%s'" % full_path) 367 369 return None 368 370 369 371 enabled = True 370 no_display = desktop_info.get('NoDisplay') 371 if no_display and (no_display == "true" or no_display == "1"): 372 enabled = False 373 374 only_show_in = desktop_info.get('OnlyShowIn') 375 if only_show_in and len(only_show_in)>0: 376 shown_in = only_show_in.split(";") 377 ignored = True 378 for shown in shown_in: 379 if len(shown)>0 and shown not in ignored_in: 380 ignored = False 381 break 382 if ignored: 372 try: 373 no_display = desktop_info.get('Desktop Entry', 'NoDisplay') 374 if no_display and (no_display == "true" or no_display == "1"): 383 375 enabled = False 376 except ConfigParser.NoOptionError: 377 pass 384 378 385 name = desktop_info.get('Name') 379 try: 380 only_show_in = desktop_info.get('Desktop Entry', 'OnlyShowIn') 381 if only_show_in and len(only_show_in)>0: 382 shown_in = only_show_in.split(";") 383 ignored = True 384 for shown in shown_in: 385 if len(shown)>0 and shown not in ignored_in: 386 ignored = False 387 break 388 if ignored: 389 enabled = False 390 except ConfigParser.NoOptionError: 391 pass 392 393 try: 394 name = desktop_info.get('Desktop Entry', 'Name') 395 except ConfigParser.NoOptionError: 396 name = None 397 386 398 if not name or len(name)==0: 387 399 logger.debug(sig+" name is missing!") 388 400 return None 389 cmd = desktop_info.get('Exec') 401 402 try: 403 cmd = desktop_info.get('Desktop Entry', 'Exec') 404 except ConfigParser.NoOptionError: 405 cmd = None 406 390 407 if req_cmd and (not cmd or len(cmd)==0): 391 408 return None 392 409 … … 426 443 skipped.append(name) 427 444 enabled = False 428 445 429 comment = desktop_info.get('Comment') 430 icon_filename = desktop_info.get('Icon') 431 categories_list = desktop_info.get('Categories') 446 try: 447 comment = desktop_info.get('Desktop Entry', 'Comment') 448 except ConfigParser.NoOptionError: 449 comment = None 450 451 try: 452 icon_filename = desktop_info.get('Desktop Entry', 'Icon') 453 except ConfigParser.NoOptionError: 454 icon_filename = None 455 456 try: 457 categories_list = desktop_info.get('Desktop Entry', 'Categories') 458 except ConfigParser.NoOptionError: 459 categories_list = None 460 432 461 categories = [] 433 462 uses_sound_out = matches_any(noparams, DEFAULT_SOUNDOUT_ENABLED_COMMANDS) is not None 434 463 uses_sound_in = matches_any(noparams, DEFAULT_SOUNDIN_ENABLED_COMMANDS) is not None … … 456 485 457 486 names = {} 458 487 comments = {} 459 for key,value in desktop_info.items( ):488 for key,value in desktop_info.items('Desktop Entry'): 460 489 _NAMEKEY='Name[' 461 490 _COMMENTKEY="Comment[" 462 491 _ENDKEY="]"