def _CompatGuessSolution(self, ui): wrapped_auto_code = self._WrapSolution(codes.AutoCode) for filename in files.ListDir(self.src_dir): try: code = wrapped_auto_code(filename, self.src_dir, self.out_dir) self._codes.append(code) except codes.UnknownCodeExtensionException: continue
def ListInvalidTestCases(self): """Enumerate invalid test cases.""" testcases = [] for infile in files.ListDir(self.out_dir, False): infile = os.path.join(self.out_dir, infile) if not infile.endswith(consts.INVALID_EXT): continue if not os.path.isfile(infile): continue testcases.append(test.TestCase(self, infile)) self._SortTestCases(testcases) return testcases
def LoadPackage(package_name): assert package_name package_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, *package_name.split('.')) for filename in files.ListDir(package_dir): if (os.path.isdir(os.path.join(package_dir, filename)) and os.path.isfile( os.path.join(package_dir, filename, '__init__.py'))): LoadPackage('%s.%s' % (package_name, filename)) elif filename.endswith('.py'): module_name = os.path.splitext(filename)[0] if module_name != '__init__': LoadModule('%s.%s' % (package_name, module_name))
def _ChainLoad(self, ui): # Chain-load problems. self.problems = [] for name in files.ListDir(self.base_dir): path = os.path.join(self.base_dir, name) if targets.registry.Problem.CanLoadFrom(path): problem = targets.registry.Problem(name, path, self) try: problem.Load(ui) self.problems.append(problem) except targets.ConfigurationError: ui.errors.Exception(problem) self.problems.sort(key=lambda a: (a.id, a.name))
def _ChainLoad(self, ui): # Chain-load solutions. self.solutions = [] for name in sorted(files.ListDir(self.base_dir)): path = os.path.join(self.base_dir, name) if targets.registry.Solution.CanLoadFrom(path): solution = targets.registry.Solution(name, path, self) try: solution.Load(ui) self.solutions.append(solution) except targets.ConfigurationError: ui.errors.Exception(solution) # Chain-load testsets. self.testsets = [] for name in sorted(files.ListDir(self.base_dir)): path = os.path.join(self.base_dir, name) if targets.registry.Testset.CanLoadFrom(path): testset = targets.registry.Testset(name, path, self) try: testset.Load(ui) self.testsets.append(testset) except targets.ConfigurationError: ui.errors.Exception(testset)
def _ExecForCompile(self, args): for f in files.ListDir(self.src_dir): srcpath = os.path.join(self.src_dir, f) dstpath = os.path.join(self.out_dir, f) if os.path.isdir(srcpath): files.CopyTree(srcpath, dstpath) else: files.CopyFile(srcpath, dstpath) if len(self.dependency) > 0: if libdir is None: raise IOError('library_dir is not defined.') else: for f in self.dependency: if not os.path.exists(os.path.join(libdir, f)): raise IOError('%s is not found in %s.' % (f, libdir)) files.CopyFile(os.path.join(libdir, f), self.out_dir) with open(os.path.join(self.out_dir, self.log_name), 'w') as outfile: yield (yield self._ExecInternal(args=args, cwd=self.out_dir, stdin=files.OpenNull(), stdout=outfile, stderr=subprocess.STDOUT))