diff --git a/src/cpl/utils/credential_manager.py b/src/cpl/utils/credential_manager.py index 7f9977d1..8a40e8dc 100644 --- a/src/cpl/utils/credential_manager.py +++ b/src/cpl/utils/credential_manager.py @@ -2,16 +2,35 @@ import base64 class CredentialManager: + """ + Handles credentials + """ @staticmethod def encrypt(string: str) -> str: + """ + Encode with base64 + :param string: + :return: + """ return base64.b64encode(string.encode('utf-8')).decode('utf-8') @staticmethod def decrypt(string: str) -> str: + """ + Decode with base64 + :param string: + :return: + """ return base64.b64decode(string).decode('utf-8') @staticmethod def build_string(string: str, credentials: str): + """ + Builds string with credentials in it + :param string: + :param credentials: + :return: + """ return string.replace('$credentials', CredentialManager.decrypt(credentials)) diff --git a/src/cpl/utils/pip.py b/src/cpl/utils/pip.py index e2b131e8..512cc3e5 100644 --- a/src/cpl/utils/pip.py +++ b/src/cpl/utils/pip.py @@ -5,6 +5,9 @@ from typing import Optional class Pip: + """ + Executes pip commands + """ _executable = sys.executable """ @@ -21,11 +24,20 @@ class Pip: @classmethod def set_executable(cls, executable: str): + """ + Sets the executable + :param executable: + :return: + """ if executable is not None: cls._executable = executable @classmethod def reset_executable(cls): + """ + Resets the executable to system standard + :return: + """ cls._executable = sys.executable """ @@ -34,6 +46,11 @@ class Pip: @classmethod def get_package(cls, package: str) -> Optional[str]: + """ + Gets given package py local pip list + :param package: + :return: + """ result = None with suppress(Exception): result = subprocess.check_output([cls._executable, "-m", "pip", "show", package], stderr=subprocess.DEVNULL) @@ -52,10 +69,23 @@ class Pip: @classmethod def get_outdated(cls) -> bytes: + """ + Gets table of outdated packages + :return: + """ return subprocess.check_output([cls._executable, "-m", "pip", "list", "--outdated"]) @classmethod def install(cls, package: str, *args, source: str = None, stdout=None, stderr=None): + """ + Installs given package + :param package: + :param args: + :param source: + :param stdout: + :param stderr: + :return: + """ pip_args = [cls._executable, "-m", "pip", "install"] for arg in args: @@ -70,4 +100,11 @@ class Pip: @classmethod def uninstall(cls, package: str, stdout=None, stderr=None): + """ + Uninstalls given package + :param package: + :param stdout: + :param stderr: + :return: + """ subprocess.run([cls._executable, "-m", "pip", "uninstall", "--yes", package], stdout=stdout, stderr=stderr) diff --git a/src/cpl/utils/string.py b/src/cpl/utils/string.py index 5ae35ad6..29d2da95 100644 --- a/src/cpl/utils/string.py +++ b/src/cpl/utils/string.py @@ -2,9 +2,17 @@ import re class String: + """ + Useful functions for strings + """ @staticmethod def convert_to_snake_case(name: str) -> str: + """ + Converts string to snake case + :param name: + :return: + """ pattern1 = re.compile(r'(.)([A-Z][a-z]+)') pattern2 = re.compile(r'([a-z0-9])([A-Z])') file_name = re.sub(pattern1, r'\1_\2', name) @@ -12,8 +20,18 @@ class String: @staticmethod def first_to_upper(string: str) -> str: + """ + Converts first char to upper + :param string: + :return: + """ return f'{string[0].upper()}{string[1:]}' @staticmethod def first_to_lower(string: str) -> str: + """ + Converts first char to lower + :param string: + :return: + """ return f'{string[0].lower()}{string[1:]}'