2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

feat: added bench.utils.log and updated is_bench_directory api

This commit is contained in:
Gavin D'souza 2020-01-10 14:48:09 +05:30
parent ef1a624556
commit e32281557f

View File

@ -17,17 +17,29 @@ logger = logging.getLogger(__name__)
folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids')
def is_bench_directory():
cur_dir = os.path.curdir
def is_bench_directory(directory=os.path.curdir):
is_bench = True
for folder in folders_in_bench:
path = os.path.join(cur_dir, folder)
path = os.path.abspath(os.path.join(directory, folder))
is_bench = is_bench and os.path.exists(path)
return is_bench
def log(message, level=0):
levels = {
0: '\033[94m', # normal
1: '\033[92m', # success
2: '\033[91m', # fail
3: '\033[93m' # warn/suggest
}
start = levels.get(level) or ''
end = '\033[0m'
print(start + message + end)
def safe_decode(string, encoding = 'utf-8'):
try:
string = string.decode(encoding)