• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-MSS / MSS / 14727107325

29 Apr 2025 08:45AM UTC coverage: 69.875% (-2.5%) from 72.411%
14727107325

push

github

web-flow
Reintroduce coverage upload to coveralls (#2811)

14474 of 20714 relevant lines covered (69.88%)

0.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.44
/mslib/utils/__init__.py
1
# -*- coding: utf-8 -*-
2
"""
3

4
    mslib.utils
5
    ~~~~~~~~~~~~~~
6

7
    Collection of utility routines for the Mission Support System.
8

9
    This file is part of MSS.
10

11
    :copyright: Copyright 2008-2014 Deutsches Zentrum fuer Luft- und Raumfahrt e.V.
12
    :copyright: Copyright 2011-2014 Marc Rautenhaus (mr)
13
    :copyright: Copyright 2016-2025 by the MSS team, see AUTHORS.
14
    :license: APACHE-2.0, see LICENSE for details.
15

16
    Licensed under the Apache License, Version 2.0 (the "License");
17
    you may not use this file except in compliance with the License.
18
    You may obtain a copy of the License at
19

20
       http://www.apache.org/licenses/LICENSE-2.0
21

22
    Unless required by applicable law or agreed to in writing, software
23
    distributed under the License is distributed on an "AS IS" BASIS,
24
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
    See the License for the specific language governing permissions and
26
    limitations under the License.
27
"""
28

29
import logging
1✔
30

31

32
class FatalUserError(Exception):
1✔
33
    def __init__(self, error_string):
1✔
34
        logging.debug("%s", error_string)
1✔
35

36

37
def setup_logging(args):
1✔
38
    logger = logging.getLogger()
1✔
39
    # this is necessary as "someone" has already initialized logging, preventing basicConfig from doing stuff
40
    for ch in logger.handlers:
1✔
41
        logger.removeHandler(ch)
1✔
42

43
    debug_formatter = logging.Formatter("%(asctime)s (%(module)s.%(funcName)s:%(lineno)s): %(levelname)s: %(message)s")
1✔
44
    default_formatter = logging.Formatter("%(levelname)s: %(message)s")
1✔
45

46
    # Console handler (suppress DEBUG by default)
47
    ch = logging.StreamHandler()
1✔
48
    if args.debug:
1✔
49
        logger.setLevel(logging.DEBUG)
×
50
        ch.setLevel(logging.DEBUG)
×
51
        ch.setFormatter(debug_formatter)
×
52
    else:
53
        logger.setLevel(logging.INFO)
1✔
54
        ch.setLevel(logging.INFO)
1✔
55
        ch.setFormatter(default_formatter)
1✔
56
    logger.addHandler(ch)
1✔
57
    # File handler (always on DEBUG level)
58
    # TODO: Change this to write to a rotating log handler (so that the file size
59
    # is kept constant). (mr, 2011-02-25)
60
    if args.logfile:
1✔
61
        logfile = args.logfile
×
62
        try:
×
63
            fh = logging.FileHandler(logfile, "w")
×
64
        except (OSError, IOError) as ex:
×
65
            logger.error("Could not open logfile '%s': %s %s", logfile, type(ex), ex)
×
66
        else:
67
            logger.setLevel(logging.DEBUG)
×
68
            fh.setLevel(logging.DEBUG)
×
69
            fh.setFormatter(debug_formatter)
×
70
            logger.addHandler(fh)
×
71

72

73
# ToDo likely this can be removed in python 3 because that uses unicode
74
# modified Version from minidom, https://github.com/python/cpython/blob/2.7/Lib/xml/dom/minidom.py
75
# MSS needed to change all writings as unicode not str
76
from xml.dom.minidom import _write_data, Node
1✔
77
# Copyright © 2001-2018 Python Software Foundation. All rights reserved.
78
# Copyright © 2000 BeOpen.com. All rights reserved.
79

80

81
def writexml(self, writer, indent="", addindent="", newl=""):
1✔
82
    # indent = current indentation
83
    # addindent = indentation to add to higher levels
84
    # newl = newline string
85
    writer.write(indent + "<" + self.tagName)
1✔
86

87
    attrs = self._get_attributes()
1✔
88

89
    for a_name in sorted(attrs.keys()):
1✔
90
        writer.write(" %s=\"" % a_name)
1✔
91
        _write_data(writer, attrs[a_name].value)  # nosec, we take care of writing correct XML
1✔
92
        writer.write("\"")
1✔
93
    if self.childNodes:
1✔
94
        writer.write(">")
1✔
95
        if (len(self.childNodes) == 1 and self.childNodes[0].nodeType == Node.TEXT_NODE):
1✔
96
            # nosec, we take care of writing correct XML
97
            self.childNodes[0].writexml(writer, '', '', '')
1✔
98
        else:
99
            writer.write(newl)
1✔
100
            for node in self.childNodes:
1✔
101
                node.writexml(writer, indent + addindent, addindent, newl)
1✔
102
            writer.write(indent)
1✔
103
        writer.write("</%s>%s" % (self.tagName, newl))
1✔
104
    else:
105
        writer.write("/>%s" % (newl))
×
106

107

108
def conditional_decorator(dec, condition):
1✔
109
    def decorator(func):
1✔
110
        if not condition:
1✔
111
            # Return the function unchanged, not decorated.
112
            return func
1✔
113
        return dec(func)
×
114
    return decorator
1✔
115

116

117
def prefix_route(route_function, prefix='', mask='{0}{1}'):
1✔
118
    """
119
    https://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes/18969161#18969161
120
    Defines a new route function with a prefix.
121
    The mask argument is a `format string` formatted with, in that order:
122
      prefix, route
123
    """
124
    def newroute(route, *args, **kwargs):
1✔
125
        """ prefix route """
126
        return route_function(mask.format(prefix, route), *args, **kwargs)
1✔
127
    return newroute
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc