|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module defining a class containing the individual project metadata. |
|
8 """ |
|
9 |
|
10 from dataclasses import asdict, dataclass |
|
11 |
|
12 |
|
13 @dataclass |
|
14 class MultiProjectProjectMeta: |
|
15 """ |
|
16 Class containing the individual project metadata. |
|
17 """ |
|
18 |
|
19 name: str # name of the project |
|
20 file: str # project file name |
|
21 uid: str # unique identifier |
|
22 master: bool = False # flag indicating the main project |
|
23 description: str = "" # description of the project |
|
24 category: str = "" # name of the group |
|
25 removed: bool = False # flag indicating a (re-)moved project |
|
26 |
|
27 def as_dict(self): |
|
28 """ |
|
29 Public method to convert the metadata into a dictionary. |
|
30 |
|
31 @return dictionary containing the metadata |
|
32 @rtype dict |
|
33 """ |
|
34 return asdict(self) |
|
35 |
|
36 @classmethod |
|
37 def from_dict(cls, data): |
|
38 """ |
|
39 Class method to create a metadata object from the given dictionary. |
|
40 |
|
41 @param data dictionary containing the metadata |
|
42 @type dict |
|
43 @return created project metadata object |
|
44 @rtype MultiProjectProjectMeta |
|
45 """ |
|
46 return cls( |
|
47 name=data["name"], |
|
48 file=data["file"], |
|
49 uid=data["uid"], |
|
50 master=data.get("master", False), |
|
51 description=data.get("description", ""), |
|
52 category=data.get("category", ""), |
|
53 removed=data.get("removed", False), |
|
54 ) |