1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-09 22:06:47 +00:00
tcl_ota_check/tcllib/dumpmgr.py

43 lines
1.3 KiB
Python
Raw Normal View History

2018-02-03 20:40:17 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2018-02-03 20:40:17 +00:00
# pylint: disable=C0111,C0326,C0103
import errno
import glob
import os
2018-02-03 20:24:36 +00:00
from . import ansi
2018-02-03 20:24:36 +00:00
2018-02-03 12:46:17 +00:00
class DumpMgrMixin:
2018-02-03 01:37:55 +00:00
def __init__(self):
self.last_dump_filename = None
def write_dump(self, data):
outfile = os.path.normpath("logs/{}.xml".format(self.get_salt()))
if not os.path.exists(os.path.dirname(outfile)):
try:
os.makedirs(os.path.dirname(outfile))
2018-02-03 20:24:36 +00:00
except OSError as err:
if err.errno != errno.EEXIST:
raise
2018-02-03 20:24:36 +00:00
with open(outfile, "w", encoding="utf-8") as fhandle:
fhandle.write(data)
self.last_dump_filename = outfile
def delete_last_dump(self):
if self.last_dump_filename:
os.unlink(self.last_dump_filename)
self.last_dump_filename = None
@staticmethod
def write_info_if_dumps_found():
# To disable this info, uncomment the following line.
2018-02-03 20:24:36 +00:00
# return
files = glob.glob(os.path.normpath("logs/*.xml"))
2018-02-03 20:24:36 +00:00
if files:
print()
print("{}There are {} logs collected in the logs/ directory.{} Please consider uploading".format(ansi.YELLOW, len(files), ansi.RESET))
print("them to https://tclota.birth-online.de/ by running {}./upload_logs.py{}.".format(ansi.CYAN, ansi.RESET))