Coverage for progstats/entities/Topic.py : 54%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of progstats.
6progstats is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11progstats is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with progstats. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20import os
21from enum import Enum
22from flask import abort
25class TopicType(Enum):
26 """
27 An enumeration modelling all possible topic types
28 """
29 GITSTATS = ("gitstats", "@{project}/index.html")
30 GIT_STATS = ("git_stats", "@{project}/index.html")
31 COVERAGE = ("coverage", "@{project}/index.html")
32 DOC_HTML = ("doc_html", "@{project}/index.html")
33 DOC_PDF = ("doc_pdf", "@{project}.pdf")
36class Topic:
37 """
38 Models a topic
39 """
41 def __init__(self, root_dir: str, topic_type: TopicType):
42 """
43 Initializes the topic
44 :param root_dir: The root data directory path
45 :param topic_type:
46 """
47 self.name, self.target = topic_type.value
48 self.path = os.path.join(root_dir, self.name)
50 def generate_path(self, project_name: str) -> str:
51 """
52 Generates the path to a project's data resource
53 :param project_name: The name of the project
54 :return: The path to the resource
55 """
56 if project_name == "":
57 abort(404)
59 return os.path.join(
60 self.name,
61 self.target.replace("@{project}", project_name)
62 )
64 def __eq__(self, other):
65 """
66 Checks for equality with another object
67 :param other: The other object to check
68 :return: True if the objects are equal, False otherwise
69 """
70 try:
71 return self.path == other.path \
72 and self.name == other.name \
73 and self.target == other.target
74 except AttributeError:
75 return False