#NEWLINE# def i3status_config_reader( self , i3status_config_path ) : #NEWLINE# #INDENT# '\n        Parse i3status.conf so we can adapt our code to the i3status config.\n        ' #NEWLINE# config = { #NEWLINE# #INDENT# 'general' : { #NEWLINE# #INDENT# 'color_bad' : '#FF0000' , #NEWLINE# 'color_degraded' : '#FFFF00' , #NEWLINE# 'color_good' : '#00FF00' , #NEWLINE# 'color_separator' : '#333333' , #NEWLINE# 'colors' : False , #NEWLINE# 'interval' : 5 , #NEWLINE# 'output_format' : 'i3bar' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'i3s_modules' : [ ] , #NEWLINE# 'on_click' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'order' : [ ] , #NEWLINE# '.group_extras' : [ ] , #NEWLINE# '.module_groups' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'py3_modules' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# in_section = False #NEWLINE# section_name = '' #NEWLINE# group_name = None #NEWLINE# for line in open ( i3status_config_path , 'r' ) : #NEWLINE# #INDENT# line = line . strip ( ' \t\n\r' ) #NEWLINE# if ( ( not line ) or line . startswith ( '#' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if line . startswith ( 'order' ) : #NEWLINE# #INDENT# in_section = True #NEWLINE# section_name = 'order' #NEWLINE# #UNINDENT# if ( ( not in_section ) and line . startswith ( 'group' ) ) : #NEWLINE# #INDENT# group_name = line . split ( '{' ) [ 0 ] . strip ( ) #NEWLINE# config [ group_name ] = { #NEWLINE# #INDENT# 'items' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# continue #NEWLINE# #UNINDENT# if ( ( not in_section ) and group_name and ( line == '}' ) ) : #NEWLINE# #INDENT# group_name = None #NEWLINE# continue #NEWLINE# #UNINDENT# if ( group_name and ( not in_section ) and ( '=' in line ) ) : #NEWLINE# #INDENT# if ( ( '{' not in line ) or ( line . index ( '{' ) > line . index ( '=' ) ) ) : #NEWLINE# #INDENT# key = line . split ( '=' , 1 ) [ 0 ] . strip ( ) #NEWLINE# key = self . eval_config_parameter ( key ) #NEWLINE# value = line . split ( '=' , 1 ) [ 1 ] . strip ( ) #NEWLINE# value = self . eval_config_value ( value ) #NEWLINE# if ( not key . startswith ( 'on_click' ) ) : #NEWLINE# #INDENT# config [ group_name ] [ key ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# button = int ( key . split ( ) [ 1 ] ) #NEWLINE# if ( button not in range ( 1 , 6 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'should be 1, 2, 3, 4 or 5' ) #NEWLINE# #UNINDENT# #UNINDENT# except IndexError as e : #NEWLINE# #INDENT# raise IndexError ( 'missing "button id" for "on_click" parameter in group {}' . format ( group_name ) ) #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# raise ValueError ( 'invalid "button id" for "on_click" parameter in group {} ({})' . format ( group_name , e ) ) #NEWLINE# #UNINDENT# on_c = config [ 'on_click' ] #NEWLINE# on_c [ e ] = on_c . get ( group_name , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# on_c [ group_name ] [ button ] = value #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# if ( not in_section ) : #NEWLINE# #INDENT# section_name = line . split ( '{' ) [ 0 ] . strip ( ) #NEWLINE# section_name = self . eval_config_parameter ( section_name ) #NEWLINE# if ( not section_name ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# in_section = True #NEWLINE# if ( section_name not in config ) : #NEWLINE# #INDENT# config [ section_name ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if group_name : #NEWLINE# #INDENT# config [ group_name ] [ 'items' ] . append ( section_name ) #NEWLINE# section = config [ '.module_groups' ] . setdefault ( section_name , [ ] ) #NEWLINE# if ( group_name not in section ) : #NEWLINE# #INDENT# section . append ( group_name ) #NEWLINE# #UNINDENT# if ( not self . valid_config_param ( section_name ) ) : #NEWLINE# #INDENT# if ( section_name not in config [ 'py3_modules' ] ) : #NEWLINE# #INDENT# config [ 'py3_modules' ] . append ( section_name ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( section_name not in config [ 'i3s_modules' ] ) : #NEWLINE# #INDENT# config [ 'i3s_modules' ] . append ( section_name ) #NEWLINE# #UNINDENT# if ( section_name not in config [ '.group_extras' ] ) : #NEWLINE# #INDENT# config [ '.group_extras' ] . append ( section_name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( '{' in line ) : #NEWLINE# #INDENT# in_section = True #NEWLINE# #UNINDENT# if ( section_name and ( '=' in line ) ) : #NEWLINE# #INDENT# section_line = line #NEWLINE# if line . endswith ( '}' ) : #NEWLINE# #INDENT# section_line = section_line . split ( '}' , ( - 1 ) ) [ 0 ] . strip ( ) #NEWLINE# #UNINDENT# if line . startswith ( ( section_name + ' {' ) ) : #NEWLINE# #INDENT# section_line = section_line . split ( ( section_name + ' {' ) ) [ 1 ] . strip ( ) #NEWLINE# #UNINDENT# key = section_line . split ( '=' , 1 ) [ 0 ] . strip ( ) #NEWLINE# key = self . eval_config_parameter ( key ) #NEWLINE# value = section_line . split ( '=' , 1 ) [ 1 ] . strip ( ) #NEWLINE# value = self . eval_config_value ( value ) #NEWLINE# if ( section_name == 'order' ) : #NEWLINE# #INDENT# config [ section_name ] . append ( value ) #NEWLINE# line = '}' #NEWLINE# if ( value not in config ) : #NEWLINE# #INDENT# config [ value ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( not self . valid_config_param ( value ) ) : #NEWLINE# #INDENT# config [ 'py3_modules' ] . append ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# config [ 'i3s_modules' ] . append ( value ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not key . startswith ( 'on_click' ) ) : #NEWLINE# #INDENT# config [ section_name ] [ key ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# button = int ( key . split ( ) [ 1 ] ) #NEWLINE# if ( button not in range ( 1 , 6 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'should be 1, 2, 3, 4 or 5' ) #NEWLINE# #UNINDENT# #UNINDENT# except IndexError as e : #NEWLINE# #INDENT# raise IndexError ( 'missing "button id" for "on_click" parameter in section {}' . format ( section_name ) ) #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# raise ValueError ( 'invalid "button id" for "on_click" parameter in section {} ({})' . format ( section_name , e ) ) #NEWLINE# #UNINDENT# on_c = config [ 'on_click' ] #NEWLINE# on_c [ section_name ] = on_c . get ( section_name , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# on_c [ section_name ] [ button ] = value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if line . endswith ( '}' ) : #NEWLINE# #INDENT# in_section = False #NEWLINE# section_name = '' #NEWLINE# #UNINDENT# #UNINDENT# if ( config [ 'general' ] [ 'output_format' ] != 'i3bar' ) : #NEWLINE# #INDENT# raise RuntimeError ( ( 'i3status output_format should be set' + ' to "i3bar" on {}' . format ( i3status_config_path , ( ' or on your own {}/.i3status.conf' . format ( os . path . expanduser ( '~' ) ) if ( i3status_config_path == '/etc/i3status.conf' ) else '' ) ) ) ) #NEWLINE# #UNINDENT# for name in config : #NEWLINE# #INDENT# if ( ( name . split ( ) [ 0 ] in TIME_MODULES ) and ( 'format' not in config [ name ] ) ) : #NEWLINE# #INDENT# if ( name . split ( ) [ 0 ] == 'time' ) : #NEWLINE# #INDENT# config [ name ] [ 'format' ] = TIME_FORMAT #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# config [ name ] [ 'format' ] = TZTIME_FORMAT #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# def clean_i3status_modules( key ) : #NEWLINE# #INDENT# for module_name in deepcopy ( config [ key ] ) : #NEWLINE# #INDENT# if ( self . valid_config_param ( module_name , cleanup = True ) and ( not config . get ( module_name ) ) ) : #NEWLINE# #INDENT# config . pop ( module_name ) #NEWLINE# if ( module_name in config [ 'i3s_modules' ] ) : #NEWLINE# #INDENT# config [ 'i3s_modules' ] . remove ( module_name ) #NEWLINE# #UNINDENT# config [ key ] . remove ( module_name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# clean_i3status_modules ( 'order' ) #NEWLINE# clean_i3status_modules ( '.group_extras' ) #NEWLINE# return config