def update_domains_structure(c, dst_path, answers_rel_path): """Migrates from v1 to v2 domain structure. In template v1: - domain_prod was a str - domain_prod_alternatives was a list of str - domain_test was a str In template v2, we support multiple domains: - domains_prod is a dict {main: [redirected, ...], ...} - domains_staging is a list of str """ answers_path = Path(dst_path, answers_rel_path) answers_yaml = _load_yaml(answers_path) answers_yaml.setdefault( "domains_prod", { answers_yaml.pop("domain_prod", None): answers_yaml.pop("domain_prod_alternatives", None) or [] }, ) domain_test = answers_yaml.pop("domain_test", None) answers_yaml.setdefault("domains_staging", [domain_test] if domain_test else []) answers_path.write_text(yaml.safe_dump(answers_yaml))
def update_domains_structure(c, dst_path, answers_rel_path): """Migrates from v1 to v2 domain structure. In template v1: - domain_prod was a str - domain_prod_alternatives was a list of str - domain_test was a str In template v2, we support multiple domains: - domains_prod is a list of dicts - domains_test is a list of dicts """ answers_path = Path(dst_path, answers_rel_path) answers_yaml = _load_yaml(answers_path) # Update domains_prod domain_prod = answers_yaml.pop("domain_prod", None) domain_prod_alternatives = answers_yaml.pop("domain_prod_alternatives", None) new_domains_prod = [] if domain_prod: new_domains_prod.append({ "hosts": [domain_prod], "cert_resolver": "letsencrypt" }) if domain_prod_alternatives: new_domains_prod.append({ "hosts": domain_prod_alternatives, "cert_resolver": "letsencrypt", "redirect_to": domain_prod, }) answers_yaml.setdefault("domains_prod", new_domains_prod) # Update domains_test domain_test = answers_yaml.pop("domain_test", None) new_domains_test = [] if domain_test: new_domains_test.append({ "hosts": [domain_test], "cert_resolver": "letsencrypt" }) answers_yaml.setdefault("domains_test", new_domains_test) answers_path.write_text(yaml.safe_dump(answers_yaml)) # Remove .env file Path(dst_path, ".env").unlink()
def update_no_license(c, dst_path, answers_rel_path): """Update projects with no license. In template version < 3.0.0, no license was `None`. In 3.0.0 it was changed to `""`, to make it compatible with Copier 6, but that made it not work fine with Copier 5. So, in version 3.0.1 it was changed to `"no_license"`. This value will always be a string, no matter the parser, and should make the parameter work fine in any Copier version. This migrates old answers to this new format. """ answers_path = Path(dst_path, answers_rel_path) answers_yaml = _load_yaml(answers_path) if (not answers_yaml.get("project_license") or answers_yaml.get("project_license") == "no_license"): answers_yaml["project_license"] = "no_license" answers_path.write_text(yaml.safe_dump(answers_yaml)) # Delete LICENSE if it existed but was empty license = Path(dst_path, "LICENSE") try: if not license.read_text().strip(): license.unlink() except FileNotFoundError: pass # LICENSE does not exist, and that's good