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