fix: get config

This commit is contained in:
lilong.129
2025-03-04 19:39:38 +08:00
parent d50b1f9855
commit e35aa782c2
10 changed files with 56 additions and 40 deletions

View File

@@ -3,6 +3,7 @@ package config
import (
"os"
"path/filepath"
"sync"
"time"
"github.com/rs/zerolog/log"
@@ -17,40 +18,55 @@ const (
ActionLogDirName = "action_log"
)
var (
type Config struct {
RootDir string
ResultsDir string
ResultsPath string
DownloadsPath string
ScreenShotsPath string
StartTime = time.Now()
StartTimeStr = StartTime.Format("20060102150405")
StartTime time.Time
ActionLogFilePath string
DeviceActionLogFilePath string
}
var (
globalConfig *Config
once sync.Once
)
func init() {
var err error
RootDir, err = os.Getwd()
if err != nil {
panic(err)
}
func GetConfig() *Config {
once.Do(func() {
cfg := &Config{
StartTime: time.Now(),
}
ResultsDir = filepath.Join(ResultsDirName, StartTimeStr)
ResultsPath = filepath.Join(RootDir, ResultsDir)
DownloadsPath = filepath.Join(RootDir, filepath.Join(DownloadsDirName, StartTimeStr))
ScreenShotsPath = filepath.Join(ResultsPath, ScreenshotsDirName)
ActionLogFilePath = filepath.Join(ResultsDir, ActionLogDirName)
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
var err error
cfg.RootDir, err = os.Getwd()
if err != nil {
panic(err)
}
// create results directory
if err := builtin.EnsureFolderExists(ResultsPath); err != nil {
log.Fatal().Err(err).Msg("create results directory failed")
}
if err := builtin.EnsureFolderExists(DownloadsPath); err != nil {
log.Fatal().Err(err).Msg("create results directory failed")
}
if err := builtin.EnsureFolderExists(ScreenShotsPath); err != nil {
log.Fatal().Err(err).Msg("create screenshots directory failed")
}
startTimeStr := cfg.StartTime.Format("20060102150405")
cfg.ResultsDir = filepath.Join(ResultsDirName, startTimeStr)
cfg.ResultsPath = filepath.Join(cfg.RootDir, cfg.ResultsDir)
cfg.DownloadsPath = filepath.Join(cfg.RootDir, filepath.Join(DownloadsDirName, startTimeStr))
cfg.ScreenShotsPath = filepath.Join(cfg.ResultsPath, ScreenshotsDirName)
cfg.ActionLogFilePath = filepath.Join(cfg.ResultsDir, ActionLogDirName)
cfg.DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
// create results directory
if err := builtin.EnsureFolderExists(cfg.ResultsPath); err != nil {
log.Fatal().Err(err).Msg("create results directory failed")
}
if err := builtin.EnsureFolderExists(cfg.DownloadsPath); err != nil {
log.Fatal().Err(err).Msg("create downloads directory failed")
}
if err := builtin.EnsureFolderExists(cfg.ScreenShotsPath); err != nil {
log.Fatal().Err(err).Msg("create screenshots directory failed")
}
globalConfig = cfg
})
return globalConfig
}

View File

@@ -1 +1 @@
v5.0.0+2503041818
v5.0.0+2503041939