Revision bcc137e3 snf-webproject/synnefo/webproject/management/commands/settings.py

b/snf-webproject/synnefo/webproject/management/commands/settings.py
30 30
from synnefo.settings.setup import Setting
31 31
from django.core.management.base import BaseCommand, CommandError
32 32
from optparse import make_option
33
from os.path import isdir
33
from os.path import isdir, exists
34 34
from pprint import pformat
35 35
from textwrap import wrap
36 36

  
......
326 326
            raise CommandError(m)
327 327

  
328 328
        category_depths = {}
329
        for name, setting in Setting.Catalogs['settings'].iteritems():
330
            category = setting.category
331
            if (category not in category_depths or
332
                    setting.configured_depth > category_depths[category]):
333
                category_depths[category] = setting.configured_depth
329
        for name, setting in display_settings_list:
330
            key = (setting.configured_depth, setting.category)
331
            if key not in category_depths:
332
                category_depths[key] = []
333
            category_depths[key].append((name, setting))
334 334

  
335 335
        old_filepath = None
336 336
        conffile = None
337 337
        filepath = None
338
        for name, setting in display_settings_list:
339
            category = setting.category
340
            category_depth = 10 * category_depths[category]
338
        for (depth, category), setting_list in \
339
                sorted(category_depths.iteritems()):
340
            depth *= 10
341 341
            filepath = '{path}/{depth}-{category}.conf'
342 342
            filepath = filepath.format(path=path,
343
                                       depth=category_depth,
343
                                       depth=depth,
344 344
                                       category=category)
345 345
            if filepath != old_filepath:
346 346
                if conffile:
347 347
                    conffile.close()
348
                if exists(filepath):
349
                    m = "File {f} already exists! aborting."
350
                    m = m.format(f=filepath)
351
                    raise CommandError(m)
352
                self.stdout.write("Writing {f}\n".format(f=filepath))
348 353
                conffile = open(filepath, "a")
349 354
                old_filepath = filepath
350
            conffile.write(setting.present_as_comment(runtime=runtime))
351
            conffile.write('\n')
355
            setting_list.sort()
356
            for name, setting in setting_list:
357
                conffile.write(setting.present_as_comment(runtime=runtime))
358
                conffile.write('\n')
352 359

  
353 360
    def handle(self, *args, **options):
354 361
        if args:

Also available in: Unified diff