Coverage for britney2/policies/__init__.py: 100%

47 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-04-18 20:48 +0000

1from enum import Enum, unique 

2from functools import total_ordering 

3 

4 

5@total_ordering 

6@unique 

7class PolicyVerdict(Enum): 

8 """""" 

9 """ 

10 The policy doesn't apply to this item. No test was done. 

11 """ 

12 NOT_APPLICABLE = 0 

13 """ 

14 The migration item passed the policy. 

15 """ 

16 PASS = 1 

17 """ 

18 The policy was completely overruled by a hint. 

19 """ 

20 PASS_HINTED = 2 

21 """ 

22 The migration item did not pass the policy, but the failure is believed 

23 to be temporary 

24 """ 

25 REJECTED_TEMPORARILY = 3 

26 """ 

27 The migration item is temporarily unable to migrate due to another item. The other item is temporarily blocked. 

28 """ 

29 REJECTED_WAITING_FOR_ANOTHER_ITEM = 4 

30 """ 

31 The migration item is permanently unable to migrate due to another item. The other item is permanently blocked. 

32 """ 

33 REJECTED_BLOCKED_BY_ANOTHER_ITEM = 5 

34 """ 

35 The migration item needs approval to migrate 

36 """ 

37 REJECTED_NEEDS_APPROVAL = 6 

38 """ 

39 The migration item is blocked, but there is not enough information to determine 

40 if this issue is permanent or temporary 

41 """ 

42 REJECTED_CANNOT_DETERMINE_IF_PERMANENT = 7 

43 """ 

44 The migration item did not pass the policy and the failure is believed 

45 to be uncorrectable (i.e. a hint or a new version is needed) 

46 """ 

47 REJECTED_PERMANENTLY = 8 

48 

49 @property 

50 def is_rejected(self) -> bool: 

51 return True if self.name.startswith('REJECTED') else False 

52 

53 @property 

54 def is_blocked(self) -> bool: 

55 """Whether the item (probably) needs a fix or manual assistance to migrate""" 

56 return self in { 

57 PolicyVerdict.REJECTED_BLOCKED_BY_ANOTHER_ITEM, 

58 PolicyVerdict.REJECTED_NEEDS_APPROVAL, 

59 PolicyVerdict.REJECTED_CANNOT_DETERMINE_IF_PERMANENT, # Assuming the worst 

60 PolicyVerdict.REJECTED_PERMANENTLY, 

61 } 

62 

63 @staticmethod 

64 def worst_of(*args: "PolicyVerdict") -> "PolicyVerdict": 

65 """Pick the "worst" of two verdicts - useful for aggregating two verdicts""" 

66 # We could have used max everywhere, but "worst_of" seemed more clear (as then you do not have to remember 

67 # the value of the verdicts) 

68 return max(args) 

69 

70 def __lt__(self, other: "PolicyVerdict") -> bool: 

71 return True if self.value < other.value else False 

72 

73 

74@unique 

75class ApplySrcPolicy(Enum): 

76 """ 

77 For a source item, run the source policy (this is the default) 

78 """ 

79 RUN_SRC = 1 

80 """ 

81 For a source item, run the arch policy on every arch 

82 """ 

83 RUN_ON_EVERY_ARCH_ONLY = 2 

84 """ 

85 For a source item, run the source policy and run the arch policy on every arch 

86 """ 

87 RUN_SRC_AND_EVERY_ARCH = 3 

88 

89 @property 

90 def run_src(self) -> bool: 

91 return self in { 

92 ApplySrcPolicy.RUN_SRC, 

93 ApplySrcPolicy.RUN_SRC_AND_EVERY_ARCH, 

94 } 

95 

96 @property 

97 def run_arch(self) -> bool: 

98 return self in { 

99 ApplySrcPolicy.RUN_ON_EVERY_ARCH_ONLY, 

100 ApplySrcPolicy.RUN_SRC_AND_EVERY_ARCH, 

101 }