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 typing import List
22from progstats.entities.Project import Project
23from progstats.entities.Topic import Topic, TopicType
26def get_topics() -> List[Topic]:
27 """
28 Retrieves a list of all available topics
29 :return: The list of topics
30 """
31 data_dir = os.environ["PROGSTATS_DATA"]
33 topics = []
34 for topic in os.listdir(data_dir):
36 if topic.startswith("."):
37 continue
39 for topic_type in TopicType:
40 if topic_type.value[0] == topic:
41 topics.append(Topic(data_dir, topic_type))
42 topics.sort(key=lambda x: x.name)
43 return topics
46def get_projects() -> List[Project]:
47 """
48 Retrieves a list of all projects
49 :return: The list of projects
50 """
52 topics = get_topics()
53 projects = {}
55 for topic in topics:
56 for project_name in os.listdir(topic.path):
58 if project_name.startswith("."):
59 continue
60 if project_name.endswith(".pdf"):
61 project_name = project_name.rsplit(".pdf", 1)[0]
63 if project_name in projects:
64 projects[project_name].add_topic(topic)
65 else:
66 projects[project_name] = Project(project_name, [topic])
68 project_list = []
69 for project in projects:
70 project_list.append(projects[project])
72 project_list.sort(key=lambda x: x.name)
73 return project_list