-
Notifications
You must be signed in to change notification settings - Fork 19
/
utils.py
62 lines (49 loc) · 1.58 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import pprint
import subprocess
from colorama import Fore
class Color:
@staticmethod
def print_focus(data: str):
print(Fore.YELLOW+data+Fore.RESET)
@staticmethod
def print_success(data: str):
print(Fore.LIGHTGREEN_EX+data+Fore.RESET)
@staticmethod
def print_failed(data: str):
print(Fore.LIGHTRED_EX+data+Fore.RESET)
@staticmethod
def print(data):
pprint.pprint(data)
class Pattern:
@staticmethod
def create(length: int=8192):
pattern = ''
parts = ['A', 'a', '0']
while len(pattern) != length:
pattern += parts[len(pattern) % 3]
if len(pattern) % 3 == 0:
parts[2] = chr(ord(parts[2]) + 1)
if parts[2] > '9':
parts[2] = '0'
parts[1] = chr(ord(parts[1]) + 1)
if parts[1] > 'z':
parts[1] = 'a'
parts[0] = chr(ord(parts[0]) + 1)
if parts[0] > 'Z':
parts[0] = 'A'
return pattern
@staticmethod
def offset(value: str, length: int=8192):
return Pattern.create(length).index(value)
def popen(cmd:str) -> str:
with subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout as source:
return source.read().decode(encoding="utf-8")
def getenv(key_name, pick=False):
if pick:
if key := os.getenv("PICKER_"+key_name):
return key
else:
return os.getenv(key_name)
else:
return os.getenv(key_name)