1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# SLEPc - Scalable Library for Eigenvalue Problem Computations
# Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
#
# This file is part of SLEPc.
# SLEPc is distributed under a 2-clause BSD license (see LICENSE).
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
from __future__ import print_function
import os, sys
class Log:
def __init__(self):
self.fd = None
self.lastfailed = False
def Open(self,slepcdir,confdir,fname):
filename = os.path.join(confdir,fname)
self.fd = open(filename,'w')
self.filename = os.path.relpath(filename,slepcdir)
try: # symbolic link to log file in current directory
if os.path.isfile(fname) or os.path.islink(fname): os.remove(fname)
os.symlink(self.filename,fname)
except: pass
def Println(self,string):
print(string)
if self.fd:
self.fd.write(string+'\n')
def Print(self,string):
print(string, end=' ')
if self.fd:
self.fd.write(string+' ')
def NewSection(self,string):
if self.lastfailed:
colorfail = '\033[91m'
colornorm = '\033[0m'
print(colorfail+'failed'+colornorm+'\n'+string, end=' ')
else:
print('done\n'+string, end=' ')
sys.stdout.flush()
if self.fd:
self.fd.write('='*80+'\n'+string+'\n')
self.lastfailed = False
def write(self,string):
if self.fd:
self.fd.write(string+'\n')
def Warn(self,string):
msg = '\nxxx'+'='*74+'xxx\nWARNING: '+string+'\nxxx'+'='*74+'xxx'
print(msg)
if self.fd:
self.fd.write(msg+'\n')
def Exit(self,string):
msg = '\nERROR: '+string
print(msg)
if self.fd:
self.fd.write(msg+'\n')
self.fd.close()
msg = 'ERROR: See "' + self.filename + '" file for details'
else:
msg = 'ERROR during configure (log file not open yet)'
sys.exit(msg)
def setLastFailed(self):
self.lastfailed = True
def Close(self):
if self.fd:
self.fd.close()
|