def backup_existing_inova_conf(self, overwrite=False): in_conf = "%s/.inova-login" % common.get_home() in_bak = in_conf + ".bak" if not common.check_file(in_conf): LOG.info("No pre-existing inova conf found") return True # check if existing supernova conf is a snail conf conf_check = ConfigParser.ConfigParser() conf_check.readfp(open(in_conf)) if conf_check.has_section("inova-login") and conf_check.has_option("inova-login", "snail-gen"): """ No need to back up a snail config file.""" return True if common.check_file(in_bak): if not overwrite: LOG.error("Backup already exists! Confirm with --overwrite") return False LOG.info("Backing up existing conf to %s" % in_bak) common.copy_file(in_conf, in_bak) return True
def generate_supernova_conf(self): repo = self.template_repo secure_dir = "%s/%s" % (self.install_path, "secure") if common.check_dir(secure_dir): common.remove_dir(secure_dir) if not common.clone_from_git_repo(repo, secure_dir): LOG.error("Could not clone %s" % repo) self.abort() seed_file = "%s/snail/supernova_seed.conf" % secure_dir remote_config = ConfigParser.ConfigParser() remote_config.readfp(open(seed_file)) snail_conf = "%s/snail.conf" % common.get_home() if not common.check_file(snail_conf): LOG.error("Could not locate snail.conf") self.abort() snail_config = ConfigParser.ConfigParser() snail_config.readfp(open(snail_conf)) inovas = {} supernovas = {} inova_template = None sn_template = None config_list = [remote_config, snail_config] ignored_keys = ["pw_type"] for config in config_list: sections = config.sections() for section in sections: td = {} for k, v in config.items(section): if k in ignored_keys: continue td[k] = v if section == "inova-template": inova_template = td continue elif section == "supernova-template": sn_template = td continue if not config.has_option(section, "type"): continue type = config.get(section, "type") if type == "inova": if section in inovas: inovas[section].update(td) else: inovas[section] = td elif type == "supernova": if section in supernovas: supernovas[section].update(td) else: supernovas[section] = td if not inova_template or not sn_template: LOG.error("Could not find inova or supernova template anywhere") common.self.abort() out_file = "%s/snail/supernova_out.conf" % secure_dir if common.check_file(out_file): common.remove_file(out_file) out_config = ConfigParser.ConfigParser() out_config.add_section("snail") out_config.set("snail", "version", "0.1") out_list = [(inovas, inova_template), (supernovas, sn_template)] for listing, template in out_list: for title, items in listing.items(): out_config.add_section(title) for template_key, template_value in template.items(): src = template_value.lower() value = template_value if src == "title": value = title if src in items: value = items[template_value.lower()] if template_key.lower() in items: value = items[template_key.lower()] out_config.set(title, template_key.upper(), value) for template_key, template_value in template.items(): src = template_value.lower() if src in items: del items[template_value.lower()] for item_key, item_value in items.items(): if not out_config.has_option(title, item_key): out_config.set(title, item_key, item_value) out_config.write(open(out_file, "w+")) sn_conf = "%s/.supernova" % common.get_home() common.copy_file(out_file, sn_conf) seed_file = "%s/snail/inova_seed.conf" % secure_dir remote_config = ConfigParser.ConfigParser() remote_config.readfp(open(seed_file)) out_file = "%s/snail/inovalogin_out.conf" % secure_dir if common.check_file(out_file): common.remove_file(out_file) out_config = ConfigParser.ConfigParser() out_config.add_section("inova-login") for k, v in remote_config.items("inova-login"): value = v if v == "USER": value = self.inova_user out_config.set("inova-login", k, value) out_config.set("inova-login", "snail_gen", "1") out_config.write(open(out_file, "w+")) sn_conf = "%s/.inova-login" % common.get_home() common.copy_file(out_file, sn_conf)