<commit_before>package tasks

import (
	"fmt"
	"log"
	"os"
	"os/exec"
	"path/filepath"

	"github.com/headmade/backuper/backuper"
)

type Runner struct {
	agentConfig *backuper.AgentConfig
}

func NewRunner(config *backuper.AgentConfig) *Runner {
	return &Runner{agentConfig: config}
}

func (runner *Runner) tmpDirPath() string {
	return runner.agentConfig.TmpDir + "/backuper/"
}

func (runner *Runner) tmpFilePath(tmpFileName string) string {
	return filepath.Join(runner.tmpDirPath(), tmpFileName)
}

func (runner *Runner) prepareTmpDirectory() error {
	log.Println("prepareTmpDirectory():", runner.tmpDirPath())
	return os.MkdirAll(runner.tmpDirPath(), 0700)
}

func (runner *Runner) CleanupTmpDirectory() error {
	log.Println("cleanupTmpDirectory():", runner.tmpDirPath())
	return nil
	return os.RemoveAll(runner.tmpDirPath())
}

func (self *backupTask) EncryptCmd(pass string) string {
	return fmt.Sprintf(
		"openssl aes-128-cbc -pass pass:%s",
		pass,
	)
}

func (runner *Runner) Run() (res *backuper.BackupResult) {
	configs := &runner.agentConfig.Tasks

	res = &backuper.BackupResult{}

	err := runner.prepareTmpDirectory()

	res.Prepare = backuper.TmpDirResult{err, ""}

	res.Backup = make([]backuper.BackupTaskResult, 0, len(*configs))

	for _, config := range *configs {
		task, err := Get(&config)
		if err == nil {
			tmpFilePath := runner.tmpFilePath(task.tmpFileName())
			log.Printf("task type: %s, task object: %#v", config.Type, task)
			out, err := task.GenerateBackupFile(tmpFilePath)
			res.Backup = append(res.Backup, backuper.BackupTaskResult{err, tmpFilePath, string(out)})
		} else {
			log.Printf("task type: %s, no registered handler found", config.Type)
		}
	}
	//backupFileName, err := encryptTmpFiles()
	//res.encrypt
	//uploadBackup(backupFileName)
	runner.CleanupTmpDirectory()
	return
}

// TODO: move to some utils
func System(cmd string) ([]byte, error) {
	return exec.Command("sh", "-c", cmd).CombinedOutput()
}<commit_msg>Reafctor name<commit_after>package tasks

import (
	"fmt"
	"log"
	"os"
	"os/exec"
	"path/filepath"

	"github.com/headmade/backuper/backuper"
)

type Runner struct {
	agentConfig *backuper.AgentConfig
}

func NewRunner(config *backuper.AgentConfig) *Runner {
	return &Runner{agentConfig: config}
}

func (runner *Runner) tmpDirPath() string {
	return runner.agentConfig.TmpDir + "/backuper/"
}

func (runner *Runner) tmpFilePath(tmpFileName string) string {
	return filepath.Join(runner.tmpDirPath(), tmpFileName)
}

func (runner *Runner) prepareTmpDirectory() error {
	log.Println("prepareTmpDirectory():", runner.tmpDirPath())
	return os.MkdirAll(runner.tmpDirPath(), 0700)
}

func (runner *Runner) CleanupTmpDirectory() error {
	log.Println("cleanupTmpDirectory():", runner.tmpDirPath())
	return nil
	return os.RemoveAll(runner.tmpDirPath())
}

func (self *backupTask) EncryptCmd(pass string) string {
	return fmt.Sprintf(
		"openssl aes-128-cbc -pass pass:%s",
		pass,
	)
}

func (runner *Runner) Run() (backupResult *backuper.BackupResult) {
	configs := &runner.agentConfig.Tasks

	backupResult = &backuper.BackupResult{}

	err := runner.prepareTmpDirectory()

	backupResult.Prepare = backuper.TmpDirResult{err, ""}

	backupResult.Backup = make([]backuper.BackupTaskResult, 0, len(*configs))

	for _, config := range *configs {
		task, err := Get(&config)
		if err == nil {
			tmpFilePath := runner.tmpFilePath(task.tmpFileName())
			log.Printf("task type: %s, task object: %#v", config.Type, task)
			out, err := task.GenerateBackupFile(tmpFilePath)
			backupResult.Backup = append(backupResult.Backup, backuper.BackupTaskResult{err, tmpFilePath, string(out)})
		} else {
			log.Printf("task type: %s, no registered handler found", config.Type)
		}
	}
	//backupFileName, err := encryptTmpFiles()
	//backupResult.encrypt
	//uploadBackup(backupFileName)
	runner.CleanupTmpDirectory()
	return
}

// TODO: move to some utils
func System(cmd string) ([]byte, error) {
	return exec.Command("sh", "-c", cmd).CombinedOutput()
}
{'fraction_non_alphanumeric': 0.14705144291091593, 'fraction_numerical': 0.004015056461731493, 'mean_word_length': 5.1894409937888195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '619547', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1363, 'n_words': 297}