def LoadrpcFile(self,rpc_FileName): def PrintWarning(Text): self.PrintWarning("<Line %d> in rpc_file %s - %s" % \ (LineIndex,self.rpc_FileName,Text) ) self.rpc_FileName = rpc_FileName self.Title = None self.TaskList = None self.CompetitorList = None if not os.path.isfile(self.GetPath() + r'/' + self.rpc_FileName): raise EXC.rpcFileNotFoundError(self.rpc_FileName,self.Path) self.GetOutputHandle().PrintRuntimeInfo("Reading rpc_file ...") LineIndex = 0 for line in open(self.GetPath() + r'/' + self.rpc_FileName): line = line.rstrip() if len(line) == 0: continue line = line.split() key,content = line[0],line[1:] if key == CNT.RPC_KEY_TITLE: if not content: self.PrintWarning("EmptyKey %s,SKipped" % key) continue self.SetTitle(content[0]) elif key == CNT.RPC_KEY_TASK: self.ClearTaskList() self.GetOutputHandle().PrintRuntimeInfo("\nAdd Tasks ...") for tk_name in content: self.AddTask(tk_name) elif key == CNT.RPC_KEY_COMPETITOR: self.ClearCompetitorList() self.GetOutputHandle().PrintRuntimeInfo("\nAdd Competitors ...") for name in content: self.AddCompetitor(name) else: PrintWarning("Unknown Key %s,Omitted" % key) if self.Title == None: raise EXC.KeyTitleNotFound(self.Getrpc()) if self.TaskList == None: raise EXC.KeyTaskNotFound(self.Getrpc()) if self.CompetitorList == None: raise EXC.KeyCompetitorNotFound(self.Getrpc()) self.GetOutputHandle().PrintRuntimeInfo("")
def ReadTask(self): def PrintWarning(txt): self.PrintWarning("<Line %d> in rtc_file of %s:%s" % (LineIndex,self.TaskName,txt)) def DealPoint(IndexSet,Pnt): for Index in IndexSet: for i in range(Index[0],Index[1] + 1): Pnt.SetIndex(i) try: Pnt.Check(self.GetDataPath(),self.TaskName) except EXC.FileNotFoundError: raise EXC.InvalidInputOutputFile(self.TaskName,LineIndex) self.AddPoint(Pnt) self.__init__(self.Path,self.TaskName,self.OutputHandle) rtc_filename = CNT.TK_DEF_RTC_FILENAME % self.TaskName if not os.path.isfile(self.Path + r'/' + rtc_filename): raise EXC.rtcFileNotFoundError(self.TaskName) flag_Global = True LineIndex = 0 IndexSet = [] Pnt = TestPoint() for line in open(self.Path + r'/' + rtc_filename): LineIndex += 1 line = line.rstrip() if len(line) == 0: continue line = line.split() if len(line) == 1: PrintWarning("EmptyKey %s,Skipped" % line[0]) continue key,content = line[0],line[1] if flag_Global: if key == CNT.RTC_KEY_SRCIN: self.SetSrcIn(content) elif key == CNT.RTC_KEY_SRCOUT: self.SetSrcOut(content) elif key == CNT.RTC_KEY_SRC: self.SetSrc(content) elif key == CNT.RTC_KEY_POINTSET: try: IndexSet = [(int(x.split(",")[0]),int(x.split(",")[1])) for x in content.split(";") if len(x.rstrip())] except Exception: raise EXC.InvalidPointSet(self.TaskName,LineIndex) flag_Global = False else: PrintWarning("Unknown key %s in Global Area,Omitted" % key) else: if key == CNT.RTC_KEY_POINTSET: DealPoint(IndexSet,Pnt) Pnt = TestPoint() try: IndexSet = [(int(x.split(",")[0]),int(x.split(",")[1])) for x in content.split(";") if len(x.rstrip())] except Exception: raise EXC.InvalidPointSet(self.TaskName,LineIndex) elif key == CNT.RTC_TPKEY_TIMELIM: Pnt.SetTimeLimit(content) elif key == CNT.RTC_TPKEY_MEMLIM: Pnt.SetMemLimit(content) elif key == CNT.RTC_TPKEY_INPUT: Pnt.SetInput(content) elif key == CNT.RTC_TPKEY_OUTPUT: Pnt.SetOutput(content) elif key == CNT.RTC_TPKEY_SCORE: Pnt.SetScore(content) elif key == CNT.RTC_TPKEY_CMPMODE: Checker = None if len(line) > 2: Checker = line[2] if Checker: Pnt.SetCmpMode(content,Checker) else: Pnt.SetCmpMode(content) else: PrintWarning("Unkown key %s in PointSet,Omitted" % key) if IndexSet: DealPoint(IndexSet,Pnt)