11# Roundup Issue Tracker configuration support
22#
3- # $Id: configuration.py,v 1.15 2004-07-28 02:29:45 richard Exp $
3+ # $Id: configuration.py,v 1.16 2004-07-28 09:46:58 a1s Exp $
44#
55__docformat__ = "restructuredtext"
66
@@ -455,20 +455,25 @@ class NullableFilePathOption(NullableOption, FilePathOption):
455455 )),
456456 ("rdbms" , (
457457 (Option , 'name' , 'roundup' ,
458- "Name of the Postgresql or MySQL database to use." ,
458+ "Name of the database to use." ,
459459 ['MYSQL_DBNAME' ]),
460460 (NullableOption , 'host' , 'localhost' ,
461- "Hostname that the Postgresql or MySQL database resides on ." ,
461+ "Database server host ." ,
462462 ['MYSQL_DBHOST' ]),
463463 (NullableOption , 'port' , '' ,
464- "Port number that the Postgresql or MySQL database resides on." ),
464+ "TCP port number of the database server.\n "
465+ "Postgresql usually resides on port 5432 (if any),\n "
466+ "for MySQL default port number is 3306.\n "
467+ "Leave this option empty to use backend default" ),
465468 (NullableOption , 'user' , 'roundup' ,
466- "Postgresql or MySQL database user that Roundup should use." ,
469+ "Database user name that Roundup should use." ,
467470 ['MYSQL_DBUSER' ]),
468471 (NullableOption , 'password' , 'roundup' ,
469- "Password for the Postgresql or MySQL database user." ,
472+ "Database user password ." ,
470473 ['MYSQL_DBPASSWORD' ]),
471- )),
474+ ), "Settings in this section are used"
475+ " by Postgresql and MySQL backends only"
476+ ),
472477 ("logging" , (
473478 (FilePathOption , "config" , "" ,
474479 "Path to configuration file for standard Python logging module.\n "
@@ -514,7 +519,7 @@ class NullableFilePathOption(NullableOption, FilePathOption):
514519 "messages to this file *instead* of sending them.\n "
515520 "This option has the same effect as environment variable"
516521 " SENDMAILDEBUG.\n Environment variable takes precedence." ),
517- )),
522+ ), "Outgoing email options. \n Used for nozy messages and approval requests" ),
518523 ("mailgw" , (
519524 (BooleanOption , "keep_quoted_text" , "yes" ,
520525 "Keep email citations when accepting messages.\n "
@@ -531,7 +536,7 @@ class NullableFilePathOption(NullableOption, FilePathOption):
531536 "if one isn't supplied in email subjects.\n "
532537 "To disable, leave the value blank." ,
533538 ["MAIL_DEFAULT_CLASS" ]),
534- )),
539+ ), "Roundup Mail Gateway options" ),
535540 ("nosy" , (
536541 (RunDetectorOption , "messages_to_author" , "no" ,
537542 "Send nosy messages to the author of the message." ,
@@ -554,7 +559,7 @@ class NullableFilePathOption(NullableOption, FilePathOption):
554559 "If 'yes', then the recipients will be added on followups too.\n "
555560 "If 'no', they're never added to the nosy.\n " ,
556561 ["ADD_RECIPIENTS_TO_NOSY" ]),
557- )),
562+ ), "Nosy messages sending" ),
558563)
559564
560565### Configuration classes
@@ -760,13 +765,13 @@ def load_ini(self, home_dir, defaults=None):
760765 config_defaults = {"HOME" : home_dir }
761766 if defaults :
762767 config_defaults .update (defaults )
763- _config = ConfigParser .ConfigParser (defaults )
764- _config .read ([os .path .join (home_dir , self .INI_FILE )])
768+ config = ConfigParser .ConfigParser (config_defaults )
769+ config .read ([os .path .join (home_dir , self .INI_FILE )])
765770 # .ini file loaded ok. set the options, starting from HOME
766771 self .reset ()
767772 self .HOME = home_dir
768- for _option in self .items ():
769- _option .load_ini (_config )
773+ for option in self .items ():
774+ option .load_ini (config )
770775
771776 def load (self , home_dir ):
772777 """Load configuration settings from home_dir"""
@@ -796,10 +801,16 @@ def save(self, ini_file=None):
796801 _fp .write ("\n # WARNING! Following options need adjustments:\n " )
797802 for section , options in need_set .items ():
798803 _fp .write ("# [%s]: %s\n " % (section , ", " .join (options )))
799- for _section in self .sections :
800- _fp .write ("\n [%s]\n " % _section )
801- for _option in self ._get_section_options (_section ):
802- _fp .write ("\n " + self .options [(_section , _option )].format ())
804+ for section in self .sections :
805+ comment = self .section_descriptions .get (section , None )
806+ if comment :
807+ _fp .write ("\n # " .join (["" ] + comment .split ("\n " )) + "\n " )
808+ else :
809+ # no section comment - just leave a blank line between sections
810+ _fp .write ("\n " )
811+ _fp .write ("[%s]\n " % section )
812+ for option in self ._get_section_options (section ):
813+ _fp .write ("\n " + self .options [(section , option )].format ())
803814 _fp .close ()
804815 if os .access (ini_file , os .F_OK ):
805816 if os .access (_bak_file , os .F_OK ):
@@ -920,7 +931,7 @@ class CoreConfig(Config):
920931 """Roundup instance configuration.
921932
922933 Core config has a predefined layout (see the SETTINGS structure),
923- support loading of old-style pythonic configurations and hold
934+ supports loading of old-style pythonic configurations and holds
924935 three additional attributes:
925936 logging:
926937 instance logging engine, from standard python logging module
@@ -946,8 +957,16 @@ def __init__(self, home_dir=None):
946957 if home_dir is None :
947958 self .init_logging ()
948959
949- # TODO: remove MAIL_PASSWORD if MAIL_USER is empty
950- #def _get_unset_options(self):
960+ def _get_unset_options (self ):
961+ need_set = Config ._get_unset_options (self )
962+ # remove MAIL_PASSWORD if MAIL_USER is empty
963+ if "password" in need_set .get ("mail" , []):
964+ if not self ["MAIL_USERNAME" ]:
965+ settings = need_set ["mail" ]
966+ settings .remove ("password" )
967+ if not settings :
968+ del need_set ["mail" ]
969+ return need_set
951970
952971 def reset (self ):
953972 Config .reset (self )
0 commit comments