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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# R overlay -- package rule actions, modify dependencies / depres
# -*- coding: utf-8 -*-
# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
# Distributed under the terms of the GNU General Public License;
# either version 2 of the License, or (at your option) any later version.
import roverlay.util.dictwalk
import roverlay.util.namespace
import roverlay.util.objects
import roverlay.depres.depresult
import roverlay.packagerules.abstract.actions
class DepConfAccess ( roverlay.util.dictwalk.FixedKeyDictWalker ):
# ideally, use a data type that
# (a) drops duplicates
# (b) is ordered
DEFAULT_CONTAINER_TYPE = set
def __init__ ( self, keypath, virtual_key=None ):
super ( DepConfAccess, self ).__init__ ( keypath )
self.virtual_key = (
self.keypath[-1] if virtual_key is None else virtual_key
)
# --- end of __init__ (...) ---
def get_root ( self, p_info ):
if p_info.depconf is None:
p_info.depconf = dict()
return p_info.depconf
# --- end of get_root (...) ---
# --- end of DepConfAccess ---
class DependencyAction (
roverlay.packagerules.abstract.actions.PackageRuleAction
):
ACTION_KEYWORD = None
@classmethod
def from_namespace ( cls, namespace, keypath, *args, **kwargs ):
depconf_access = namespace.get_object ( DepConfAccess, keypath )
return namespace.get_object_v (
cls, ( depconf_access, ) + args, kwargs
)
# --- end of from_namespace (...) ---
def __init__ ( self, depconf_access, priority=1000 ):
super ( DependencyAction, self ).__init__ ( priority=priority )
self.depconf = depconf_access
# --- end of __init__ (...) ---
def get_action_keyword ( self ):
return self.__class__.ACTION_KEYWORD
# --- end of get_action_keyword (...) ---
def get_virtual_key ( self ):
key = str ( self.depconf.virtual_key )
return None if key == 'all' else key
# --- end of get_virtual_key (...) ---
@roverlay.util.objects.abstractmethod
def get_action_arg_str ( self ):
pass
# --- end of get_action_arg_str (...) ---
def gen_str ( self, level ):
action_keyword = self.get_action_keyword()
action_arg_str = self.get_action_arg_str()
virtual_key = self.get_virtual_key()
indent = level * self.INDENT
if virtual_key:
virtual_key = ' ' + virtual_key
else:
virtual_key = ''
if action_arg_str:
action_arg_str = ' \"' + action_arg_str + '\"'
else:
action_arg_str = ''
yield "{indent}{action_keyword}{virtual_key}{action_arg_str}".format (
indent=indent, action_keyword=action_keyword,
virtual_key=virtual_key, action_arg_str=action_arg_str
)
# --- end of gen_str (...) ---
# --- end of DependencyAction ---
class DependencyVarAction ( DependencyAction ):
CATEGORY_KEY = None
CONVERT_VALUE_TO_DEPRESULT = True
@classmethod
def from_namespace ( cls, namespace, deptype_key, value, *args, **kwargs ):
assert cls.CATEGORY_KEY is not None
depconf_access = namespace.get_object (
DepConfAccess, ( cls.CATEGORY_KEY, deptype_key )
)
if cls.CONVERT_VALUE_TO_DEPRESULT:
my_value = namespace.get_object_v (
roverlay.depres.depresult.ConstantDepResult, ( value, 50, 0 )
)
else:
my_value = value
return namespace.get_object_v (
cls, ( depconf_access, my_value ) + args, kwargs
)
# --- end of from_namespace (...) ---
# @classmethod
# def get_subclass (
# cls, action_keyword, category_key, name=None, doc=None
# ):
# class NewDependencyVarAction ( cls ):
# ACTION_KEYWORDS = action_keyword
# CATEGORY_KEY = category_key
# # --- end of NewDependencyVarAction ---
#
# if name is not None:
# NewDependencyVarAction.__name__ = name
# else:
# NewDependencyVarAction.__name__ = 'New' + cls.__name__
#
# if doc is not None:
# NewDependencyVarAction.__doc__ = doc
#
# return NewDependencyVarAction
# # --- end of get_subclass (...) ---
def __init__ ( self, depconf_access, value, priority=1000 ):
super ( DependencyVarAction, self ).__init__ (
depconf_access, priority=priority
)
self.value = value
# --- end of __init__ (...) ---
def get_action_arg_str ( self ):
return str ( self.value )
# --- end of get_action_arg_str (...) ---
def apply_action ( self, p_info ):
self.depconf.add_value ( self.value, p_info )
# --- end of apply_action (...) ---
# --- end of DependencyVarAction ---
class DependencyInjectAction ( DependencyVarAction ):
ACTION_KEYWORD = 'add'
CATEGORY_KEY = 'extra'
# --- end of DependencyInjectAction (...) ---
class DepStrIgnoreAction ( DependencyVarAction ):
CATEGORY_KEY = 'depres_ignore'
ACTION_KEYWORD = CATEGORY_KEY
CONVERT_VALUE_TO_DEPRESULT = False
# --- end of DepStrIgnoreAction ---
|