From afeeb2b6430875cc3979ae4ad690d2a3efc0ac68 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 11 May 2012 13:27:07 -0400 Subject: moved plugin-specific configs to main config file; propagate "setup" object to server Core --- tools/upgrade/1.3/migrate_configs.py | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 tools/upgrade/1.3/migrate_configs.py (limited to 'tools/upgrade/1.3/migrate_configs.py') diff --git a/tools/upgrade/1.3/migrate_configs.py b/tools/upgrade/1.3/migrate_configs.py new file mode 100755 index 000000000..c6e6cd2c3 --- /dev/null +++ b/tools/upgrade/1.3/migrate_configs.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +import os +import sys +from Bcfg2.Bcfg2Py3k import ConfigParser +import Bcfg2.Options + +def copy_section(src_file, tgt_cfg, section, newsection=None): + if newsection is None: + newsection = section + + cfg = ConfigParser.ConfigParser() + if len(cfg.read(src_file)) == 1: + if cfg.has_section(section): + try: + tgt_cfg.add_section(newsection) + except ConfigParser.DuplicateSectionError: + print("[%s] section already exists in %s, adding options" % + (newsection, setup['cfile'])) + for opt in cfg.options(section): + val = cfg.get(section, opt) + if tgt_cfg.has_option(newsection, opt): + print("%s in [%s] already populated in %s, skipping" % + (opt, newsection, setup['cfile'])) + print(" %s: %s" % (setup['cfile'], + tgt_cfg.get(newsection, opt))) + print(" %s: %s" % (src_file, val)) + else: + print("Set %s in [%s] to %s" % (opt, newsection, val)) + tgt_cfg.set(newsection, opt, val) + +def main(): + opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY, + configfile=Bcfg2.Options.CFILE) + setup = Bcfg2.Options.OptionParser(opts) + setup.parse(sys.argv[1:]) + + copy_section(os.path.join(setup['repo'], 'Rules', 'rules.conf'), setup.cfp, + "rules") + pkgs_conf = os.path.join(setup['repo'], 'Packages', 'packages.conf') + copy_section(pkgs_conf, setup.cfp, "global", newsection="packages") + for section in ["apt", "yum", "pulp"]: + copy_section(pkgs_conf, setup.cfp, section, + newsection="packages:" + section) + + print("Writing %s" % setup['configfile']) + try: + setup.cfp.write(open(setup['configfile'], "w")) + except IOError: + err = sys.exc_info()[1] + print("Could not write %s: %s" % (setup['configfile'], err)) + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3-1-g7c22