def output(fname, lines): fobj = TextFio(fname, 'w', encoding='utf8') if fobj.open() < 0: Error(prog).error(fobj.error()) if fobj.writelines(lines, '\n') < 0: Error(prog).error(fobj.error()) fobj.close()
def __init_log(self, path, step, errlog=None): # arguments: # path: Log file path (str). # step: Execution step (RST.BLD or RST.RUN). # errlog: Error log or not (RST.ERR or None). if path is None: return None # file header info testids = { TESTID.STUB: 'スタブ', TESTID.EMBPYTHON: 'EmbPython', TESTID.TESTS: '', TESTID.SAMPLES: 'サンプル', TESTID.OTHER: 'その他' } steps = {RST.BLD: 'ビルド', RST.RUN: '実行'} datestr = '日付 : %s' % Util.date() err = 'エラー' if errlog == RST.ERR else '' header = '--- %s%s%sのログ ---' % \ (testids[self.testid], steps[step], err) # write header f = TextFio(path, 'w', encoding=self.encoding) if f.open() < 0: msg = '__init_log: open error "%s"', path Error(self.clsname).error(msg) return f.writeline(datestr) f.writeline(header) f.writeline('') f.close() print('init logfile: "%s"' % path)
def output(fname): fobj = TextFio(fname, 'w', encoding='utf8') if fobj.open() < 0: E.print(fobj.error(), exitcode=0) if fobj.writelines(lines, '\n') < 0: E.print(fobj.error(), exitcode=0) fobj.close()
def make_makefile(module, fname, interfs, inchdrs, srchdrs): target = '%s/EP%s.cpp' % (embpythondir, module) dependencies = [] dependencies.extend(interfs) dependencies.extend(inchdrs) dependencies.extend(srchdrs) if verbose: print(' target: [%s]' % target) print(' dependencies: [%s]' % dependencies) lines = [] lines.append('# Do not edit. RunSwig_EmbPython will update this file.') lines.append('# File: %s' % fname) lines.append('') lines.append('all:\t%s' % target) lines.append('%s:\t%s' % (target, ' '.join(dependencies))) lines.append('\t@python %s %s' % (swig, module)) lines.append('') for f in dependencies: lines.append('%s:' % f) fio = TextFio(fname, 'w') if fio.open() != 0: msg = '%s: can not open file (write)' % fname Error(prog).abort(msg) rc = fio.writelines(lines) fio.close() if rc != 0: msg = '%s: write failed' % fname Error(prog).abort(msg)
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 output(fname, lines): if verbose: print('%s:' % fname) for line in lines: print(' %s' % line) fobj = TextFio(fname, 'w', encoding='utf8') if fobj.open() < 0: Error(prog).put(fobj.error(), exitcode=0, alive=True) if fobj.writelines(lines, '\n') < 0: Error(prog).put(fobj.error(), exitcode=0, alive=True) fobj.close()
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 __open_log(self, fname, fmode, prefix): # arguments: # logfile: Log file path. # returns: Log file object. if self.dry_run: print(' open log file "%s"' % fname) return None logdir = self.__dirpart(fname) if logdir != '': os.makedirs(logdir, exist_ok=True) logf = TextFio(fname, mode=fmode) if logf.open() < 0: msg = '%s: open error: "%s"' % (prefix, fname) self.E.print(msg, alive=True) logf = None return logf
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
def write(self): if not self.register: if self.verbose: print('write: has no permission') return # lines = [] lines.append('# %s' % self.filename) # lines.append('') lines.append('[%s]' % self.PATH) for key in self.path_list.keys(): line = '%s\t%s' % (key, self.path_list[key]) lines.append(line) # lines.append('') lines.append('[%s]' % self.PROG) for key in self.prog_list.keys(): line = '%s\t%s' % (key, self.prog_list[key]) lines.append(line) # lines.append('') lines.append('[%s]' % self.DATA) for key in self.data_list.keys(): line = '%s\t%s' % (key, self.data_list[key]) lines.append(line) # if self.verbose > 1: for line in lines: print('[%s]' % line) fio = TextFio(self.path, 'w', verbose=self.verbose) if fio.open() < 0: return -1 if fio.writelines(lines) < 0: fio.close() return -2 fio.close() return 0
def __open_log(self, fname, fmode, step): # arguments: # fname: Log file path. # fmode: File open mode ('r', 'w' or 'a'). # prefix: Error message prefix (str). # returns: File object. if self.dry_run: print(' open log file "%s"' % fname) return None if fname is None: return None logdir = self.__dirpart(fname) if logdir != '': os.makedirs(logdir, exist_ok=True) logf = TextFio(fname, mode=fmode, encoding=self.encoding) if logf.open() < 0: msg = 'build' if step == RST.BLD else 'run' msg += ': open error: "%s"' % fname Error(self.clsname).error(msg) logf = None return logf
macro = r'#undef USE_CLOSED_SRC' if os.path.exists(closed): if os.path.isdir(closed): macro = r'#define USE_CLOSED_SRC' else: print('%s: Warning: "%s" exists but not a directory' % (prog, closed)) lines = [] lines.append(r'// This file is generated by Springhead system.') lines.append(r'') lines.append(r'// Use Springhead/closed source or not.') lines.append(macro) # ---------------------------------------------------------------------- # ファイルに書き出す # fio = TextFio(header_file, 'w') if fio.open() != 0: Error(prog).error('can not open file "%s"' % header_file) if fio.writelines(lines) != 0: Error(prog).error('write failed on file %s"' % header_file) fio.close() print('%s: "%s" written with "%s"' % (prog, header_file, macro)) # ---------------------------------------------------------------------- # 処理終了 # os.chdir(cwd) sys.exit(0) # end: CheckClosedSrc.py
if verbose: print('%s:' % prog) print(' report file: %s' % res_file) print(' output file: %s' % outfile) print(' out_type: %s' % out_type) if out_type == 'r': print(' platform: %s' % platform) print(' config: %s' % config) # ---------------------------------------------------------------------- # Main process. # res = TestResult(res_file, scratch=False, verbose=0) if out_type == 'r': lines = res.edit_result_log(platform, config) for line in lines: print(line) if outfile: fio = TextFio(outfile, 'w', encoding='cp932') if fio.open() < 0: Error(prog).abort('can\'t open "%s"' % outfile) fio.writelines(lines) fio.close() if out_type == 'd': res.dump() sys.exit(0) # end: GenResultLog.py
# if options.version: E.print('Version %s' % version, prompt=None) sys.exit(0) # if len(args) != 1: E.print("incorrect number of arguments") # output file name outfile = args[0] # ---------------------------------------------------------------------- # Open output file # f = TextFio(outfile, 'a') if f.open() < 0: E.print(f.error()) # ---------------------------------------------------------------------- # Copy from stdin to outfile # while True: line = sys.stdin.read() if line == '': break f.writeline(line) f.close() sys.exit(0) # dnd: log_append.py
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
lines.append('$(INCHDRS):\t') lines.append('\t') lines.append('$(SRCHDRS):\t') lines.append('\t') if verbose: for line in lines: print(line) # ---------------------------------------------------------------------- # ファイルに書き出す. # fobj = TextFio(makefile, 'w', encoding='utf8') if fobj.open() < 0: error.print(fobj.error()) if fobj.writelines(lines, '\n') < 0: error.print(fobj.error()) fobj.close() # ---------------------------------------------------------------------- # 処理終了. # if trace: print('LEAVE: %s' % prog) sys.stdout.flush() sys.exit(0) # end create_mkf.py
# ---------------------------------------------------------------------- # Make test date/time information file. # if check_exec('DAILYBUILD_GEN_HISTORY', unix_gen_history): Print('making test date information') os.chdir('%s/log' % TestDir) # date_and_time = Util.now('%Y-%m%d %H:%M:%S') lines = [ '** DO NOT EDIT THIS FILE **', 'generated by "%s"' % prog, '- - - %s' % date_and_time ] fio = TextFio(date_record, 'w') if fio.open() == 0: fio.writelines(lines) fio.close() else: Error(prog).error('cannot make "Test.date".') os.chdir(repository) # ---------------------------------------------------------------------- # Copy log files to the web server. # if check_exec('DAILYBUILD_COPYTO_BUILDLOG', unix_copyto_buildlog): Print('copying log files to web') # if Util.is_unix(): tohost = '%s@%s' % (log_user, log_server) todir = '/home/WWW/docroots/springhead/dailybuild/log.unix'