def __read_usage(self, path): if not os.path.exists(path): msg = 'no such file: "%s"' % path Error(self.clsname).abort(msg) # read the file f = TextFio(path) if f.open() < 0: Error(self.clsname).abort(f.error()) lines = f.read() f.close() # find pattern usage = None patt = '#(define|undef)\s+USE_CLOSED_SRC' for line in lines: m = re.match(patt, line) if m: matched = m.group(1) if matched == 'define': usage = CSU.USE if matched == 'undef': usage = CSU.UNUSE break if usage is None: msg = 'bad closed-src-header' Error(self.clsname).abort(msg) return usage
def get_username(fname): fio = TextFio(fname) if fio.open() < 0: Error(prog).error(fio.error()) return '' lines = fio.read() fio.close() return lines[0]
def take_cmakelists_ver(fname): fio = TextFio(fname, 'r', encoding='utf8', size=16384) ver = None patt = r'(SPRINGHEAD_PROJECT_VERSION [\d\.]+)' if fio.open() == 0: for line in fio.read(): m = re.search(patt, line) if m: ver = m.group(1) break fio.close() return ver
def grep(path, patt): f = TextFio(path) if f.open() < 0: Error(prog).abort(f.error()) lines = f.read() f.close() # count = 0 for line in lines: count += 1 m = re.search(patt, line) if m: print('%d: %s' % (count, line))
def __merge_log(self, kind, data, logf, cmnd, step): # arguments: # kind: Kind of process. # 1: Next arg 'data' is a list of log data. # 2: Read log data from the file named 'data'. # data: See above. # logf: Log file object. # step: Execution step (RST.BLD or RST.RUN). # cmnd: Command string to be executed (str). if logf is None: return # make header part cwd = self.dirpath if self.dirpath else os.getcwd() cwd = Util.upath(cwd).split('/') head1 = '*** %s: %s ***' % (cwd[-2], cwd[-1]) head2 = '%% %s' % cmnd if step == RST.BLD: title = [head1, head2, ''] else: title = [head1] # merge if kind == 1: # data is a list of string logf.writelines(title) logf.writelines(data) elif kind == 2: # data is the file name to be read fsize = os.stat(data).st_size tmpf = TextFio(data, size=fsize) if tmpf.open() < 0: msg = 'build' if step == RST.BLD else 'run' msg += '_w: open error: "%s"' % (name, data) Error(self.clsname).error(msg) else: logf.writelines(title) lines = tmpf.read() logf.writelines(lines) tmpf.close() else: msg = 'merge_log: bad kind: %s' % kind Error(self.clsname).abort(msg) logf.close()
def __select_errors(self, fname, step): # arguments: # fname: Log file name (str). # step: Execute step (RST.BLD or RST.RUN). # returns: List of error messages (str[]). fsize = os.stat(fname).st_size fobj = TextFio(fname, size=fsize) if fobj.open() < 0: msg = 'build' if step == RST.BLD else 'run' msg += '_s: open error: "%s"' % fname Error(self.clsname).error(msg) lines = fobj.read() fobj.close() patt = re.compile(' error', re.I) errors = [] for line in lines: if patt.search(line): errors.append(line) return errors
def __build_w(self, logf, tmpdir): # arguments: # logf: Log file object. # tmpdir: Temporary directory for logging. # self.args: Other parameters. [slnfile, opts, outfile, force] = self.args outdir = self.__dirpart(outfile).replace('x86', 'Win32') tmplog = 'log/%s_%s_%s_%s_build.log' % \ (self.clsname, self.ccver, self.arch, config) FileOp().rm(tmplog) if self.verbose > 1: print('build solution (Windows)') print(' slnfile: %s' % slnfile) print(' opts: %s' % opts) print(' outdir: %s' % outdir) print(' errlog: %s' % errlog) print(' tmplog: %s' % tmplog) print(' force: %s' % force) vs = VisualStudio(self.ccver, self.verbose) vs.solution(slnfile) vs.set(VisualStudio.OUTDIR, outdir, force) vs.set(VisualStudio.LOGFILE, tmplog) vs.set(VisualStudio.DRYRUN, self.dry_run) if vs.has_error(): self.E.print(vs.has_error()) stat = vs.build(self.arch, opts) if logf: tmpf = TextFio(tmplog) if tmpf.open() < 0: msg = '__build_w: open error: "%s"' % tmplog self.E.print(msg, alive=True) else: lines = tmpf.read() logf.writelines(lines) tmpf.close() return stat
# Scripts # if options.python: python = options.python createmkf = '%s %s/create_mkf.py -P %s' % (python, runswigdir, python) # ---------------------------------------------------------------------- # Main process # ---------------------------------------------------------------------- # Read project dependency definition file. # fio = TextFio('%s/%s' % (etcdir, projfile)) if fio.open() < 0: E.print(fio.error()) lines = fio.read() fio.close() # Do the job. # curr_proj = os.getcwd().split(os.sep)[-1].lower() for line in lines: vprint('Def: [%s]' % line, 1) fields = line.split() proj = fields[0] dept = fields[1] if len(fields) > 1 else None vprint('proj: %s <- %s' % (proj, dept), 1) # Change to target directory. cwd = os.getcwd() target_dir = '%s/%s' % (srcdir, proj)
# Scripts # if options.python: python = options.python createmkf = '%s %s/create_mkf.py -P %s' % (python, runswigdir, python) # ---------------------------------------------------------------------- # Main process # ---------------------------------------------------------------------- # Read project dependency definition file. # fio = TextFio("%s/%s" % (etcdir, projfile)) if fio.open() < 0: Error(prog).error(fio.error()) lines = fio.read() fio.close() # Remove cmake generated dummy files. # projs = [] for line in lines: proj = line.split() if (len(proj) > 0): projs.append(proj[0]) cwd = os.getcwd() for proj in projs: os.chdir('../%s' % proj) fio = TextFio('RunSwig_gen_files.txt') if fio.open() < 0: Error(prog).error(fio.error())
verbose = options.verbose logfile = args[0] if verbose: outname = outfile if outfile != sys.stdout else 'stdout' print('logfile: %s' % logfile) print('outfile: %s' % outname) # ---------------------------------------------------------------------- # Read log data. # f = TextFio(logfile) if f.open() < 0: print('%s: %s' % (prog, f.error())) sys.exit(-1) f.read() lines = f.lineinfo() f.close() # ---------------------------------------------------------------------- # Abbreviations for run status. # def abbrev_sub(string, find_str): return string.find(find_str) >= 0 def abbrev(stat): if abbrev_sub(stat, 'Need Intervention'): return '**NI**' if abbrev_sub(stat, 'Assertion faild'): return 'Assert' if abbrev_sub(stat, 'interrunpted:'): return 'INTR' if abbrev_sub(stat, 'Access Violation'): return 'AccV' if abbrev_sub(stat, 'SEH:'): return '*SEH*'
def run(self, dirpath, exefile, args, logfile, addpath=None, timeout=None, pipeprocess=None): if self.verbose: print('run program') print(' dirpath: %s' % dirpath) print(' exefile: %s' % exefile) print(' args: %s' % args) print(' logfile: %s' % logfile) print(' addpath: %s' % addpath) print(' timeout: %s' % timeout) print(' pipe: %s' % pipeprocess) # go to target directory. dirsave = self.__chdir('run', dirpath) if self.verbose: cwd = Util.upath(os.getcwd()) print('run: in directory "%s"' % cwd) if Util.is_windows(): arch = 'x64' if self.arch == 'x64' else 'Win32' bindir = '%s/%s/%s' % (self.ccver, arch, self.config) exefile = '%s/%s' % (bindir, exefile) if self.verbose: print(' exefile: %s' % exefile) if not os.path.exists(exefile): print('fun: no such file "%s"' % exefile) return -1 # use following temporary log file. tmpdir = self.__dirpart(logfile) if Util.is_unix(): config = config.replace('-', '') tmplog = 'log/%s_%s_%s_%s_run.log' % \ (self.clsname, self.ccver, self.arch, self.config) # prepare log file (append mode). logf = self.__open_log(logfile, 'a', 'go') # execute program. if pipeprocess: proc1 = Proc(self.verbose, self.dry_run) proc2 = Proc(self.verbose, self.dry_run) proc1.exec('%s %s' % (exefile, args), addpath=addpath, stdin=Proc.PIPE, stdout=tmplog, stderr=Proc.STDOUT) proc2.exec(pipeprocess, addpath=addpath, stdout=Proc.PIPE) proc2.wait() stat = proc1.wait(timeout) else: proc1 = Proc(self.verbose, self.dry_run) proc1.exec('%s %s' % (exefile, args), stdout=tmplog, stderr=Proc.STDOUT) stat = proc1.wait(timeout) # merge log info. if logf: tmpf = TextFio(tmplog) if tmpf.open() < 0: msg = '__run: open error: "%s"' % tmplog self.E.print(msg, alive=True) else: lines = tmpf.read() logf.writelines(lines) tmpf.close() logf.close() os.chdir(dirsave) return stat