Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(utils): Remove unused utils and their corresponding tests #267

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/powerapi/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from powerapi.utils.utils import timestamp_to_datetime, datetime_to_timestamp, dict_merge
from powerapi.utils.tree import Tree
from powerapi.utils.stat_buffer import StatBuffer
from .json_stream import JsonStream
from .tree import Tree
from .utils import timestamp_to_datetime
28 changes: 0 additions & 28 deletions src/powerapi/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,3 @@ def merge_dictionaries(source: dict, destination: dict) -> dict:
destination[current_source_key])

return destination


def generate_group_configuration_from_environment_variables_dict(environ_vars: dict, prefix: str,
var_names: list) -> dict:
"""
Generate a group configuration by using a dictionary of environment variables.
:param environ_vars: Dictionary for generating the configuration
:param prefix: the prefix of the environment variables in environ_vars (all variable starts vy prefix)
:param var_names: the variables names related to the group configuration (each variable has as suffix a name
in this list)
"""
conf = {}

for environ_var_name, var_value in environ_vars:
# We remove the prefix : <group_name_var_name> is the result
suffix_var_name = environ_var_name[len(prefix) - len(environ_var_name):].lower()

for var_name in var_names:
# the var_name has to be at the end of the suffix
var_name_lower_case = var_name.lower()
if suffix_var_name.endswith(var_name_lower_case):
# The group's name is at the begining of the
group_var_name = suffix_var_name[0:suffix_var_name.find(var_name_lower_case) - 1]
if group_var_name not in conf:
conf[group_var_name] = {}
conf[group_var_name][var_name_lower_case] = var_value
break
return conf
131 changes: 0 additions & 131 deletions src/powerapi/utils/stat_buffer.py

This file was deleted.

142 changes: 0 additions & 142 deletions src/powerapi/utils/sync.py

This file was deleted.

27 changes: 0 additions & 27 deletions src/powerapi/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import collections.abc as collections
import datetime


Expand All @@ -39,29 +38,3 @@ def timestamp_to_datetime(timestamp):
:rtype: datetime.datetime
"""
return datetime.datetime.fromtimestamp(timestamp / 1000)


def datetime_to_timestamp(date):
"""
Cast a datetime object to a simple timestamp

:param datetime.datetime date:
:rtype: int
"""
return int(datetime.datetime.timestamp(date) * 1000)


def dict_merge(dict1, dict2):
"""
Recursive dict merge, act like dict.update() but update
all level and not only top-level.

:param dict dict1:
:param dict dict2:

"""
for key, value in dict2.items():
if (key in dict1 and isinstance(dict1[key], dict) and isinstance(dict2[key], collections.Mapping)):
dict_merge(dict1[key], dict2[key])
else:
dict1[key] = value
Loading