def main(options, args): # Create top level logger. logger = log.get_logger(name='qcheck', options=options) if options.input_filename: # This section is for reading an Excel file that has the usual # sheets in it (targets, envcfg, etc.) # Append any directory path supplied in options.input_filename # onto the end of the options.input_dir value. input_dir = os.path.join(options.input_dir, os.path.dirname(options.input_filename)) # Parse the input filename so we can get the proposal name. input_filename = os.path.basename(options.input_filename) propname, ext = input_filename.split('.') if ext in filetypes.QueueFile.excel_ext: propdict = {} key = propname.upper() propdict[key] = entity.Program(key, hours=0, category='') progFile = filetypes.ProgramFile(input_dir, logger, propname, propdict) else: logger.error("File extension '%s' is not a valid file type. Must be one of %s." % (ext, filetypes.QueueFile.excel_ext)) sys.exit(1) else: # This section is for reading a directory that contains CSV # files, i.e., targets.csv, inscfg.csv, etc. dirname = os.path.dirname(options.input_dir) propname = os.path.basename(options.input_dir) propdict = {} key = propname.upper() propdict[key] = entity.Program(key, hours=0, category='') progFile = filetypes.ProgramFile(dirname, logger, propname, propdict, file_ext='csv') logger.info('Warning count is %d' % progFile.warn_count) logger.info('Error count is %d' % progFile.error_count)
def load_program(self, propname): self.logger.info("attempting to read phase 2 info for '%s'" % (propname)) try: pf = filetypes.ProgramFile(self.input_dir, self.logger, propname, self.programs_qf.programs_info, file_ext=self.input_fmt) # Set telcfg telcfg_qf = pf.cfg['telcfg'] self.telcfg_qf_dict[propname] = telcfg_qf self.model.set_telcfg_qf_dict(self.telcfg_qf_dict) # Set inscfg inscfg_qf = pf.cfg['inscfg'] self.inscfg_qf_dict[propname] = inscfg_qf self.model.set_inscfg_qf_dict(self.inscfg_qf_dict) # Set envcfg envcfg_qf = pf.cfg['envcfg'] self.envcfg_qf_dict[propname] = envcfg_qf self.model.set_envcfg_qf_dict(self.envcfg_qf_dict) # Set targets tgtcfg_qf = pf.cfg['targets'] self.tgtcfg_qf_dict[propname] = tgtcfg_qf self.model.set_tgtcfg_qf_dict(self.tgtcfg_qf_dict) # Finally, set OBs self.ob_qf_dict[propname] = pf.cfg['ob'] self.model.set_ob_qf_dict(self.ob_qf_dict) return True except Exception as e: errmsg = "error attempting to read phase 2 info for '%s'\n" % ( propname) errmsg += "\n".join([e.__class__.__name__, str(e)]) try: (type, value, tb) = sys.exc_info() tb_str = "\n".join(traceback.format_tb(tb)) except Exception as e: tb_str = "Traceback information unavailable." errmsg += tb_str self.logger.error(errmsg) self.controller.gui_do(self.controller.show_error, errmsg, raisetab=True) return False
def initialize_model_cb(self, widget): self.input_dir = self.w.input_dir.get_text().strip() self.input_fmt = self.controller.input_fmt try: # read weights self.weights_qf = filetypes.WeightsFile(self.input_dir, self.logger, file_ext=self.input_fmt) # Load "Weights" Tab if not self.view.gpmon.has_plugin('weightstab'): self.view.load_plugin('weightstab', self.spec_weights) self.model.set_weights_qf(self.weights_qf) # read schedule self.schedule_qf = filetypes.ScheduleFile(self.input_dir, self.logger, file_ext=self.input_fmt) # Load "Schedule" Tab if not self.view.gpmon.has_plugin('scheduletab'): self.view.load_plugin('scheduletab', self.spec_schedule) self.model.set_schedule_qf(self.schedule_qf) # read proposals self.programs_qf = filetypes.ProgramsFile(self.input_dir, self.logger, file_ext=self.input_fmt) if not self.view.gpmon.has_plugin('programstab'): self.view.load_plugin('programstab', self.spec_programs) self.model.set_programs_qf(self.programs_qf) # read observing blocks self.ob_qf_dict = {} self.tgtcfg_qf_dict = {} self.envcfg_qf_dict = {} self.inscfg_qf_dict = {} self.telcfg_qf_dict = {} self.oblist_info = [] propnames = list(self.programs_qf.programs_info.keys()) propnames.sort() for propname in propnames: pf = filetypes.ProgramFile(self.input_dir, self.logger, propname, self.programs_qf.programs_info, file_ext=self.input_fmt) # Set telcfg telcfg_qf = pf.cfg['telcfg'] self.telcfg_qf_dict[propname] = telcfg_qf self.model.set_telcfg_qf_dict(self.telcfg_qf_dict) # Set inscfg inscfg_qf = pf.cfg['inscfg'] self.inscfg_qf_dict[propname] = inscfg_qf self.model.set_inscfg_qf_dict(self.inscfg_qf_dict) # Set envcfg envcfg_qf = pf.cfg['envcfg'] self.envcfg_qf_dict[propname] = envcfg_qf self.model.set_envcfg_qf_dict(self.envcfg_qf_dict) # Set targets tgtcfg_qf = pf.cfg['targets'] self.tgtcfg_qf_dict[propname] = tgtcfg_qf self.model.set_tgtcfg_qf_dict(self.tgtcfg_qf_dict) # Finally, set OBs self.ob_qf_dict[propname] = pf.cfg['ob'] #self.oblist_info.extend(self.oblist[propname].obs_info) self.model.set_ob_qf_dict(self.ob_qf_dict) except Exception as e: self.logger.error("Error initializing: %s" % (str(e)))
def initialize_model(self): try: # read weights self.logger.info("reading weights from %s" % (self.input_dir)) self.weights_qf = filetypes.WeightsFile(self.input_dir, self.logger, file_ext='xlsx') self.model.set_weights_qf(self.weights_qf) # read schedule self.logger.info("reading schedule from %s" % (self.input_dir)) self.schedule_qf = filetypes.ScheduleFile(self.input_dir, self.logger, file_ext='xlsx') self.model.set_schedule_qf(self.schedule_qf) # read proposals self.logger.info("reading proposals from %s" % (self.input_dir)) self.programs_qf = filetypes.ProgramsFile(self.input_dir, self.logger, file_ext='xlsx') self.model.set_programs_qf(self.programs_qf) # read observing blocks self.ob_qf_dict = {} self.tgtcfg_qf_dict = {} self.envcfg_qf_dict = {} self.inscfg_qf_dict = {} self.telcfg_qf_dict = {} self.oblist_info = [] propnames = list(self.programs_qf.programs_info.keys()) propnames.sort() for propname in propnames: pf = filetypes.ProgramFile(self.input_dir, self.logger, propname, self.programs_qf.programs_info, file_ext=self.input_fmt) # Set telcfg telcfg_qf = pf.cfg['telcfg'] self.telcfg_qf_dict[propname] = telcfg_qf self.model.set_telcfg_qf_dict(self.telcfg_qf_dict) # Set inscfg inscfg_qf = pf.cfg['inscfg'] self.inscfg_qf_dict[propname] = inscfg_qf self.model.set_inscfg_qf_dict(self.inscfg_qf_dict) # Set envcfg envcfg_qf = pf.cfg['envcfg'] self.envcfg_qf_dict[propname] = envcfg_qf self.model.set_envcfg_qf_dict(self.envcfg_qf_dict) # Set targets tgtcfg_qf = pf.cfg['targets'] self.tgtcfg_qf_dict[propname] = tgtcfg_qf self.model.set_tgtcfg_qf_dict(self.tgtcfg_qf_dict) # Finally, set OBs self.ob_qf_dict[propname] = pf.cfg['ob'] #self.oblist_info.extend(self.oblist[propname].obs_info) self.model.set_ob_qf_dict(self.ob_qf_dict) except Exception as e: self.logger.error("Error initializing: %s" % (str(e)))