<s> import collections <EOL> import logging <EOL> import pkgutil <EOL> from django . utils import importlib <EOL> def import_submodules ( module ) : <EOL> """<STR_LIT>""" <EOL> submodules = { } <EOL> for loader , name , ispkg in pkgutil . iter_modules ( module . __path__ , <EOL> module . __name__ + '<STR_LIT:.>' ) : <EOL> try : <EOL> submodule = importlib . import_module ( name ) <EOL> except ImportError as e : <EOL> logging . warning ( "<STR_LIT>" % name ) <EOL> logging . exception ( e ) <EOL> else : <EOL> parent , child = name . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> submodules [ child ] = submodule <EOL> return submodules <EOL> def import_dashboard_config ( modules ) : <EOL> """<STR_LIT>""" <EOL> config = collections . defaultdict ( dict ) <EOL> for module in modules : <EOL> for key , submodule in import_submodules ( module ) . iteritems ( ) : <EOL> try : <EOL> dashboard = submodule . DASHBOARD <EOL> except AttributeError : <EOL> logging . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % submodule . __name__ ) <EOL> else : <EOL> config [ dashboard ] . update ( submodule . __dict__ ) <EOL> return sorted ( config . iteritems ( ) , <EOL> key = lambda c : c [ <NUM_LIT:1> ] [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) ) <EOL> def update_dashboards ( modules , horizon_config , installed_apps ) : <EOL> """<STR_LIT>""" <EOL> dashboards = [ ] <EOL> exceptions = { } <EOL> apps = [ ] <EOL> for dashboard , config in import_dashboard_config ( modules ) : <EOL> if config . get ( '<STR_LIT>' , False ) : <EOL> continue <EOL> dashboards . append ( dashboard ) <EOL> exceptions . update ( config . get ( '<STR_LIT>' , { } ) ) <EOL> apps . extend ( config . get ( '<STR_LIT>' , [ ] ) ) <EOL> if config . get ( '<STR_LIT>' , False ) : <EOL> horizon_config [ '<STR_LIT>' ] = dashboard <EOL> horizon_config [ '<STR_LIT>' ] = tuple ( dashboards ) <EOL> horizon_config [ '<STR_LIT>' ] . update ( exceptions ) <EOL> installed_apps . extend ( apps ) </s>
