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

Open-MSS / MSS / 10653123390

01 Sep 2024 10:12AM UTC coverage: 69.967% (-0.07%) from 70.037%
10653123390

Pull #2495

github

web-flow
Merge d3a10b8f0 into 0b95679f6
Pull Request #2495: remove the conda/mamba based updater.

24 of 41 new or added lines in 5 files covered. (58.54%)

92 existing lines in 6 files now uncovered.

13843 of 19785 relevant lines covered (69.97%)

0.7 hits per line

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

69.7
/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-2024 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
import os
1✔
31
import subprocess
1✔
32

33

34
def subprocess_startupinfo():
1✔
35
    """
36
    config options to hide windows terminals on subprocess call
37
    """
UNCOV
38
    startupinfo = None
×
UNCOV
39
    if os.name == 'nt':
×
40
        # thx to https://gist.github.com/nitely/3862493
41
        startupinfo = subprocess.STARTUPINFO()
×
42
        startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
×
43
        startupinfo.wShowWindow = subprocess.SW_HIDE
×
UNCOV
44
    return startupinfo
×
45

46

47
class FatalUserError(Exception):
1✔
48
    def __init__(self, error_string):
1✔
49
        logging.debug("%s", error_string)
1✔
50

51

52
def setup_logging(args):
1✔
53
    logger = logging.getLogger()
1✔
54
    # this is necessary as "someone" has already initialized logging, preventing basicConfig from doing stuff
55
    for ch in logger.handlers:
1✔
56
        logger.removeHandler(ch)
1✔
57

58
    debug_formatter = logging.Formatter("%(asctime)s (%(module)s.%(funcName)s:%(lineno)s): %(levelname)s: %(message)s")
1✔
59
    default_formatter = logging.Formatter("%(levelname)s: %(message)s")
1✔
60

61
    # Console handler (suppress DEBUG by default)
62
    ch = logging.StreamHandler()
1✔
63
    if args.debug:
1✔
64
        logger.setLevel(logging.DEBUG)
×
65
        ch.setLevel(logging.DEBUG)
×
66
        ch.setFormatter(debug_formatter)
×
67
    else:
68
        logger.setLevel(logging.INFO)
1✔
69
        ch.setLevel(logging.INFO)
1✔
70
        ch.setFormatter(default_formatter)
1✔
71
    logger.addHandler(ch)
1✔
72
    # File handler (always on DEBUG level)
73
    # TODO: Change this to write to a rotating log handler (so that the file size
74
    # is kept constant). (mr, 2011-02-25)
75
    if args.logfile:
1✔
76
        logfile = args.logfile
×
77
        try:
×
78
            fh = logging.FileHandler(logfile, "w")
×
79
        except (OSError, IOError) as ex:
×
80
            logger.error("Could not open logfile '%s': %s %s", logfile, type(ex), ex)
×
81
        else:
82
            logger.setLevel(logging.DEBUG)
×
83
            fh.setLevel(logging.DEBUG)
×
84
            fh.setFormatter(debug_formatter)
×
85
            logger.addHandler(fh)
×
86

87

88
# modified Version from minidom, https://github.com/python/cpython/blob/2.7/Lib/xml/dom/minidom.py
89
# MSS needed to change all writings as unicode not str
90
from xml.dom.minidom import _write_data, Node
1✔
91
# Copyright © 2001-2018 Python Software Foundation. All rights reserved.
92
# Copyright © 2000 BeOpen.com. All rights reserved.
93

94

95
def writexml(self, writer, indent="", addindent="", newl=""):
1✔
96
    # indent = current indentation
97
    # addindent = indentation to add to higher levels
98
    # newl = newline string
99
    writer.write(indent + "<" + self.tagName)
1✔
100

101
    attrs = self._get_attributes()
1✔
102

103
    for a_name in sorted(attrs.keys()):
1✔
104
        writer.write(" %s=\"" % a_name)
1✔
105
        _write_data(writer, attrs[a_name].value)
1✔
106
        writer.write("\"")
1✔
107
    if self.childNodes:
1✔
108
        writer.write(">")
1✔
109
        if (len(self.childNodes) == 1 and self.childNodes[0].nodeType == Node.TEXT_NODE):
1✔
110
            self.childNodes[0].writexml(writer, '', '', '')
1✔
111
        else:
112
            writer.write(newl)
1✔
113
            for node in self.childNodes:
1✔
114
                node.writexml(writer, indent + addindent, addindent, newl)
1✔
115
            writer.write(indent)
1✔
116
        writer.write("</%s>%s" % (self.tagName, newl))
1✔
117
    else:
118
        writer.write("/>%s" % (newl))
×
119

120

121
def conditional_decorator(dec, condition):
1✔
122
    def decorator(func):
1✔
123
        if not condition:
1✔
124
            # Return the function unchanged, not decorated.
125
            return func
1✔
126
        return dec(func)
×
127
    return decorator
1✔
128

129

130
def prefix_route(route_function, prefix='', mask='{0}{1}'):
1✔
131
    """
132
    https://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes/18969161#18969161
133
    Defines a new route function with a prefix.
134
    The mask argument is a `format string` formatted with, in that order:
135
      prefix, route
136
    """
137
    def newroute(route, *args, **kwargs):
1✔
138
        """ prefix route """
139
        return route_function(mask.format(prefix, route), *args, **kwargs)
1✔
140
    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

© 2025 Coveralls, Inc