Total Complexity | 10 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
|
|||
2 | |||
3 | import errno |
||
4 | import glob |
||
5 | import os |
||
6 | from . import ansi |
||
7 | |||
8 | class DumpMgrMixin: |
||
9 | def __init__(self): |
||
10 | self.last_dump_filename = None |
||
11 | |||
12 | def write_dump(self, data): |
||
13 | outfile = os.path.normpath("logs/{}.xml".format(self.get_salt())) |
||
14 | if not os.path.exists(os.path.dirname(outfile)): |
||
15 | try: |
||
16 | os.makedirs(os.path.dirname(outfile)) |
||
17 | except OSError as e: |
||
18 | if e.errno != errno.EEXIST: |
||
19 | raise |
||
20 | with open(outfile, "w", encoding="utf-8") as f: |
||
21 | f.write(data) |
||
22 | self.last_dump_filename = outfile |
||
23 | |||
24 | def delete_last_dump(self): |
||
25 | if self.last_dump_filename: |
||
26 | os.unlink(self.last_dump_filename) |
||
27 | self.last_dump_filename = None |
||
28 | |||
29 | @staticmethod |
||
30 | def write_info_if_dumps_found(): |
||
31 | # To disable this info, uncomment the following line. |
||
32 | #return |
||
33 | files = glob.glob(os.path.normpath("logs/*.xml")) |
||
34 | if len(files) > 0: |
||
35 | print() |
||
36 | print("{}There are {} logs collected in the logs/ directory.{} Please consider uploading".format(ansi.YELLOW, len(files), ansi.RESET)) |
||
1 ignored issue
–
show
|
|||
37 | print("them to https://tclota.birth-online.de/ by running {}./upload_logs.py{}.".format(ansi.CYAN, ansi.RESET)) |
||
1 ignored issue
–
show
|
|||
38 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.