~gnuoy/charms/trusty/openstack-dashboard/plugin-relation

« back to all changes in this revision

Viewing changes to hooks/horizon_contexts.py

  • Committer: Michał Sawicz
  • Date: 2015-06-03 12:36:26 UTC
  • Revision ID: michal.sawicz@canonical.com-20150603123626-jcos6woiu9obw6t2
Fix lint and add priority support to LocalSettingsContext

Show diffs side-by-side

added added

removed removed

Lines of Context:
180
180
    def __call__(self):
181
181
        ''' Additional config stanzas to be appended to local_settings.py '''
182
182
 
183
 
        settings = []
 
183
        relations = []
184
184
 
185
185
        for rid in relation_ids("plugin"):
186
186
            try:
189
189
                pass
190
190
            else:
191
191
                rdata = relation_get(unit=unit, rid=rid)
192
 
                if 'local_settings' in rdata:
193
 
                    settings.append('# {0}\n{1}'.format(
194
 
                        unit, rdata['local_settings'])
195
 
                    )
 
192
                if set(('local_settings', 'priority')) <= set(rdata.keys()):
 
193
                    relations.append((unit, rdata))
 
194
 
196
195
        ctxt = {
197
 
            'settings': settings
 
196
            'settings': [
 
197
                '# {0}\n{1}'.format(u, rd['local_settings'])
 
198
                for u, rd in sorted(relations,
 
199
                                   key=lambda r: r[1]['priority'])]
198
200
        }
199
201
        return ctxt
200
202
 
215
217
                    if rdata['priority'] is not None and rdata['plugin_file']:
216
218
                        service = re.sub('[^a-z0-9_]', '_', unit.split('/')[0])
217
219
                        plugins[(rdata['priority'], service)] = {
218
 
                                    'unit': unit,
219
 
                                    'plugin_file': rdata['plugin_file']}
 
220
                            'unit': unit,
 
221
                            'plugin_file': rdata['plugin_file']}
220
222
                except KeyError:
221
223
                    pass
222
224
 
223
 
        return plugins
 
 
b'\\ No newline at end of file'
 
225
        return plugins