2020-01-19 15:36:52 +01:00
import argparse
2020-04-08 11:50:00 +02:00
import logging
2020-01-19 15:36:52 +01:00
2020-01-25 14:24:21 +01:00
import util . store
2020-04-02 16:54:57 +02:00
import util . format
2020-01-25 14:24:21 +01:00
2020-04-08 11:50:00 +02:00
log = logging . getLogger ( __name__ )
2020-02-09 13:46:56 +01:00
MODULE_HELP = ' Specify a space-separated list of modules to load. The order of the list determines their order in the i3bar (from left to right). Use <module>:<alias> to provide an alias in case you want to load the same module multiple times, but specify different parameters. '
PARAMETER_HELP = ' Provide configuration parameters in the form of <module>.<key>=<value> '
THEME_HELP = ' Specify the theme to use for drawing modules '
2020-01-19 15:36:52 +01:00
2020-01-25 14:24:21 +01:00
class Config ( util . store . Store ) :
2020-01-19 15:36:52 +01:00
def __init__ ( self , args ) :
2020-01-25 14:24:21 +01:00
super ( Config , self ) . __init__ ( )
2020-01-19 15:36:52 +01:00
parser = argparse . ArgumentParser ( description = ' bumblebee-status is a modular, theme-able status line generator for the i3 window manager. https://github.com/tobi-wan-kenobi/bumblebee-status/wiki ' )
2020-02-09 13:46:56 +01:00
parser . add_argument ( ' -m ' , ' --modules ' , nargs = ' + ' , action = ' append ' , default = [ ] ,
2020-01-19 15:36:52 +01:00
help = MODULE_HELP )
2020-02-09 13:46:56 +01:00
parser . add_argument ( ' -p ' , ' --parameters ' , nargs = ' + ' , action = ' append ' , default = [ ] ,
2020-01-25 14:24:21 +01:00
help = PARAMETER_HELP )
2020-02-09 13:46:56 +01:00
parser . add_argument ( ' -t ' , ' --theme ' , default = ' default ' , help = THEME_HELP )
parser . add_argument ( ' -i ' , ' --iconset ' , default = ' auto ' ,
help = ' Specify the name of an iconset to use (overrides theme default) ' )
2020-03-29 14:13:21 +02:00
parser . add_argument ( ' -a ' , ' --autohide ' , nargs = ' + ' , default = [ ] ,
help = ' Specify a list of modules to hide when not in warning/error state ' )
parser . add_argument ( ' --debug ' , action = ' store_true ' ,
help = ' Add debug fields to i3 output ' )
2020-04-04 13:54:08 +02:00
self . __args = parser . parse_args ( args )
2020-01-19 15:36:52 +01:00
2020-04-04 13:54:08 +02:00
parameters = [ item for sub in self . __args . parameters for item in sub ]
2020-01-25 14:24:21 +01:00
for param in parameters :
2020-04-08 11:50:00 +02:00
if not ' = ' in param :
log . error ( ' missing value for parameter " {} " - ignoring this parameter ' . format ( param ) )
continue
2020-02-09 13:46:56 +01:00
key , value = param . split ( ' = ' , 1 )
2020-01-25 14:24:21 +01:00
self . set ( key , value )
2020-01-19 15:36:52 +01:00
def modules ( self ) :
2020-04-04 13:54:08 +02:00
return [ item for sub in self . __args . modules for item in sub ]
2020-01-19 15:36:52 +01:00
2020-04-02 16:54:57 +02:00
def interval ( self , default = 1 ) :
return util . format . seconds ( self . get ( ' interval ' , default ) )
2020-02-09 13:46:56 +01:00
2020-03-29 14:13:21 +02:00
def debug ( self ) :
2020-04-04 13:54:08 +02:00
return self . __args . debug
2020-03-29 14:13:21 +02:00
2020-02-09 13:46:56 +01:00
def theme ( self ) :
2020-04-04 13:54:08 +02:00
return self . __args . theme
2020-02-09 13:46:56 +01:00
def iconset ( self ) :
2020-04-04 13:54:08 +02:00
return self . __args . iconset
2020-01-25 14:24:21 +01:00
2020-03-15 14:01:09 +01:00
def autohide ( self , name ) :
2020-04-04 13:54:08 +02:00
return name in self . __args . autohide
2020-03-15 14:01:09 +01:00
2020-01-19 15:36:52 +01:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4