Commit d5f5978fcf221243723c07624d738979031d1ba5

Authored by Matheus de Sousa Faria
Committed by Gust
1 parent b5ff2e20

Importing widgets settings

Showing 2 changed files with 31 additions and 0 deletions   Show diff stats
colab/settings.py
... ... @@ -290,3 +290,5 @@ TEMPLATE_DIRS += (
290 290 )
291 291  
292 292 conf.validate_database(DATABASES, DEFAULT_DATABASE, DEBUG)
  293 +
  294 +conf.load_widgets_settings()
... ...
colab/utils/conf.py
... ... @@ -141,6 +141,35 @@ def load_colab_apps():
141 141 return {'COLAB_APPS': COLAB_APPS}
142 142  
143 143  
  144 +def load_widgets_settings():
  145 + settings_file = os.getenv('COLAB_WIDGETS_SETTINGS',
  146 + '/etc/colab/widgets_settings.py')
  147 + settings_module = settings_file.split('.')[-2].split('/')[-1]
  148 + py_path = "/".join(settings_file.split('/')[:-1])
  149 +
  150 + logger.info('Widgets Settings file: %s', settings_file)
  151 +
  152 + if not os.path.exists(py_path):
  153 + msg = "The py file {} does not exist".format(py_path)
  154 + raise InaccessibleSettings(msg)
  155 +
  156 + py_settings = _load_py_file(settings_module, py_path)
  157 +
  158 + # Read settings from settings.d
  159 + settings_dir = '/etc/colab/widgets.d'
  160 + logger.info('Widgets Settings directory: %s', settings_dir)
  161 +
  162 + if not os.path.exists(settings_dir):
  163 + return py_settings
  164 +
  165 + for file_name in os.listdir(settings_dir):
  166 + if not file_name.endswith('.py'):
  167 + continue
  168 +
  169 + file_module = file_name.split('.')[0]
  170 + _load_py_file(file_module, settings_dir)
  171 + logger.info('Loaded %s/%s', settings_dir, file_name)
  172 +
144 173 def validate_database(database_dict, default_db, debug):
145 174 db_name = database_dict.get('default', {}).get('NAME')
146 175 if not debug and db_name == default_db:
... ...