2021.4 #19

Merged
edraft merged 237 commits from 2021.4 into master 2021-04-01 10:13:33 +02:00
3 changed files with 74 additions and 0 deletions
Showing only changes of commit ac1b4b1a2a - Show all commits

View File

@ -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))

View File

@ -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)

View File

@ -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:]}'