Пример #1
0
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()
Пример #2
0
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()
Пример #3
0
	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
Пример #4
0
    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
Пример #5
0
	def __head(self, fname, maxlines):
		# arguments:
		#   file:	File path (str).
		#   maxlines:	Maximum lines to be printed (int).

		if not os.path.exists(fname):
			return 
		f = TextFio(fname)
		if f.open() < 0:
Пример #6
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()
Пример #7
0
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]
Пример #8
0
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)
Пример #9
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
Пример #10
0
 def __init__(self, path, sep=None, overwrite=True, desig='#', verbose=0):
     self.clsname = self.__class__.__name__
     self.version = 3.0
     #
     self.sep = sep
     self.overwrite = overwrite
     self.desig = desig
     self.verbose = verbose
     #
     self.defined_sections = [self.DEFAULT]
     self.curr_section = self.DEFAULT
     self.dict = {}
     self.fobj = TextFio(path, verbose=verbose)
     self.errmsg = None
Пример #11
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))
Пример #12
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
Пример #13
0
    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
Пример #14
0
    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()
Пример #15
0
    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
Пример #16
0
    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
Пример #17
0
    python = options.python
make = 'make' if unix else 'nmake /NOLOGO'
#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:
Пример #18
0
lines.append('[prog]')
#lines.append('python\t%s' % progs['python'])
for prog in required:
    if prog_scanned[prog] == '':
        continue
    lines.append('%s\t%s' % (prog, prog_scanned[prog]))
lines.append('')
lines.append('[path]')
for key in paths:
    lines.append('%s\t%s' % (key, paths[key]))
lines.append('')
lines.append('[data]')
for key in parms.keys():
    lines.append('%s\t%s' % (key, parms[key]))

fio = TextFio(setup_file, 'w')
if fio.open() < 0:
    E.abort('can not open "%s" for writing' % setup_file)
if fio.writelines(lines) < 0:
    E.abort('write error on "%s"' % setup_file)
fio.close()

#  ファイル内容の表示
#
print()
sf = SetupFile(setup_file)
sf.show()
print()
print('   written to "%s"' % Util.upath(os.path.abspath(setup_file)))

# ----------------------------------------------------------------------
Пример #19
0
    os.chdir(repository)

# ----------------------------------------------------------------------
#  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)
Пример #20
0
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
Пример #21
0
    for line in lines:
        count += 1
        Print('%3d: %s<EOL>' % (count, line))
    if changed:
        Print('- %d lines changed' % changed)


def print_info(infos, changed=None):
    for info in infos:
        Print('%3d: %s<EOL>' % (info[f.NUMB], info[f.DATA]))
    if changed:
        Print('- %d lines changed' % changed)


# ----------------------------------------------------------------------
T = TextFio('')
print('Test program for class: %s, Ver %s\n' % (T.clsname, T.version))

# encoding
#
print('---- encoding ----')
print()
encs = ['utf8', 'sjis', 'unicode', 'jis', 'euc', 'ascii', 'utf8-bom', 'utf16']
for enc in encs:
    fname = 'test/TextFioTest.' + enc
    f = TextFio(fname, verbose=verbose)
    lines = fileread(f)
    print()

print('---------------------------------------')
files = ['test/TextFioTest.txt', 'test/empty.txt']
Пример #22
0
# ----------------------------------------------------------------------
#  make はインストールされているか
#
cmnd = '%s -help' % make if Util.is_unix() else '%s /?' % make
rc_make = Proc(dry_run=dry_run).execute(cmnd,
                                        stdout=Proc.NULL,
                                        stderr=Proc.NULL,
                                        shell=True).wait()
if rc_make != 0:
    Error(prog).abort('can\'t find "%s"' % make)

# ----------------------------------------------------------------------
#  処理するモジュールの一覧を作成
#
fname = '%s/%s' % (etcdir, projfile)
fio = TextFio(fname, 'r')
if fio.open() != 0:
    Error(prog).abort('open error: "%s"' % fname)
lines = fio.read()
fio.close()

projs = ['Base']
for line in lines:
    if not line: continue
    projs.append(line.split()[0])
if verbose:
    print('  PROJS: %s' % projs)

# ----------------------------------------------------------------------
#  処理開始
#
Пример #23
0
	parser.error("incorrect number of arguments")

# 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**'
Пример #24
0
    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
Пример #25
0
    print()

# ----------------------------------------------------------------------
#  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)
Пример #26
0
lines.append('\t')

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
Пример #27
0
(options, args) = parser.parse_args()
#
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)
Пример #28
0
    print()

# ----------------------------------------------------------------------
#  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)
Пример #29
0
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
Пример #30
0
    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)