← Back to team overview

credativ team mailing list archive

[Merge] lp:~credativ/openobject-server/trunk-comments into lp:openobject-server

 

Dmitrijs Ledkovs (credativ) has proposed merging lp:~credativ/openobject-server/trunk-comments into lp:openobject-server.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~credativ/openobject-server/trunk-comments/+merge/69933

server config file generated with "-s" doesn't have any comments and sometimes it is hard to guess what each option means.

This patch adds comments to the config file from the respective arg help string together with the default value.

The config options are still correctly read at load time, because config parser ignores lines that start with "#" and ";".

== BEFORE ==
[options]
addons_path = /home/dle/src/openerp/trunk/server/openerp/addons
admin_passwd = admin
assert_exit_level = error
cache_timeout = 100000

== AFTER ==
[options]
# specify additional addons paths (separated by commas).; default = None
addons_path = /home/dle/src/openerp/trunk/server/openerp/addons
# set superadmin password; default = admin
admin_passwd = admin
# specify the level at which a failed assertion will stop the server.
# accepted values: ['info', 'debug_rpc', 'warn', 'test', 'critical',
# 'debug_sql', 'error', 'debug', 'debug_rpc_answer', 'notset'];
# default = error
assert_exit_level = error
# set the timeout for the cache system; default = 100000
cache_timeout = 100000

-- 
https://code.launchpad.net/~credativ/openobject-server/trunk-comments/+merge/69933
Your team Credativ is subscribed to branch lp:~credativ/openobject-server/trunk-comments.
=== modified file 'openerp/tools/config.py'
--- openerp/tools/config.py	2011-06-23 09:04:57 +0000
+++ openerp/tools/config.py	2011-07-31 21:14:23 +0000
@@ -27,6 +27,7 @@
 import openerp.loglevels as loglevels
 import logging
 import openerp.release as release
+from textwrap import fill
 
 class MyOption (optparse.Option, object):
     """ optparse Option with two additional attributes.
@@ -508,12 +509,27 @@
     def save(self):
         p = ConfigParser.ConfigParser()
         loglevelnames = dict(zip(self._LOGLEVELS.values(), self._LOGLEVELS.keys()))
+        comments = {}
+        defaults = {}
+        for group in self.parser.option_groups:
+            for option in group.option_list:
+                comments[option.dest] = option.help
+                defaults[option.dest] = option.my_default
+        comments['admin_passwd'] = "Set superadmin password"
+        defaults['admin_passwd'] = "admin"
         p.add_section('options')
         for opt in sorted(self.options.keys()):
-            if opt in ('version', 'language', 'translate_out', 'translate_in', 'overwrite_existing_translations', 'init', 'update'):
+            if opt in ('version', 'language', 'translate_out', 'translate_in',
+                       'overwrite_existing_translations', 'init', 'update'):
                 continue
             if opt in self.blacklist_for_save:
                 continue
+            try:
+                p.set('options',
+                      fill(comments[opt] + '; Default',
+                           initial_indent='# ', subsequent_indent='# '),
+                      defaults[opt])
+            except: pass
             if opt in ('log_level', 'assert_exit_level'):
                 p.set('options', opt, loglevelnames.get(self.options[opt], self.options[opt]))
             else:


Follow ups