示例#1
0
 def __init__(self):
     if PATH_search('x-terminal-emulator'):
         terminal = 'x-terminal-emulator'
     else:
         terminal = 'xterm'
     self.default = {'terminal': terminal,
                     'systray': 'true',
                     'rounded': '4',
                     'menu_width': '430',
                     'bg_color': '#DCDCDC',
                     'border_color': '#4D4D4D',
                     'hide_list': 'None',
                     'category_click': 'true',
                     'favorites': 'false',
                     'desktop_dirs': ["/usr/share/applications/",
                                     "%s/.local/share/applications/"
                                     % os.getenv('HOME'),
                                     "/usr/local/share/applications/",
                                     "/usr/share/applications/kde4/",
                                     "/usr/local/share/applications/kde4/"
                                     ]
                     }
     config = {}
     try:
         f = open(CONFIG_FILE, 'r')
         logINFO("Found user config.")
         for line in f:
             if line == '\n' or line.startswith('#'):
                 continue
             else:
                 line = line.strip('\n ').split('=')
                 if line[0] == "desktop_dirs":
                     config["desktop_dirs"] = filter( None, 
                                   map ( lambda ln: expanduser( expandvars ( ln.lstrip().rstrip() ) ),
                                        line[1].split(",") ) 
                                  )
                 else:
                     config[line[0]] = line[1]
         f.close()
     except IOError,e:
         printERROR(u"I/O error: %s" % repr(e))
示例#2
0
 def validateConfig(self):
     for line in self.config:
         if line not in self.default:
             printERROR( u"Error in config file: Unknown parameter (\"{0}\")".format(line))
             continue
         if self.config[line] == '':
             printERROR(u"Error in config file: parameter \"{0}\" can't be empty. Using default value.".format(line))
             self.config[line] = self.default[line]
         if line == 'rounded' or line == 'menu_width':
             if not self.isValidInt(self.config[line]):
                 printERROR( u"Error in config file: parameter \"{0}\" must be valid integer. Using default value.".format(line))
                 self.config[line] = self.default[line]
             if int(self.config[line]) < 0:
                 printERROR(u"Error in config file: parameter \"{0}\" must be positive value. Using default value.".format(line))
                 self.config[line] = self.default[line]
示例#3
0
def parse_user_menu(config):
    logINFO('Parse user menu ..')
    cfg_file = USERMENU
    cat_index = None
    if os.access(cfg_file, os.F_OK | os.R_OK):
        logINFO('Found user menu ..')
        f = open(cfg_file, 'r')
        for line in f:
            try:
                if line == '\n' or line.startswith('#'):
                    continue
                elif line.startswith('@'):
                    if line.count("##") > 0:
                        cat = line[1:].strip('\n ').split("##")
                        config[cat[0]] = []
                        cat_icon[cat[0]] = expanduser( expandvars ( cat[1] ) )
                        cat_index = cat[0]
                    else:
                        printERROR(u"# Error reading line: %s, not enough parameters"
                              u" (must be at least 2)" % line)
                else:
                    if line.count("##") > 2:
                        if cat_index is not None:
                            #Parameters:#[0]CMD#[1]Icon#[2]Name#[3]--/--#[4]Desc
                            cmd_line = line.strip('\n\t ').split('##') 
                            cmd_line[0] = expanduser( expandvars ( cmd_line[0] ) )
                            cmd_line[1] = expanduser( expandvars ( cmd_line[1] ) )
                            cmd_line.insert(3, "")
                            cmd_line[0] = parse_cmd(cmd_line[0], "", cmd_line[1], cmd_line[2])
                            config[cat_index].append(cmd_line)
                        else:
                            printERROR( u"# Error reading line: %s, not enough parameters"
                                  u" (must be at least 3)" % line)
                    else:
                        printERROR( u"# Error reading line: %s, not enough parameters"
                              u" (must be at least 3)" % line)
            except:
                logINFO("# Error in user config menu at line: %s" % line)
                logTRACEBACK()
        f.close()
    return config