[widgets] an option for Select to show sorted content
importsysfromcubicwebimportwarningdeflines(path,comments=None):result=[]forlineinopen(path,'U'):line=line.strip()iflineand(commentsisNoneornotline.startswith(comments)):result.append(line)returnresultdefread_config(config_file):"""read the application configuration from a file and return it as a dictionnary :type config_file: str :param config_file: path to the configuration file :rtype: dict :return: a dictionary with specified values associated to option names """config=current={}try:forlineinlines(config_file,comments='#'):try:option,value=line.split('=',1)exceptValueError:option=line.strip().lower()ifoption[0]=='[':# start a sectionsection=option[1:-1]assertnotconfig.has_key(section), \'Section %s is defined more than once'%sectionconfig[section]=current={}continueprint>>sys.stderr,'ignoring malformed line\n%r'%linecontinueoption=option.strip().replace(' ','_')value=value.strip()current[option]=valueorNoneexceptIOError,ex:warning('missing or non readable configuration file %s (%s)',config_file,ex)returnconfigdefenv_path(env_var,default,name):returndefaultdefcreate_dir(*args):raiseRuntimeError()