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="."):
|
||||
from frappe.installer import update_site_config
|
||||
|
||||
if os.path.exists(os.path.join(sites_path, site)):
|
||||
with open(os.path.join(sites_path, "currentsite.txt"), "w") as sitefile:
|
||||
sitefile.write(site)
|
||||
sites_path = os.getcwd()
|
||||
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}")
|
||||
else:
|
||||
print(f"Site {site} does not exist")
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import os
|
|||
import traceback
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
|
||||
import click
|
||||
|
||||
|
|
@ -52,10 +53,19 @@ def get_sites(site_arg: str) -> list[str]:
|
|||
return [site_arg]
|
||||
elif os.environ.get("FRAPPE_SITE"):
|
||||
return [os.environ.get("FRAPPE_SITE")]
|
||||
elif os.path.exists("currentsite.txt"):
|
||||
with open("currentsite.txt") as f:
|
||||
if site := f.read().strip():
|
||||
return [site]
|
||||
elif default_site := frappe.get_conf().default_site:
|
||||
return [default_site]
|
||||
# This is not supported, just added here for warning.
|
||||
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 []
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,10 +31,6 @@ function get_conf() {
|
|||
if (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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue