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 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 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 __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 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))
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
patterns = ['0', '-'] lines3, c = f.replace(patterns, lines3) print_info(lines3, c) print() patterns = [['--1', '1--'], ['com', 'Com']] lines3, c = f.replace(patterns, lines3) print_info(lines3, c) print() print('---------------------------------------') print('-- write file --') for enc in encs: fname = 'test/foo.' + enc f = TextFio(fname, 'w', encoding=enc, verbose=verbose) if f.open() < 0: Print(f.error()) sys.exit(-1) lines = ['# %s' % fname, '', '', '', 'end'] if enc == 'ascii': lines[2] = ' This is the line to verify encoding.' else: lines[2] = ' これはエンコディングを確認するための行.' f.writelines(lines) f.close() f = TextFio(fname, verbose=verbose) if f.open() < 0: Print(f.error()) sys.exit(-1) leaf = fname.split('/')[-1] Print('"%s": encoding: %s (verify)' % (leaf, f.get_encoding()))
# ---------------------------------------------------------------------- # 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()
#make = 'gmake' if unix else 'nmake /NOLOGO' opts = '-P %s' % python makemanager = '%s "%s/make_manager.py" %s' % (python, runswigdir, opts) # ---------------------------------------------------------------------- # Globals (part 2) # proc = Proc(verbose=verbose, dry_run=dry_run) f_op = FileOp(verbose=verbose) # ---------------------------------------------------------------------- # プロジェクト依存定義ファイルを読み込む. # fio = TextFio('%s/%s' % (etcdir, projfile)) if fio.open() < 0: Error(prog).error(fio.error()) lines = fio.read() fio.close() # ---------------------------------------------------------------------- # 各プロジェクト毎に処理を行なう. # for line in lines: fields = line.split() if len(fields) < 1: continue proj = fields[0] dept = fields[1] if len(fields) > 1 else None if debug: print('proj: %s <- %s' % (proj, dept))
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
# get options and input file name outfile = options.outfile if options.outfile else sys.stdout 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'
make = 'make' if unix else 'nmake' opts = '-P %s' % python makemanager = '%s %s/make_manager.py %s' % (python, runswigdir, opts) # ---------------------------------------------------------------------- # Globals (part 2) # proc = Proc(verbose=verbose, dry_run=debug) f_op = FileOp(verbose=verbose) # ---------------------------------------------------------------------- # プロジェクト依存定義ファイルを読み込む. # fio = TextFio('%s/%s' % (etcdir, projfile)) if fio.open() < 0: error.print(fio.error()) lines = fio.read() fio.close() # ---------------------------------------------------------------------- # 各プロジェクト毎に処理を行なう. # for line in lines: fields = line.split() proj = fields[0] dept = fields[1] if len(fields) > 1 else None if debug: print('proj: %s <- %s' % (proj, dept)) print() print('*** %s ***' % proj)
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: E.abort(fobj.error()) if fobj.writelines(lines, '\n') < 0: E.abort(fobj.error()) fobj.close() # ---------------------------------------------------------------------- # 処理終了. # if trace: print('LEAVE: %s' % prog) sys.stdout.flush() sys.exit(0) # end create_mkf.py