2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 08:16:28 +00:00

Merge pull request #1243 from gavindsouza/get-system-fixes

fix: Misc fixes
This commit is contained in:
gavin 2021-12-28 17:57:20 +05:30 committed by GitHub
commit 5213807d8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 14 deletions

View File

@ -94,6 +94,7 @@ class AppMeta:
def _setup_details_from_name_tag(self):
self.org, self.repo, self.tag = fetch_details_from_tag(self.name)
self.tag = self.tag or self.branch
def _setup_details_from_installed_apps(self):
self.org, self.repo, self.tag = os.path.split(
@ -105,9 +106,11 @@ class AppMeta:
def __setup_details_from_git(self):
if self.use_ssh:
self.org, _repo = self.name.split(":")[1].split("/")
_first_part, _second_part = self.name.split(":")
self.remote_server = _first_part.split("@")[-1]
self.org, _repo = _second_part.split("/")
else:
self.org, _repo = self.name.split("/")[-2:]
self.remote_server, self.org, _repo = self.name.split("/")[-3:]
self.tag = self.branch
self.repo = _repo.split(".")[0]

View File

@ -25,6 +25,7 @@ from bench.utils import (
is_root,
log,
setup_logging,
parse_sys_argv,
)
from bench.utils.bench import get_env_cmd
@ -34,19 +35,24 @@ verbose = False
is_envvar_warn_set = None
from_command_line = False # set when commands are executed via the CLI
bench.LOG_BUFFER = []
sys_argv = None
change_uid_msg = "You should not run this command as root"
src = os.path.dirname(__file__)
def cli():
global from_command_line, bench_config, is_envvar_warn_set
global from_command_line, bench_config, is_envvar_warn_set, verbose, sys_argv
from_command_line = True
command = " ".join(sys.argv)
argv = set(sys.argv)
is_envvar_warn_set = not (os.environ.get("BENCH_DEVELOPER") or os.environ.get("CI"))
is_cli_command = len(sys.argv) > 1 and not argv.intersection({"src", "--version"})
sys_argv = parse_sys_argv()
if "--verbose" in sys_argv.options:
verbose = True
change_working_directory()
logger = setup_logging()
@ -89,13 +95,10 @@ def cli():
print(get_frappe_help())
return
if sys.argv[1] in ["--site", "--force", "--profile"]:
frappe_cmd()
if sys.argv[1] in get_cached_frappe_commands():
frappe_cmd()
if sys.argv[1] in get_frappe_commands():
if (
sys_argv.commands.intersection(get_cached_frappe_commands())
or sys_argv.commands.intersection(get_frappe_commands())
):
frappe_cmd()
if sys.argv[1] in Bench(".").apps:
@ -185,15 +188,15 @@ def frappe_cmd(bench_path="."):
def get_cached_frappe_commands():
if os.path.exists(bench_cache_file):
command_dump = open(bench_cache_file, "r").read() or "[]"
return json.loads(command_dump)
return []
return set(json.loads(command_dump))
return set()
def get_frappe_commands():
if not is_bench_directory():
return []
return set()
return generate_command_cache()
return set(generate_command_cache())
def get_frappe_help(bench_path="."):

View File

@ -471,3 +471,38 @@ def get_traceback() -> str:
trace_list = format_exception(exc_type, exc_value, exc_tb)
return "".join(trace_list)
class _dict(dict):
"""dict like object that exposes keys as attributes"""
# bench port of frappe._dict
def __getattr__(self, key):
ret = self.get(key)
# "__deepcopy__" exception added to fix frappe#14833 via DFP
if not ret and key.startswith("__") and key != "__deepcopy__":
raise AttributeError()
return ret
def __setattr__(self, key, value):
self[key] = value
def __getstate__(self):
return self
def __setstate__(self, d):
self.update(d)
def update(self, d):
"""update and return self -- the missing dict feature in python"""
super(_dict, self).update(d)
return self
def copy(self):
return _dict(dict(self).copy())
def parse_sys_argv():
sys_argv = _dict(options=set(), commands=set())
for c in sys.argv[1:]:
if c.startswith("-"):
sys_argv.options.add(c)
else:
sys_argv.commands.add(c)
return sys_argv