The freezer.utils.utils
Module¶
Copyright 2015 Hewlett-Packard (c) Copyright 2016 Hewlett Packard Enterprise Development Company LP
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Freezer general utils functions
-
class
freezer.utils.utils.
Namespace
(obj={})[source]¶ Bases:
dict
A dict subclass that exposes its items as attributes.
Warning: Namespace instances do not have direct access to the dict methods.
-
class
freezer.utils.utils.
ReSizeStream
(stream, length, chunk_size)[source]¶ Bases:
object
Iterator/File-like object for changing size of chunk in stream
-
freezer.utils.utils.
alter_proxy
(proxy)[source]¶ Read proxy option from dictionary and alter the HTTP_PROXY and/or HTTPS_PROXY system variables
-
freezer.utils.utils.
create_dir
(directory, do_log=True)[source]¶ Creates a directory if it doesn’t exists and write the execution in the logs
-
freezer.utils.utils.
create_subprocess
(cmd)[source]¶ Create a new subprocess in the OS :param cmd: command to execute in the subprocess :return: the output and errors of the subprocess
-
freezer.utils.utils.
dequote
(s)[source]¶ If a string has single or double quotes around it, remove them. Make sure the pair of quotes match. If a matching pair of quotes is not found, return the string unchanged.
-
freezer.utils.utils.
exclude_path
(path, exclude)[source]¶ Tests if path is to be excluded according to the given pattern. :return: True if path matches the exclude pattern, False otherwise
-
freezer.utils.utils.
execute_walk_callback
(count, filepath, callback, *kargs, **kwargs)[source]¶ Execute the callback function adding the file path to its argument list. Increments the file counter and returns it. NB: the callback function must be defined with the filepath argument.
-
freezer.utils.utils.
get_executable_path
(binary)[source]¶ This function returns the executable path of a given binary if it is found in the system. :param binary: :type binary: str :rtype: str :return: Absolute Path to the executable file
-
freezer.utils.utils.
get_mount_from_path
(path)[source]¶ Take a file system path as argument and return the mount point for that file system path.
Parameters: path – file system path Returns: mount point of path, rest of the path
-
freezer.utils.utils.
human2bytes
(s)[source]¶ Attempts to guess the string format based on default symbols set and return the corresponding bytes as an integer. When unable to recognize the format ValueError is raised.
-
freezer.utils.utils.
walk_path
(path, exclude, ignorelinks, callback, *kargs, **kwargs)[source]¶ Walk a directory and execute a callback function for each file found. If path to a single file is given, the callback is excuted for this file. The callback is also executed and counted for an empty directory. :return: int with the number of files walked