Skip to content

Commit

Permalink
wip: move code from planInstall to new function configlib.SetPlanCust…
Browse files Browse the repository at this point in the history
…omizations
  • Loading branch information
david-lyder committed Aug 16, 2019
1 parent b836707 commit 3574212
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 42 deletions.
46 changes: 4 additions & 42 deletions cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"fmt"

"github.com/metrumresearchgroup/pkgr/rollback"

"github.com/metrumresearchgroup/pkgr/desc"
Expand Down Expand Up @@ -111,46 +112,7 @@ func planInstall(rv cran.RVersion, exitOnMissing bool) (*cran.PkgNexus, gpsr.Ins
}

dependencyConfigurations := gpsr.NewDefaultInstallDeps()

if cfg.Suggests {
for _, pkg := range cfg.Packages {
// set all top level packages to install suggests
dp := dependencyConfigurations.Default
dp.Suggests = true
dependencyConfigurations.Deps[pkg] = dp
}
}
if viper.Sub("Customizations") != nil && viper.Sub("Customizations").AllSettings()["packages"] != nil {

pkgSettings := viper.Sub("Customizations").AllSettings()["packages"].([]interface{})
//repoSettings := viper.Sub("Customizations").AllSettings()["packages"].([]interface{})

for pkg, v := range cfg.Customizations.Packages {
if configlib.IsCustomizationSet("Suggests", pkgSettings, pkg) {
pkgDepTypes := dependencyConfigurations.Default
pkgDepTypes.Suggests = v.Suggests
dependencyConfigurations.Deps[pkg] = pkgDepTypes
}
if configlib.IsCustomizationSet("Repo", pkgSettings, pkg) {
err := pkgNexus.SetPackageRepo(pkg, v.Repo)
if err != nil {
log.WithFields(log.Fields{
"pkg": pkg,
"repo": v.Repo,
}).Fatal("error finding custom repo to set")
}
}
if configlib.IsCustomizationSet("Type", pkgSettings, pkg) {
err := pkgNexus.SetPackageType(pkg, v.Type)
if err != nil {
log.WithFields(log.Fields{
"pkg": pkg,
"repo": v.Repo,
}).Fatal("error finding custom repo to set")
}
}
}
}
configlib.SetPlanCustomizations(cfg, dependencyConfigurations, pkgNexus)

availableUserPackages := pkgNexus.GetPackages(cfg.Packages)
if len(availableUserPackages.Missing) > 0 {
Expand Down Expand Up @@ -223,8 +185,8 @@ func planInstall(rv cran.RVersion, exitOnMissing bool) (*cran.PkgNexus, gpsr.Ins
log.WithFields(fields).Info("package installation sources")

log.WithFields(log.Fields{
"to_install": toInstall,
"to_update": pkgsToUpdateCount,
"to_install": toInstall,
"to_update": pkgsToUpdateCount,
}).Info("package installation plan")

if toInstall > 0 && toInstall != totalPackagesRequired {
Expand Down
49 changes: 49 additions & 0 deletions configlib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"os"
"path/filepath"

"github.com/metrumresearchgroup/pkgr-work/feature_lockfile-cfg/pkgr/configlib"
"github.com/metrumresearchgroup/pkgr/cran"
"github.com/metrumresearchgroup/pkgr/gpsr"
"github.com/metrumresearchgroup/pkgr/rcmd"
homedir "github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -215,3 +217,50 @@ func SetCustomizations(rSettings rcmd.RSettings, cfg PkgrConfig) rcmd.RSettings
}
return rSettings
}

// SetPlanCustomizations ...
func SetPlanCustomizations(cfg PkgrConfig, dependencyConfigurations gpsr.InstallDeps, pkgNexus *cran.PkgNexus) {
if cfg.Suggests {
log.Info("SetPlanCustomizations suggests")
for _, pkg := range cfg.Packages {
// set all top level packages to install suggests
dp := dependencyConfigurations.Default
dp.Suggests = true
dependencyConfigurations.Deps[pkg] = dp
}
}
if viper.Sub("Customizations") != nil && viper.Sub("Customizations").AllSettings()["packages"] != nil {
log.Info("SetPlanCustomizations viper")
pkgSettings := viper.Sub("Customizations").AllSettings()["packages"].([]interface{})
//repoSettings := viper.Sub("Customizations").AllSettings()["packages"].([]interface{})

for pkg, v := range cfg.Customizations.Packages {
if configlib.IsCustomizationSet("Suggests", pkgSettings, pkg) {
pkgDepTypes := dependencyConfigurations.Default
pkgDepTypes.Suggests = v.Suggests
dependencyConfigurations.Deps[pkg] = pkgDepTypes
log.Info("SetPlanCustomizations viper Suggests ")
}
if configlib.IsCustomizationSet("Repo", pkgSettings, pkg) {
err := pkgNexus.SetPackageRepo(pkg, v.Repo)
if err != nil {
log.WithFields(log.Fields{
"pkg": pkg,
"repo": v.Repo,
}).Fatal("error finding custom repo to set")
}
log.Info("SetPlanCustomizations viper Repo ")
}
if configlib.IsCustomizationSet("Type", pkgSettings, pkg) {
err := pkgNexus.SetPackageType(pkg, v.Type)
if err != nil {
log.WithFields(log.Fields{
"pkg": pkg,
"repo": v.Repo,
}).Fatal("error finding custom repo to set")
}
log.Info("SetPlanCustomizations viper Type ")
}
}
}
}
7 changes: 7 additions & 0 deletions pkgr_ws.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}

0 comments on commit 3574212

Please sign in to comment.