mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 09:02:10 +00:00
Merge pull request #1006 from gavindsouza/cleanup-logger
fix: exit with appropriate return code
This commit is contained in:
commit
b8d3dc3d61
@ -127,6 +127,7 @@ Do you want to continue and overwrite it?'''.format(repo_name)):
|
|||||||
install_app(app=app_name, bench_path=bench_path, verbose=verbose, skip_assets=skip_assets)
|
install_app(app=app_name, bench_path=bench_path, verbose=verbose, skip_assets=skip_assets)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
print('\n{0}Getting {1}{2}'.format(color.yellow, repo_name, color.nc))
|
||||||
logger.log('Getting app {0}'.format(repo_name))
|
logger.log('Getting app {0}'.format(repo_name))
|
||||||
exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream".format(
|
exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream".format(
|
||||||
git_url=git_url,
|
git_url=git_url,
|
||||||
|
@ -59,8 +59,10 @@ def cli():
|
|||||||
try:
|
try:
|
||||||
bench_command()
|
bench_command()
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
logger.warn("{0} executed with exit code {1}".format(command, getattr(e, "code", None)))
|
return_code = getattr(e, "code", 0)
|
||||||
sys.exit(1)
|
if return_code:
|
||||||
|
logger.warning("{0} executed with exit code {1}".format(command, return_code))
|
||||||
|
sys.exit(return_code)
|
||||||
|
|
||||||
|
|
||||||
def check_uid():
|
def check_uid():
|
||||||
|
@ -302,7 +302,7 @@ def exec_cmd(cmd, cwd='.'):
|
|||||||
cmd = shlex.split(cmd)
|
cmd = shlex.split(cmd)
|
||||||
return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True)
|
return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True)
|
||||||
if return_code:
|
if return_code:
|
||||||
logger.warn("{0} executed with exit code {1}".format(cmd_log, return_code))
|
logger.warning("{0} executed with exit code {1}".format(cmd_log, return_code))
|
||||||
|
|
||||||
|
|
||||||
def which(executable, raise_err = False):
|
def which(executable, raise_err = False):
|
||||||
@ -435,26 +435,13 @@ def setup_logging(bench_path='.'):
|
|||||||
self._log(LOG_LEVEL, message, args, **kws)
|
self._log(LOG_LEVEL, message, args, **kws)
|
||||||
logging.Logger.log = logv
|
logging.Logger.log = logv
|
||||||
|
|
||||||
class log_filter(object):
|
|
||||||
def __init__(self, level):
|
|
||||||
self.__level = level
|
|
||||||
|
|
||||||
def filter(self, logRecord):
|
|
||||||
return logRecord.levelno == self.__level
|
|
||||||
|
|
||||||
if os.path.exists(os.path.join(bench_path, 'logs')):
|
if os.path.exists(os.path.join(bench_path, 'logs')):
|
||||||
logger = logging.getLogger(bench.PROJECT_NAME)
|
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||||
log_file = os.path.join(bench_path, 'logs', 'bench.log')
|
log_file = os.path.join(bench_path, 'logs', 'bench.log')
|
||||||
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
|
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
|
||||||
hdlr = logging.FileHandler(log_file)
|
hdlr = logging.FileHandler(log_file)
|
||||||
hdlr.setFormatter(formatter)
|
hdlr.setFormatter(formatter)
|
||||||
|
|
||||||
log_hndlr = logging.StreamHandler(sys.stdout)
|
|
||||||
log_hndlr.setFormatter(logging.Formatter('%(message)s'))
|
|
||||||
log_hndlr.addFilter(log_filter(LOG_LEVEL))
|
|
||||||
|
|
||||||
logger.addHandler(hdlr)
|
logger.addHandler(hdlr)
|
||||||
logger.addHandler(log_hndlr)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
return logger
|
return logger
|
||||||
@ -985,7 +972,7 @@ def migrate_env(python, backup=False):
|
|||||||
logger.log('Clearing Redis DataBase...')
|
logger.log('Clearing Redis DataBase...')
|
||||||
exec_cmd('{redis} FLUSHDB'.format(redis = redis))
|
exec_cmd('{redis} FLUSHDB'.format(redis = redis))
|
||||||
except:
|
except:
|
||||||
logger.warn('Please ensure Redis Connections are running or Daemonized.')
|
logger.warning('Please ensure Redis Connections are running or Daemonized.')
|
||||||
|
|
||||||
# Backup venv: restore using `virtualenv --relocatable` if needed
|
# Backup venv: restore using `virtualenv --relocatable` if needed
|
||||||
if backup:
|
if backup:
|
||||||
@ -1015,7 +1002,7 @@ def migrate_env(python, backup=False):
|
|||||||
logger.log('Migration Successful to {}'.format(python))
|
logger.log('Migration Successful to {}'.format(python))
|
||||||
except:
|
except:
|
||||||
if venv_creation or packages_setup:
|
if venv_creation or packages_setup:
|
||||||
logger.warn('Migration Error')
|
logger.warning('Migration Error')
|
||||||
|
|
||||||
|
|
||||||
def is_dist_editable(dist):
|
def is_dist_editable(dist):
|
||||||
|
Loading…
Reference in New Issue
Block a user