def get_configs(self): profiles = self.get_profiles() tracefiles = self.get_trace_files() injectfiles = self.get_inject_files() configs = [] for profile in profiles: for tracefile in tracefiles: for injectfile in injectfiles: profileconfig = ConfigParser.ConfigParser() commonsections = [s for s in self.config.sections() if s.startswith("common:")] profilesections = [s for s in self.config.sections() if s.startswith(profile +":")] sections = commonsections + profilesections for s in sections: s_noprefix = s.split(":")[1] items = self.config.items(s) if not profileconfig.has_section(s_noprefix): profileconfig.add_section(s_noprefix) for item in items: profileconfig.set(s_noprefix, item[0], item[1]) # The tracefile section may have not been created if not profileconfig.has_section("tracefile"): profileconfig.add_section("tracefile") # Add tracefile option profileconfig.set("tracefile", "tracefile", tracefile) # Add injected file option if injectfile != None: profileconfig.set("tracefile", "injectionfile", injectfile) # Add datafile option datadir = self.config.get(self.MULTI_SEC, self.DATADIR_OPT) datafilename = generate_config_name(profile, tracefile, injectfile) datafile = datadir + "/" + datafilename + ".dat" # The accounting section may have not been created if not profileconfig.has_section("accounting"): profileconfig.add_section("accounting") profileconfig.set("accounting", "datafile", datafile) # Set "attributes" option (only used internally) attrs = {"profile":profile,"tracefile":tracefile,"injectfile":injectfile} # TODO: Load additional attributes from trace/injfiles attrs_str = ",".join(["%s=%s" % (k,v) for (k,v) in attrs.items()]) if profileconfig.has_option("accounting", "attributes"): attrs_str += ",%s" % profileconfig.get("general", "attributes") profileconfig.set("accounting", "attributes", attrs_str) try: c = HaizeaConfig(profileconfig) except ConfigException, msg: print >> sys.stderr, "Error in configuration file:" print >> sys.stderr, msg exit(1) configs.append(c)
def run(self): self.parse_options() configfile=self.opt.conf multiconfig = HaizeaMultiConfig.from_file(configfile) etcdir = self.opt.dir configs = multiconfig.get_configs() etcdir = os.path.abspath(etcdir) if not os.path.exists(etcdir): os.makedirs(etcdir) for c in configs: profile = c.get_attr("profile") tracefile = c.get("tracefile") injfile = c.get("injectionfile") configname = generate_config_name(profile, tracefile, injfile) configfile = etcdir + "/%s.conf" % configname fc = open(configfile, "w") c.config.write(fc) fc.close()
def run(self): self.parse_options() configfile = self.opt.conf multiconfig = HaizeaMultiConfig.from_file(configfile) etcdir = self.opt.dir configs = multiconfig.get_configs() etcdir = os.path.abspath(etcdir) if not os.path.exists(etcdir): os.makedirs(etcdir) for c in configs: profile = c.get_attr("profile") tracefile = c.get("tracefile") injfile = c.get("injectionfile") configname = generate_config_name(profile, tracefile, injfile) configfile = etcdir + "/%s.conf" % configname fc = open(configfile, "w") c.config.write(fc) fc.close()
def get_configs(self): profiles = self.get_profiles() tracefiles = self.get_trace_files() annotationfiles = self.get_annotation_files() injectfiles = self.get_inject_files() if not self.config.has_option(self.MULTI_SEC, self.SKIP_NO_INJECTION_OPT): skip_no_injection = False else: skip_no_injection = self.config.getboolean(self.MULTI_SEC, self.SKIP_NO_INJECTION_OPT) if not self.config.has_option(self.MULTI_SEC, self.SKIP_NO_ANNOTATION_OPT): skip_no_annotation = False else: skip_no_annotation = self.config.getboolean(self.MULTI_SEC, self.SKIP_NO_ANNOTATION_OPT) no_annotations = (annotationfiles == [None]) no_injections = (injectfiles == [None]) configs = [] for profile in profiles: for tracefile in tracefiles: for annotationfile in annotationfiles: for injectfile in injectfiles: if annotationfile == None and skip_no_annotation: continue if injectfile == None and skip_no_injection: continue profileconfig = ConfigParser.ConfigParser() commonsections = [s for s in self.config.sections() if s.startswith("common:")] profilesections = [s for s in self.config.sections() if s.startswith(profile +":")] sections = commonsections + profilesections for s in sections: s_noprefix = s.split(":")[1] items = self.config.items(s) if not profileconfig.has_section(s_noprefix): profileconfig.add_section(s_noprefix) for item in items: profileconfig.set(s_noprefix, item[0], item[1]) # The tracefile section may have not been created if not profileconfig.has_section("tracefile"): profileconfig.add_section("tracefile") # Add tracefile option profileconfig.set("tracefile", "tracefile", tracefile) # Add injected file option if injectfile != None: profileconfig.set("tracefile", "injectionfile", injectfile) # Add annotations file option if annotationfile != None: profileconfig.set("tracefile", "annotationfile", annotationfile) # Add datafile option datadir = self.config.get(self.MULTI_SEC, self.DATADIR_OPT) datafilename = generate_config_name(profile, tracefile, annotationfile, injectfile) datafile = datadir + "/" + datafilename + ".dat" # The accounting section may have not been created if not profileconfig.has_section("accounting"): profileconfig.add_section("accounting") profileconfig.set("accounting", "datafile", datafile) # Set "attributes" option (only used internally) attrs = {"profile":profile,"tracefile":tracefile,"injectfile":injectfile,"annotationfile":annotationfile} trace_attrs = self.__load_attributes_from_file(tracefile) attrs.update(trace_attrs) if injectfile != None: inj_attrs = self.__load_attributes_from_file(injectfile) attrs.update(inj_attrs) if annotationfile != None: annot_attrs = self.__load_attributes_from_file(annotationfile) attrs.update(annot_attrs) attrs_str = ",".join(["%s=%s" % (k,v) for (k,v) in attrs.items()]) if profileconfig.has_option("accounting", "attributes"): attrs_str += ",%s" % profileconfig.get("accounting", "attributes") profileconfig.set("accounting", "attributes", attrs_str) try: c = HaizeaConfig(profileconfig) except ConfigException, msg: print >> sys.stderr, "Error in configuration file:" print >> sys.stderr, msg exit(1) configs.append(c)
class haizea_generate_scripts(Command): """ Generates a script, based on a script template, to run all the individual configuration files generated by haizea-generate-configs. This command requires Mako Templates for Python (http://www.makotemplates.org/).""" name = "haizea-generate-scripts" def __init__(self, argv): Command.__init__(self, argv) self.optparser.add_option( Option("-c", "--conf", action="store", type="string", dest="conf", required=True, help=""" Multiconfiguration file used in haizea-generate-configs. """)) self.optparser.add_option( Option("-d", "--confdir", action="store", type="string", dest="confdir", required=True, help=""" Directory containing the individual configuration files. """)) self.optparser.add_option( Option("-t", "--template", action="store", type="string", dest="template", required=True, help=""" Script template (sample templates are included in /usr/share/haizea/etc) """)) self.optparser.add_option( Option("-m", "--only-missing", action="store_true", dest="onlymissing", help=""" If specified, the generated script will only run the configurations that have not already produced a datafile. This is useful when some simulations fail, and you don't want to have to rerun them all. """)) def run(self): self.parse_options() configfile = self.opt.conf multiconfig = HaizeaMultiConfig.from_file(configfile) try: from mako.template import Template except Exception, e: print "You need Mako Templates for Python to run this command." print "You can download them at http://www.makotemplates.org/" exit(1) configs = multiconfig.get_configs() etcdir = os.path.abspath(self.opt.confdir) if not os.path.exists(etcdir): os.makedirs(etcdir) templatedata = [] for c in configs: profile = c.get_attr("profile") tracefile = c.get("tracefile") injfile = c.get("injectionfile") datafile = c.get("datafile") configname = generate_config_name(profile, tracefile, injfile) if not self.opt.onlymissing or not os.path.exists(datafile): configfile = etcdir + "/%s.conf" % configname templatedata.append((configname, configfile)) template = Template(filename=self.opt.template) print template.render(configs=templatedata, etcdir=etcdir)
def get_configs(self): profiles = self.get_profiles() tracefiles = self.get_trace_files() injectfiles = self.get_inject_files() configs = [] for profile in profiles: for tracefile in tracefiles: for injectfile in injectfiles: profileconfig = ConfigParser.ConfigParser() commonsections = [ s for s in self.config.sections() if s.startswith("common:") ] profilesections = [ s for s in self.config.sections() if s.startswith(profile + ":") ] sections = commonsections + profilesections for s in sections: s_noprefix = s.split(":")[1] items = self.config.items(s) if not profileconfig.has_section(s_noprefix): profileconfig.add_section(s_noprefix) for item in items: profileconfig.set(s_noprefix, item[0], item[1]) # The tracefile section may have not been created if not profileconfig.has_section("tracefile"): profileconfig.add_section("tracefile") # Add tracefile option profileconfig.set("tracefile", "tracefile", tracefile) # Add injected file option if injectfile != None: profileconfig.set("tracefile", "injectionfile", injectfile) # Add datafile option datadir = self.config.get(self.MULTI_SEC, self.DATADIR_OPT) datafilename = generate_config_name( profile, tracefile, injectfile) datafile = os.path.expanduser(datadir + "/" + datafilename + ".dat") # The accounting section may have not been created if not profileconfig.has_section("accounting"): profileconfig.add_section("accounting") profileconfig.set("accounting", "datafile", datafile) # Set "attributes" option (only used internally) attrs = { "profile": profile, "tracefile": tracefile, "injectfile": injectfile } # TODO: Load additional attributes from trace/injfiles attrs_str = ",".join( ["%s=%s" % (k, v) for (k, v) in attrs.items()]) if profileconfig.has_option("accounting", "attributes"): attrs_str += ",%s" % profileconfig.get( "general", "attributes") profileconfig.set("accounting", "attributes", attrs_str) try: c = HaizeaConfig(profileconfig) except ConfigException, msg: print >> sys.stderr, "Error in configuration file:" print >> sys.stderr, msg exit(1) configs.append(c)