Skip to content

Commit

Permalink
Allow disabling filters via the 'disabled' key
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLich committed Oct 11, 2021
1 parent f1b793f commit ec25e4b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
47 changes: 31 additions & 16 deletions regolith/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func GetExportPaths(exportTarget ExportTarget, name string) (bpPath string, rpPa

// ExportProject copies files from the tmp paths (tmp/BP and tmp/RP) into
// the project's export target. The paths are generated with GetExportPaths.

func ExportProject(profile Profile, name string) error {
exportTarget := profile.ExportTarget
bpPath, rpPath, err := GetExportPaths(exportTarget, name)
Expand All @@ -78,8 +79,9 @@ func ExportProject(profile Profile, name string) error {
"Regolith for the first time on this project make sure that the " +
"export paths are empty. Otherwise, you can check \"" +
EditedFilesPath + "\" file to see if it contains the full list of " +
"the files that can be reomved.")
"the files that can be removed.")
}

// Clearing output locations
// Spooky, I hope file protection works, and it won't do any damage
err = os.RemoveAll(bpPath)
Expand All @@ -90,25 +92,26 @@ func ExportProject(profile Profile, name string) error {
if err != nil {
return wrapError("Failed to clear resource pack build output", err)
}
err = os.RemoveAll(profile.DataPath)
if err != nil {
return wrapError("Failed to clear filter data path", err)
}

Logger.Info("Exporting project to ", bpPath)
Logger.Info("Exporting project to ", rpPath)
err = CopyOrMove(".regolith/tmp/BP", bpPath)
if err != nil {
return err
}

err = os.Rename(".regolith/tmp/BP/", bpPath)
if err != nil { // Rename might fail if output path is on a different drive
Logger.Infof("Couldn't move BP files to %s. Trying to copy files instead...", bpPath)
err = copy.Copy(".regolith/tmp/BP/", bpPath, copy.Options{PreserveTimes: false, Sync: false})
if err != nil {
return wrapError(fmt.Sprintf("Couldn't copy BP files to %s", bpPath), err)
}
Logger.Info("Exporting project to ", rpPath)
err = CopyOrMove(".regolith/tmp/RP", rpPath)
if err != nil {
return err
}
err = os.Rename(".regolith/tmp/RP/", rpPath)
if err != nil { // Rename might fail if output path is on a different drive
Logger.Infof("Couldn't move RP files to %s. Trying to copy files instead...", rpPath)
err = copy.Copy(".regolith/tmp/RP/", rpPath, copy.Options{PreserveTimes: false, Sync: false})
if err != nil {
return wrapError(fmt.Sprintf("Couldn't copy RP files to %s", rpPath), err)
}

err = CopyOrMove(".regolith/tmp/data", profile.DataPath)
if err != nil {
return err
}

// Create new edited_files.json
Expand All @@ -119,3 +122,15 @@ func ExportProject(profile Profile, name string) error {
err = editedFiles.Dump()
return err
}

func CopyOrMove(source string, destination string) error {
err := os.Rename(source, destination)
if err != nil { // Rename might fail if output path is on a different drive
Logger.Infof("Couldn't move files to %s. Trying to copy files instead...", destination)
err = copy.Copy(source, destination, copy.Options{PreserveTimes: false, Sync: false})
if err != nil {
return wrapError(fmt.Sprintf("Couldn't copy data files to %s, aborting.", destination), err)
}
}
return nil
}
6 changes: 6 additions & 0 deletions regolith/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func (filter *Filter) RunFilter(absoluteLocation string) error {
Logger.Info(filter.GetName())
start := time.Now()

// Disabled filters are skipped
if filter.Disabled == true {
Logger.Infof("Filter '%s' is disabled, skipping.", filter.GetName())
return nil
}

if filter.Url != "" {
err := RunRemoteFilter(filter.Url, *filter)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions regolith/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Profile struct {
type Filter struct {
Name string `json:"name"`
Script string `json:"script"`
Disabled bool `json:"disabled"`
RunWith string `json:"runWith"`
Command string `json:"command"`
Arguments []string `json:"arguments"`
Expand All @@ -59,6 +60,7 @@ type ExportTarget struct {
// Path string `json:"path"`
}

// TODO This function is kinda weird. Probably should not include "Running filter"
func (filter Filter) GetName() string {
if filter.Name != "" {
return filter.Name
Expand Down

0 comments on commit ec25e4b

Please sign in to comment.