def create_template( templating: Templating, template_name: str, target_path: Path, name: str, services: List[str], auth: str, force: bool, project: str, ) -> None: if not force and target_path.exists(): print_and_exit("{} already exists", target_path) template = templating.get_template( template_name, { "name": name, "services": services, "auth_service": auth, "project": project }, ) templating.save_template(target_path, template, force=force)
def create_projectrc(self) -> None: templating = Templating() t = templating.get_template( "projectrc", { "project": Configuration.project, "hostname": Configuration.hostname, "swarm": Configuration.swarm_mode, "production": Configuration.production, "testing": Configuration.testing, "services": self.active_services, "env_variables": Configuration.environment, }, ) templating.save_template(PROJECTRC, t, force=True) Application.load_projectrc() if not self.files: log.debug("Created temporary default {} file", PROJECTRC) PROJECTRC.unlink() else: log.info("Created default {} file", PROJECTRC)
def create_project( project_name: str, auth: str, frontend: str, services: List[str], extend: Optional[str], envs: Optional[List[str]] = None, auto: bool = False, force: bool = False, force_current: bool = False, add_optionals: bool = False, path: Path = None, ) -> None: project_scaffold = Project() enable_postgres = auth == "postgres" or "postgres" in services enable_mysql = auth == "mysql" or "mysql" in services enable_neo4j = auth == "neo4j" or "neo4j" in services enable_rabbit = "rabbit" in services enable_redis = "redis" in services enable_celery = "celery" in services enable_flower = "flower" in services enable_fail2ban = "fail2ban" in services enable_ftp = "ftp" in services enable_bot = "bot" in services if auth == "postgres" or auth == "mysql": auth = "sqlalchemy" if auth == "no": auth = NO_AUTHENTICATION if frontend == "no": frontend = NO_FRONTEND if not force_current: dirs = os.listdir(".") if dirs and dirs != [".git"]: print_and_exit( "Current folder is not empty, cannot create a new project here.\n" "Found: {}\n" "Use --current to force the creation here", ", ".join(dirs[0:3]), # add first 3 files/folders found ) celery_broker = None # Keep default value == REDIS celery_backend = None # Keep default value == REDIS if enable_celery: if enable_rabbit: celery_broker = "RABBIT" else: celery_broker = "REDIS" enable_redis = True if enable_redis: celery_backend = "REDIS" else: celery_backend = "RABBIT" env_variables = parse_env_variables(envs) project_scaffold.load_project_scaffold(project_name, auth, services) if frontend != NO_FRONTEND: project_scaffold.load_frontend_scaffold(frontend) # In case of errors this function will exit project_scaffold.check_invalid_characters(project_name) if project_name in project_scaffold.reserved_project_names: print_and_exit( "You selected a reserved name, invalid project name: {}", project_name) templating = Templating() folders = project_scaffold.expected_folders + project_scaffold.data_folders if add_optionals: folders += project_scaffold.optionals_folders for f in folders: if f.exists(): log.debug("Project folder already exists: {}", f) continue if not auto: print_and_exit("\nmkdir -p {}", f) f.mkdir(parents=True, exist_ok=True) for f in project_scaffold.suggested_gitkeep: f.open("a").close() files = project_scaffold.expected_files if add_optionals: files += project_scaffold.optionals_files if path: if path not in files: print_and_exit("Invalid path, cannot upgrade {}", path) else: files = [path] for p in files: template = templating.get_template( p.name, { "version": __version__, "project": project_name, "auth_service": auth, "enable_postgres": enable_postgres, "enable_mysql": enable_mysql, "enable_neo4j": enable_neo4j, "enable_rabbit": enable_rabbit, "enable_redis": enable_redis, "enable_celery": enable_celery, "enable_flower": enable_flower, "enable_fail2ban": enable_fail2ban, "enable_ftp": enable_ftp, "enable_bot": enable_bot, "celery_broker": celery_broker, "celery_backend": celery_backend, "frontend": frontend, "testing": Configuration.testing, "extend": extend, "services": services, "env_variables": env_variables, }, ) # automatic creation if auto: if p.exists() and not force: log.info("Project file already exists: {}", p) else: templating.save_template(p, template, force=force) continue # manual creation if p.exists(): log.info("Project file already exists: {}", p) else: print(f"\n{template}") print_and_exit(str(p)) if not path: for p in project_scaffold.raw_files: # automatic creation if auto: if p.exists() and not force: log.info("Project file already exists: {}", p) else: shutil.copyfile(templating.template_dir.joinpath(p.name), p) continue # manual creation if p.exists(): log.info("Project file already exists: {}", p) else: # print(f"Missing file: {p}") print_and_exit("File is missing: {}", p)