/usr/lib/python3/dist-packages/dep11/hints.py is in python3-dep11 0.4.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | #!/usr/bin/env python
#
# Copyright (c) 2015 Matthias Klumpp <mak@debian.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program.
import os
import sys
import yaml
import logging as log
__all__ = []
_DEP11_HINT_DESCRIPTIONS = None
class HintSeverity:
'''
Importance of a component parsing hint.
'''
ERROR = 3
WARNING = 2
INFO = 1
__all__.append('HintSeverity')
class Hint:
'''
An issue found with the metadata.
'''
severity = HintSeverity.INFO
tag_name = str()
text_params = dict()
def __init__(self, severity, tag, params):
self.severity = severity
self.tag_name = tag
self.text_params = params
def __str__(self):
return "%s: %s (%s)" % (str(self.severity), tag_name, str(text_params))
__all__.append('Hint')
def get_hints_index_fname():
'''
Find the YAML tag description, even if the DEP-11 metadata generator
is not properly installed.
'''
fname = os.path.join(sys.prefix, "share", "dep11", "dep11-hints.yml")
if os.path.isfile(fname):
return fname
fname = os.path.dirname(os.path.realpath(__file__))
fname = os.path.realpath(os.path.join(fname, "..", "data", "dep11-hints.yml"))
if os.path.isfile(fname):
return fname
raise Exception("Could not find tag description file (dep11-hints.yml).")
def get_hint_description_index():
global _DEP11_HINT_DESCRIPTIONS
if not _DEP11_HINT_DESCRIPTIONS:
fname = get_hints_index_fname()
f = open(fname, 'r')
_DEP11_HINT_DESCRIPTIONS = yaml.safe_load(f.read())
f.close()
return _DEP11_HINT_DESCRIPTIONS
__all__.append('get_hint_description_index')
def get_hint_tag_info(tag_name):
idx = get_hint_description_index()
tag = idx.get(tag_name)
if not tag:
log.error("Could not find tag name: %s", tag_name)
tag = idx.get("internal-unknown-tag")
return tag
__all__.append('get_hint_tag_info')
def get_hint_severity(tag_name):
tag = get_hint_tag_info(tag_name)
severity = tag.get('severity')
if not severity:
log.error("Tag %s has no severity!", tag_name)
if severity == "warning":
return HintSeverity.WARNING
if severity == "info":
return HintSeverity.INFO
return HintSeverity.ERROR
__all__.append('get_hint_severity')
def hint_tag_is_error(tag_name):
tag = get_hint_tag_info(tag_name)
severity = tag.get('severity')
if not severity:
log.error("Tag %s has no severity!", tag_name)
if severity == "error":
return True
return False
__all__.append('hint_tag_is_error')
|