DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 1 | # 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 | |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 15 | from robot.libraries.BuiltIn import BuiltIn |
| 16 | |
| 17 | |
DR695H | 0605e35 | 2019-07-26 15:56:10 -0400 | [diff] [blame^] | 18 | class VariableHelper(object): |
| 19 | """ Non keyword class for useful for working with varaibles """ |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 20 | |
| 21 | def __init__(self): |
DR695H | 0605e35 | 2019-07-26 15:56:10 -0400 | [diff] [blame^] | 22 | super(VariableHelper, self).__init__() |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 23 | self.builtin = BuiltIn() |
| 24 | |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 25 | def get_globally_injected_parameters(self): |
| 26 | dictionary = self.builtin.get_variables(no_decoration=True) |
DR695H | 0605e35 | 2019-07-26 15:56:10 -0400 | [diff] [blame^] | 27 | return self.filter_variables_by_key_prefix(dictionary, "GLOBAL_INJECTED_") |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 28 | |
DR695H | 0605e35 | 2019-07-26 15:56:10 -0400 | [diff] [blame^] | 29 | 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): |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 39 | matches = dict() |
| 40 | for key, val in dictionary.items(): |
| 41 | if key.startswith(partial): |
| 42 | matches[key] = val |
| 43 | return matches |