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.Bunch(**kwds)[source]

Bases: object

class freezer.utils.utils.DateTime(value)[source]

Bases: object

static now()[source]
timestamp
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.

static delattr(ns, name)[source]
classmethod from_mapping(ns, names=None)[source]
classmethod from_object(obj, names=None)[source]
classmethod from_sequence(seq, names=None)[source]
static getattr(ns, name)[source]
static hasattr(ns, name)[source]
static setattr(ns, name, value)[source]
class freezer.utils.utils.ReSizeStream(stream, length, chunk_size)[source]

Bases: object

Iterator/File-like object for changing size of chunk in stream

next()[source]
read(chunk_size)[source]
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_dir_tree(directory_path)[source]
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.date_to_timestamp(date)[source]
freezer.utils.utils.delete_file(path_to_file)[source]

Delete a file from the file system

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.find_executable(name)[source]
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.is_bsd()[source]
freezer.utils.utils.is_empty_dir(path)[source]
freezer.utils.utils.openssl_path()[source]
freezer.utils.utils.path_join(*args)[source]

Should work for windows and linux :rtype: str

freezer.utils.utils.save_config_to_file(config, f, section='freezer_default')[source]
freezer.utils.utils.set_max_process_priority()[source]

Set freezer in max priority on the os

freezer.utils.utils.shield(func)[source]

Remove try except boilerplate code from functions

freezer.utils.utils.tar_path()[source]

This function returns tar binary path

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