mirror of
https://github.com/frappe/bench.git
synced 2024-11-13 16:56:33 +00:00
fix: added code removed via erroneous commit
This commit is contained in:
parent
7f678a3047
commit
7e28a3dd9e
31
bench/app.py
31
bench/app.py
@ -94,7 +94,6 @@ class AppMeta:
|
||||
self._setup_details_from_name_tag()
|
||||
|
||||
def _setup_details_from_mounted_disk(self):
|
||||
self.branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
|
||||
self.org, self.repo, self.tag = os.path.split(self.name)[-2:] + (self.branch,)
|
||||
|
||||
def _setup_details_from_name_tag(self):
|
||||
@ -102,7 +101,6 @@ class AppMeta:
|
||||
self.tag = self.tag or self.branch
|
||||
|
||||
def _setup_details_from_installed_apps(self):
|
||||
self.branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
|
||||
self.org, self.repo, self.tag = os.path.split(
|
||||
os.path.join(self.bench.name, "apps", self.name)
|
||||
)[-2:] + (self.branch,)
|
||||
@ -178,31 +176,30 @@ class App(AppMeta):
|
||||
shutil.move(active_app_path, archived_app_path)
|
||||
|
||||
@step(title="Installing App {repo}", success="App {repo} Installed")
|
||||
def install(self, skip_assets=False, verbose=False):
|
||||
def install(self, skip_assets=False, verbose=False, resolved=False):
|
||||
import bench.cli
|
||||
from bench.utils.app import get_app_name
|
||||
|
||||
verbose = bench.cli.verbose or verbose
|
||||
app_name = get_app_name(self.bench.name, self.repo)
|
||||
|
||||
# TODO: this should go inside install_app only tho - issue: default/resolved branch
|
||||
setup_app_dependencies(
|
||||
repo_name=self.repo,
|
||||
bench_path=self.bench.name,
|
||||
branch=self.tag,
|
||||
verbose=verbose,
|
||||
skip_assets=skip_assets,
|
||||
)
|
||||
if not resolved:
|
||||
# TODO: this should go inside install_app only tho - issue: default/resolved branch
|
||||
setup_app_dependencies(
|
||||
repo_name=self.repo,
|
||||
bench_path=self.bench.name,
|
||||
branch=self.tag,
|
||||
verbose=verbose,
|
||||
skip_assets=skip_assets,
|
||||
)
|
||||
|
||||
install_app(
|
||||
app=app_name, bench_path=self.bench.name, verbose=verbose, skip_assets=skip_assets,
|
||||
app=app_name, tag=self.tag, bench_path=self.bench.name, verbose=verbose, skip_assets=skip_assets,
|
||||
)
|
||||
|
||||
@step(title="Cloning and installing {repo}", success="App {repo} Installed")
|
||||
def install_resolved_apps(self, *args, **kwargs):
|
||||
self.get()
|
||||
self.install(*args, **kwargs, resolved=True)
|
||||
self.bench.apps.update_apps_states(self.repo, self.tag)
|
||||
|
||||
@step(title="Uninstalling App {repo}", success="App {repo} Uninstalled")
|
||||
def uninstall(self):
|
||||
@ -217,11 +214,9 @@ class App(AppMeta):
|
||||
lines = [x for x in f.split("\n") if x.strip().startswith("required_apps")]
|
||||
required_apps = eval(lines[0].strip("required_apps").strip().lstrip("=").strip())
|
||||
return required_apps
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
return info_file["required_apps"] if info_file else {}
|
||||
|
||||
def make_resolution_plan(app: App, bench: "Bench"):
|
||||
"""
|
||||
decide what apps and versions to install and in what order
|
||||
@ -473,6 +468,7 @@ def new_app(app, no_git=None, bench_path="."):
|
||||
|
||||
def install_app(
|
||||
app,
|
||||
tag,
|
||||
bench_path=".",
|
||||
verbose=False,
|
||||
no_cache=False,
|
||||
@ -504,6 +500,7 @@ def install_app(
|
||||
bench.run("yarn install", cwd=app_path)
|
||||
|
||||
bench.apps.sync()
|
||||
bench.apps.update_apps_states(app, tag)
|
||||
|
||||
if not skip_assets:
|
||||
build_assets(bench_path=bench_path, app=app)
|
||||
|
@ -57,7 +57,6 @@ class Bench(Base, Validator):
|
||||
def __init__(self, path):
|
||||
self.name = path
|
||||
self.cwd = os.path.abspath(path)
|
||||
self.apps_states = os.path.join(self.name, "sites", "apps_states.json")
|
||||
self.exists = is_bench_directory(self.name)
|
||||
|
||||
self.setup = BenchSetup(self)
|
||||
@ -151,19 +150,20 @@ class Bench(Base, Validator):
|
||||
class BenchApps(MutableSequence):
|
||||
def __init__(self, bench: Bench):
|
||||
self.bench = bench
|
||||
self.states_path = os.path.join(self.bench.name, "sites", "apps_states.json")
|
||||
self.initialize_apps()
|
||||
|
||||
def initialize_states(self):
|
||||
def set_states(self):
|
||||
try:
|
||||
with open(self.bench.apps_states, "r") as f:
|
||||
with open(self.states_path, "r") as f:
|
||||
self.states = json.loads(f.read() or "{}")
|
||||
except FileNotFoundError:
|
||||
with open(self.bench.apps_states, "w") as f:
|
||||
with open(self.states_path, "w+") as f:
|
||||
self.states = json.loads(f.read() or "{}")
|
||||
|
||||
def update_apps_states(self, app_name: str = None, resolution: str = None):
|
||||
self.initialize_states()
|
||||
self.initialize_apps()
|
||||
self.set_states()
|
||||
apps_to_remove = []
|
||||
for app in self.states:
|
||||
if app not in self.apps:
|
||||
@ -172,14 +172,14 @@ class BenchApps(MutableSequence):
|
||||
for app in apps_to_remove:
|
||||
del self.states[app]
|
||||
|
||||
if app_name and resolution:
|
||||
version = get_current_version(app_name)
|
||||
if app_name:
|
||||
version = get_current_version(app_name, self.bench.name)
|
||||
self.states[app_name] = {
|
||||
"resolution": resolution,
|
||||
"version": version,
|
||||
}
|
||||
|
||||
with open(self.bench.apps_states, "w") as f:
|
||||
with open(self.states_path, "w") as f:
|
||||
f.write(json.dumps(self.states, indent=4))
|
||||
|
||||
def sync(self):
|
||||
|
@ -208,6 +208,10 @@ def get_app_name(bench_path, repo_name):
|
||||
|
||||
return repo_name
|
||||
|
||||
def check_existing_dir(bench_path, repo_name):
|
||||
cloned_path = os.path.join(bench_path, "apps", repo_name)
|
||||
dir_already_exists = os.path.isdir(cloned_path)
|
||||
return dir_already_exists, cloned_path
|
||||
|
||||
def get_current_version(app, bench_path="."):
|
||||
current_version = None
|
||||
|
Loading…
Reference in New Issue
Block a user