-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtypes.py
More file actions
101 lines (81 loc) · 1.86 KB
/
types.py
File metadata and controls
101 lines (81 loc) · 1.86 KB
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
"""PackageCompat type."""
from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum
class ucstr(str):
"""Uppercase string."""
__slots__ = ()
def __new__(cls, v: str | None):
"""Create a new ucstr from a str.
:param str v: string to cast
:return ucstr: uppercase string.
"""
if v is None:
return ucstr("")
return super().__new__(cls, v.upper())
UNKNOWN = ucstr("UNKNOWN")
JOINS = ucstr(";; ")
@dataclass(unsafe_hash=True, order=True)
class PackageInfo:
"""PackageInfo type."""
name: str
version: str | None = None
namever: str = field(init=False)
size: int = -1
homePage: str | None = None
author: str | None = None
license: ucstr | None = None
licenseCompat: bool = False
errorCode: int = 0
def __post_init__(self) -> None:
"""Set the namever once the object is initialised."""
self.namever = f"{self.name}-{self.version or UNKNOWN}"
def get_filtered_dict(self, hide_output_parameters: list[ucstr]) -> dict:
"""Return a filtered dictionary of the object.
:param list[ucstr] hide_output_parameters: list of parameters to ignore
:return dict: filtered dictionary
"""
return {
k: (v if v is not None else UNKNOWN)
for k, v in self.__dict__.items()
if k.upper() not in hide_output_parameters
}
class License(Enum):
"""License Enum to hold a set of potential licenses."""
# Public domain
PUBLIC = 0
UNLICENSE = 1
# Permissive GPL compatible
MIT = 10
BOOST = 11
BSD = 12
ISC = 13
NCSA = 14
PSFL = 15
# Other permissive
APACHE = 20
ECLIPSE = 21
ACADEMIC_FREE = 22
# LGPL
LGPL_X = 30
LGPL_2 = 31
LGPL_3 = 32
LGPL_2_PLUS = 33
LGPL_3_PLUS = 34
# GPL
GPL_X = 40
GPL_2 = 41
GPL_3 = 42
GPL_2_PLUS = 43
GPL_3_PLUS = 44
# AGPL
AGPL_3_PLUS = 50
# Other copyleft
MPL = 60
EU = 61
# PROPRIETARY
PROPRIETARY = 190
UNKNOWN = 191
# No License
NO_LICENSE = 200
L = License