• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2018 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16import logging
17
18from acts.keys import Config
19
20
21class ConfigWrapper(object):
22    """A wrapper tool around the finalized Configuration.
23
24    The purpose of this class is to give ACTS the ability to gather metrics on
25    how its configuration is being used, which in turn will allow old values
26    to be deprecated and refine workflows to match user needs.
27    """
28    def __init__(self, dictionary):
29        self._dictionary = dictionary
30
31    def __getitem__(self, key):
32        if key == Config.key_config_path:
33            logging.warning(
34                'The config key "%s" is pending deprecation. For resolving '
35                'files in the same directory as your config, please use a '
36                'key-value entry in your config that contains an absolute '
37                'path.' % Config.key_config_path)
38        return self._dictionary[key]
39
40    def __contains__(self, key):
41        return key in self._dictionary
42
43    def __setitem__(self, key, item):
44        logging.warning('Setting additional keys in the base configuration is '
45                        'pending deprecation.')
46        self._dictionary[key] = item
47
48    def __delitem__(self, key):
49        logging.warning('Deleting keys from the base configuration is '
50                        'pending deprecation.')
51        del self._dictionary[key]
52
53    def items(self):
54        return self._dictionary.items()
55
56    def __str__(self):
57        return str(self._dictionary)
58