refactor!: Drop support for currentsite.txt (#21536)
* refactor!: Drop currentsite.txt - `bench use` will continue to work. - Instead of txt file use common_site_config to set default site using `default_site` key. - `FRAPPE_SITE` environment variable also works * fix(DX): warn if non-empty currentsite.txt is present
This commit is contained in:
parent
f5e75c2fef
commit
441495b561
3 changed files with 19 additions and 10 deletions
|
|
@ -700,9 +700,12 @@ def _use(site, sites_path="."):
|
||||||
|
|
||||||
|
|
||||||
def use(site, sites_path="."):
|
def use(site, sites_path="."):
|
||||||
|
from frappe.installer import update_site_config
|
||||||
|
|
||||||
if os.path.exists(os.path.join(sites_path, site)):
|
if os.path.exists(os.path.join(sites_path, site)):
|
||||||
with open(os.path.join(sites_path, "currentsite.txt"), "w") as sitefile:
|
sites_path = os.getcwd()
|
||||||
sitefile.write(site)
|
conifg = os.path.join(sites_path, "common_site_config.json")
|
||||||
|
update_site_config("default_site", site, validate=False, site_config_path=conifg)
|
||||||
print(f"Current Site set to {site}")
|
print(f"Current Site set to {site}")
|
||||||
else:
|
else:
|
||||||
print(f"Site {site} does not exist")
|
print(f"Site {site} does not exist")
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import os
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
|
@ -52,10 +53,19 @@ def get_sites(site_arg: str) -> list[str]:
|
||||||
return [site_arg]
|
return [site_arg]
|
||||||
elif os.environ.get("FRAPPE_SITE"):
|
elif os.environ.get("FRAPPE_SITE"):
|
||||||
return [os.environ.get("FRAPPE_SITE")]
|
return [os.environ.get("FRAPPE_SITE")]
|
||||||
elif os.path.exists("currentsite.txt"):
|
elif default_site := frappe.get_conf().default_site:
|
||||||
with open("currentsite.txt") as f:
|
return [default_site]
|
||||||
if site := f.read().strip():
|
# This is not supported, just added here for warning.
|
||||||
return [site]
|
elif (site := frappe.read_file("currentsite.txt")) and site.strip():
|
||||||
|
click.secho(
|
||||||
|
dedent(
|
||||||
|
f"""
|
||||||
|
WARNING: currentsite.txt is not supported anymore for setting default site. Use following command to set it as default site.
|
||||||
|
$ bench use {site}"""
|
||||||
|
),
|
||||||
|
fg="red",
|
||||||
|
)
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,6 @@ function get_conf() {
|
||||||
if (process.env.FRAPPE_SITE) {
|
if (process.env.FRAPPE_SITE) {
|
||||||
conf.default_site = process.env.FRAPPE_SITE;
|
conf.default_site = process.env.FRAPPE_SITE;
|
||||||
}
|
}
|
||||||
if (fs.existsSync("sites/currentsite.txt")) {
|
|
||||||
conf.default_site = fs.readFileSync("sites/currentsite.txt").toString().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue