mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-02-04 21:19:14 +00:00
Rewrite swtpm-localca in python and get rid of the bash file and the flock dependency. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
33 lines
697 B
Python
33 lines
697 B
Python
""" swtpm_logging.py
|
|
"""
|
|
|
|
# pylint: disable=W0703
|
|
|
|
import sys
|
|
|
|
|
|
def append_to_file(filename, string):
|
|
"""" Append a string to a file """
|
|
try:
|
|
fobj = open(filename, 'a')
|
|
fobj.write(string)
|
|
fobj.close()
|
|
except Exception:
|
|
sys.stdout.write(string)
|
|
|
|
|
|
def logit(logfile, string):
|
|
""" Print the given string to stdout or into the logfile """
|
|
if len(logfile) == 0:
|
|
sys.stdout.write(string)
|
|
else:
|
|
append_to_file(logfile, string)
|
|
|
|
|
|
def logerr(logfile, string):
|
|
""" Print the given string to stderr or into the logfile """
|
|
if len(logfile) == 0:
|
|
sys.stdout.write(string)
|
|
else:
|
|
append_to_file(logfile, string)
|