From 6c033a0fb677967145b86ab3360e37857fe940d5 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 31 Aug 2023 20:51:08 +0200 Subject: [PATCH] automatic create global requirements txt if not exists --- main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/main.go b/main.go index cd333c9..523085d 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,7 @@ func init() { createServerDirectoriesIfNotExists() createLogLanguageFilesIfNotExist() + createGlobalRequirementsTxtIfNotExists() utils.ValidatorInit() logger.InitLanguageLogMessages() @@ -175,6 +176,34 @@ MARIADB_DATABASE_NAME=db_database_name` } } +// create global requirements.txt in cfg.PublicStatic groupTasks folder +func createGlobalRequirementsTxtIfNotExists() { + cfg := config.Cfg.FolderPaths + filePath := cfg.GroupTasksGroups + "requirements.txt" + + _, err := os.Stat(filePath) + + if os.IsNotExist(err) { + file, err := os.Create(filePath) + + if err != nil { + log.Error().Msgf("Failed to create global requirements.txt file: %s", err.Error()) + return + } + + defer file.Close() + + _, err = file.WriteString("# HERE YOU CAN DEFINE GLOBAL REQUIREMENTS\n# WHICH WILL BE INSTALLED ON THE SAME WAY AS THE GROUP TASKS REQUIREMENTS,\n# BUT YOU DON'T HAVE TO DEFINE THEM IN EVERY GROUP TASK\n") + + if err != nil { + log.Error().Msgf("Failed to write to requirements.txt file: %s", err.Error()) + return + } + + log.Info().Msgf("Created global requirements.txt file") + } +} + func createServerDirectoriesIfNotExists() { cfg := config.Cfg.FolderPaths