Skip to content

Commit

Permalink
Finish implementation of remote filters
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLich committed Aug 8, 2021
1 parent a96a41e commit 8f5ef3b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
47 changes: 24 additions & 23 deletions src/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func RunProfile(profileName string) {

//now, we go through the filters!
for _, filter := range profile.Filters {
RunFilter(filter)
path, _ := filepath.Abs(".")
RunFilter(filter, path)
}

//copy contents of .regolith/tmp to build
Expand All @@ -69,40 +70,38 @@ func RunProfile(profileName string) {
}

// Runs the filter by selecting the correct filter type and running it
func RunFilter(filter Filter) {
func RunFilter(filter Filter, absoluteLocation string) {
Logger.Infof("Running filter '%s'", filter.Name)
start := time.Now()

// Run via online filter
if filter.Url != "" {
RunRemoteFilter(filter.Url, filter.Arguments)
}

// Run via standard filter
if filter.Filter != "" {
} else if filter.Filter != "" {
RunStandardFilter(filter, filter.Arguments)
} else {
switch filter.RunWith {
case "python":
RunPythonFilter(filter, absoluteLocation+filter.Location)
default:
Logger.Warnf("Filter type '%s' not supported", filter.RunWith)
}
Logger.Info("Executed in ", time.Since(start))
}

// Run based on run-target
switch filter.RunWith {
case "python":
RunPythonFilter(filter)
default:
Logger.Warnf("Filter type '%s' not supported", filter.RunWith)
}
Logger.Info("Executed in ", time.Since(start))
}

func RunStandardFilter(filter Filter, arguments []string) {
url := "https://github.com/Bedrock-OSS/regolith-filters/" + filter.Filter
RunRemoteFilter(url, arguments)
Logger.Infof("RunStandardFilter '%s'", filter.Filter)
RunRemoteFilter(FilterNameToUrl(filter.Filter), arguments)
}

func LoadFiltersFromPath(path string) Profile {
path = path + "/filter.json"
file, err := ioutil.ReadFile(path)

if err != nil {
log.Fatal(color.RedString("Couldn't find %s! Consider running 'regolith init'", ManifestName))
log.Fatal(color.RedString("Couldn't find %s! Consider running 'regolith install'", path), err)
}

var result Profile
err = json.Unmarshal(file, &result)
if err != nil {
Expand All @@ -112,17 +111,19 @@ func LoadFiltersFromPath(path string) Profile {
}

func RunRemoteFilter(url string, arguments []string) {
Logger.Infof("RunRemoteFilter '%s'", url)
if !IsRemoteFilterCached(url) {
Logger.Error("Filter is not downloaded! Please run 'regolith install'.")
}

for _, filter := range LoadFiltersFromPath(UrlToPath(url)).Filters {
RunFilter(filter)
path := UrlToPath(url)
absolutePath, _ := filepath.Abs(path)
for _, filter := range LoadFiltersFromPath(path).Filters {
RunFilter(filter, absolutePath)
}
}

func RunPythonFilter(filter Filter) {
absoluteLocation, _ := filepath.Abs(filter.Location)
func RunPythonFilter(filter Filter, absoluteLocation string) {
RunSubProcess(filter.RunWith, append([]string{"-u", absoluteLocation}, filter.Arguments...))
}

Expand Down
33 changes: 23 additions & 10 deletions src/remote_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (
)

func UrlToPath(url string) string {
return ".regolith/cache" + url
return ".regolith/cache/" + url
}

func FilterNameToUrl(name string) string {
return "github.com/Bedrock-OSS/regolith-filters//" + name
}

func IsRemoteFilterCached(url string) bool {
Expand All @@ -34,17 +38,18 @@ func GatherDependencies() []string {
var dependencies []string
for _, profile := range project.Profiles {
for _, filter := range profile.Filters {
dependencies = append(dependencies, GatherDependency(filter))
if filter.Url != "" {
dependencies = append(dependencies, filter.Url)
}

if filter.Filter != "" {
dependencies = append(dependencies, FilterNameToUrl(filter.Filter))
}
}
}
return dependencies
}

func GatherDependency(filter Filter) string {
Logger.Info("TODO")
return "TODO"
}

func InstallDependencies() {
log.Println(color.GreenString("Installing dependencies..."))
log.Println(color.YellowString("Warning: This may take a while..."))
Expand All @@ -65,8 +70,16 @@ func InstallDependencies() {
log.Println(color.GreenString("Dependencies installed."))
}

func InstallDependency(name string) error {
log.Println(color.GreenString("Installing dependency %s...", name))
// TODO!
func InstallDependency(url string) error {
log.Println(color.GreenString("Installing dependency %s...", url))

// Install the url into the cache folder

err := getter.Get(UrlToPath(url), url)

if err != nil {
log.Fatal(color.RedString("Could not install dependency %s: ", url), err)
}

return nil
}

0 comments on commit 8f5ef3b

Please sign in to comment.