blob: 4a0b819f33b4855fd844791e4973ad426e95a641 [file] [log] [blame]
DR695H7145fe02019-07-24 16:37:01 -04001# Copyright 2019 AT&T Intellectual Property. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
DR695H7145fe02019-07-24 16:37:01 -040015from robot.libraries.BuiltIn import BuiltIn
16
17
DR695H0605e352019-07-26 15:56:10 -040018class VariableHelper(object):
19 """ Non keyword class for useful for working with varaibles """
DR695H7145fe02019-07-24 16:37:01 -040020
21 def __init__(self):
DR695H0605e352019-07-26 15:56:10 -040022 super(VariableHelper, self).__init__()
DR695H7145fe02019-07-24 16:37:01 -040023 self.builtin = BuiltIn()
24
DR695H7145fe02019-07-24 16:37:01 -040025 def get_globally_injected_parameters(self):
26 dictionary = self.builtin.get_variables(no_decoration=True)
DR695H0605e352019-07-26 15:56:10 -040027 return self.filter_variables_by_key_prefix(dictionary, "GLOBAL_INJECTED_")
DR695H7145fe02019-07-24 16:37:01 -040028
DR695H0605e352019-07-26 15:56:10 -040029 def get_global_parameters(self):
30 dictionary = self.builtin.get_variables(no_decoration=True)
31 global_variables = self.filter_variables_by_key_prefix(dictionary, "GLOBAL_")
32 # strip out global injected (get those above)
33 for key in self.get_globally_injected_parameters():
34 del global_variables[key]
35 return global_variables
36
37 @staticmethod
38 def filter_variables_by_key_prefix(dictionary, partial):
DR695H7145fe02019-07-24 16:37:01 -040039 matches = dict()
40 for key, val in dictionary.items():
41 if key.startswith(partial):
42 matches[key] = val
43 return matches