1
0
Fork 0
mirror of https://github.com/cosmo-sims/cosmICweb-music.git synced 2024-09-19 16:53:43 +02:00

use click to open editor

This commit is contained in:
Lukas Winkler 2024-04-27 19:32:46 +02:00
parent eed3641aa8
commit 9f9bb3fbd1
Signed by: lukas
GPG key ID: 54DE4D798D244853

View file

@ -24,8 +24,6 @@ logger.setLevel("INFO")
# Some constants
DEFAULT_URL = "https://cosmicweb.eu"
EDITOR = os.environ.get("EDITOR", "vim")
EDITOR_IS_VIM = EDITOR in {"vim", "nvim"}
def query_yes_no(question: str, default="yes") -> bool:
@ -176,17 +174,10 @@ def fetch_multiple(
def edit_template(template: str) -> str:
with tempfile.NamedTemporaryFile(suffix=".tmp.conf", mode="r+") as tf:
tf.write(template)
tf.flush()
editor_parameters = []
if EDITOR_IS_VIM:
# backupcopy=yes prevents vim from creating copy and rename
editor_parameters.append("+set backupcopy=yes")
subprocess.call([EDITOR] + editor_parameters + [tf.name])
tf.seek(0)
template = tf.read()
return template
return_value = click.edit(template, extension=".conf")
if return_value is None:
return template
return return_value
def apply_config_parameter(config: str, parameters: dict[str, Any]) -> str: