On 4/2/06, Brad Fuller <[EMAIL PROTECTED]> wrote:
>> I created a small python script for globally removing unwanted
>> parameters. I can post it if you like.
>
> that'd be nice, thanks
Please find the file attached. It's quite a hack and not that well
documented but anyway here it is. You need at least to change the
TRAC_PARENT_PATH in the file since I'm on Windows.
-- JornH
from ConfigParser import ConfigParser
import sys, os
TRAC_PARENT_PATH = '\\tracdata\\'
def config_get(config, section, option, default=None, raw=0, vars=None):
"""Get a value from the configuration, with a default."""
if config.has_option(section, option):
return config.get(section, option, raw=raw, vars=None)
else:
return default
def config_show(config, section, option):
if config.has_option(section, option):
return "%s" % (config_get(config, section, option))
else:
return "*undefined*"
def one_ini(trac_env, section, option, value):
config_file = "%s%s/conf/trac.ini" % (TRAC_PARENT_PATH, trac_env)
if os.path.exists(config_file):
config = ConfigParser()
config.read(config_file)
if not config.has_section(section):
print >>sys.stderr, "%s: Configuration missing [%s] section." % (trac_env, section)
if cmd == 'show':
print "%s,\t %s" % (trac_env, config_show(config, section, option))
if cmd == 'killsection':
config.remove_section(section)
config.write(open(config_file, 'w+'))
if cmd == 'killoption':
config.remove_option(section, option)
config.write(open(config_file, 'w+'))
if cmd == 'setall':
config.set(section, option, value)
print "%s, [%s] %s = %s" % (config_file, section, option, config_get(config, section, option))
config.write(open(config_file, 'w+'))
def show_usage():
print "usage: %s <cmd> <section> <option> [value]" % (sys.argv[0])
print " where cmd is 'show' or 'setall'"
print " and 'value' is only used for the 'setall' cmd"
if __name__ == "__main__":
if len(sys.argv) < 4:
show_usage()
sys.exit(1)
cmd = sys.argv[1]
section = sys.argv[2]
option = sys.argv[3]
if len(sys.argv) > 4:
value = sys.argv[4]
#envs = ['Newtracdb09', 'Newtracdb']
#print envs
## for reading from a file
envs_file = open('envlist.txt', 'r')
envs = envs_file.readlines()
#print envs
## for reading all dirs in a parent env
#envs = os.listdir(TRAC_PARENT_PATH)
for trac_env in envs:
# clean possible trailing newlines from envlist file
trac_env = trac_env.strip()
one_ini(trac_env, section, option, value=None)
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac