Exemplo n.º 1
0
func ensureLogsDirectory(logsDirectory string) {
	err := os.MkdirAll(logsDirectory, 0700)
	if err != nil {
		log.Error("Cannot create the logs directory ('%v'). %v", logsDirectory, err)
		os.Exit(v3.ExitCodeError)
	}
}
Exemplo n.º 2
0
func (app *App) SaveReferenceDescriptor() (referenceDescriptorSaved bool) {
	referenceDescriptor, err := app.GetReferenceDescriptor()
	if err != nil {
		log.Warning("Cannot save the reference descriptor: %v", err)
		return false
	}

	log.Info("Saving the reference descriptor as the local descriptor...")
	referenceDescriptorBytes, err := referenceDescriptor.GetBytes()
	if err != nil {
		log.Error("Could not serialize the reference descriptor: %v", err)
		return false
	}

	err = ioutil.WriteFile(app.localDescriptorPath, referenceDescriptorBytes, 0600)
	if err != nil {
		log.Error("Could not save the reference descriptor: %v", err)
		return false
	}

	log.Notice("Reference descriptor saved")
	return true
}
Exemplo n.º 3
0
func getMoonSettings() *MoonSettings {
	if moonSettings != nil {
		return moonSettings
	}

	rawMoonSettings := getRawMoonSettings()

	moonSettings = &MoonSettings{}

	if rawMoonSettings.LocalDirectory != "" {
		moonSettings.localDirectory = rawMoonSettings.LocalDirectory
	} else {
		userDir, err := caravel.GetUserDirectory()
		if err != nil {
			log.Error("Cannot retrieve the user's directory")
			os.Exit(v3.ExitCodeError)
		}

		moonSettings.localDirectory = filepath.Join(userDir, defaultLocalDirName)
	}

	moonSettings.galleryDirectory = filepath.Join(moonSettings.localDirectory, galleryDirName)
	moonSettings.logsDirectory = filepath.Join(moonSettings.localDirectory, logsDirName)

	if rawMoonSettings.BufferSize > 0 {
		moonSettings.bufferSize = rawMoonSettings.BufferSize
	} else {
		moonSettings.bufferSize = defaultBufferSize
	}

	moonSettings.loggingLevel = parseLoggingLevel(rawMoonSettings.LoggingLevel)

	moonSettings.skipAppOutput = rawMoonSettings.SkipAppOutput

	if 0 <= rawMoonSettings.BackgroundColor && rawMoonSettings.BackgroundColor <= 255 {
		moonSettings.backgroundColor = rawMoonSettings.BackgroundColor
	} else {
		moonSettings.backgroundColor = defaultBackgroundColor
	}

	if 0 <= rawMoonSettings.ForegroundColor && rawMoonSettings.ForegroundColor <= 255 {
		moonSettings.foregroundColor = rawMoonSettings.ForegroundColor
	} else {
		moonSettings.foregroundColor = defaultForegroundColor
	}

	return moonSettings
}
Exemplo n.º 4
0
func createLogFile(logsDirectory string) *os.File {
	now := time.Now()

	logFileName := fmt.Sprintf("MoonDeploy - %d-%d-%d %d-%d-%d %d.log",
		now.Year(),
		now.Month(),
		now.Day(),
		now.Hour(),
		now.Minute(),
		now.Second(),
		now.Nanosecond())

	logFilePath := filepath.Join(logsDirectory, logFileName)

	logFile, err := os.Create(logFilePath)
	if err != nil {
		log.Error("Cannot create the log file '%v'! %v", logFilePath, err.Error())
		os.Exit(v3.ExitCodeError)
	}

	return logFile
}
func (userInterface *TerminalUserInterface) ShowError(message string) {
	userInterface.Hide()

	log.Error(message)
}
Exemplo n.º 6
0
func exitWithError(err error) {
	log.Error(err.Error())
	os.Exit(v3.ExitCodeError)
}