From 16453bd09ffe4f63c35b5409c07c555b0f4bda1e Mon Sep 17 00:00:00 2001 From: Daniele Rondina Date: Sun, 29 Dec 2019 16:33:10 +0100 Subject: [PATCH] Concurrency option is now global * concurrency could be configured now from cmdline, configuration file or LUET_GENERAL__CONCURRENCY env variable * verbose option is now related to debug option --- cmd/build.go | 8 +++----- cmd/convert.go | 15 +++++++++------ cmd/install.go | 6 ++---- cmd/root.go | 10 ++++++++-- cmd/search.go | 3 --- cmd/uninstall.go | 6 ++---- cmd/upgrade.go | 6 ++---- 7 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index 55c8d48b..d63cde63 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -18,15 +18,15 @@ import ( "fmt" "io/ioutil" "os" - "runtime" - _gentoo "github.com/Sabayon/pkgs-checker/pkg/gentoo" "github.com/mudler/luet/pkg/compiler" "github.com/mudler/luet/pkg/compiler/backend" + . "github.com/mudler/luet/pkg/config" . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" tree "github.com/mudler/luet/pkg/tree" + _gentoo "github.com/Sabayon/pkgs-checker/pkg/gentoo" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -39,7 +39,6 @@ var buildCmd = &cobra.Command{ viper.BindPFlag("tree", cmd.Flags().Lookup("tree")) viper.BindPFlag("destination", cmd.Flags().Lookup("destination")) viper.BindPFlag("backend", cmd.Flags().Lookup("backend")) - viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency")) viper.BindPFlag("privileged", cmd.Flags().Lookup("privileged")) viper.BindPFlag("database", cmd.Flags().Lookup("database")) viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps")) @@ -50,7 +49,7 @@ var buildCmd = &cobra.Command{ src := viper.GetString("tree") dst := viper.GetString("destination") - concurrency := viper.GetInt("concurrency") + concurrency := LuetCfg.GetGeneral().Concurrency backendType := viper.GetString("backend") privileged := viper.GetBool("privileged") revdeps := viper.GetBool("revdeps") @@ -162,7 +161,6 @@ func init() { } buildCmd.Flags().String("tree", path, "Source luet tree") buildCmd.Flags().String("backend", "docker", "backend used (docker,img)") - buildCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency") buildCmd.Flags().Bool("privileged", false, "Privileged (Keep permissions)") buildCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)") buildCmd.Flags().Bool("revdeps", false, "Build with revdeps") diff --git a/cmd/convert.go b/cmd/convert.go index 4cb0f29d..9e53ca63 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -16,8 +16,8 @@ package cmd import ( "io/ioutil" - "runtime" + . "github.com/mudler/luet/pkg/config" . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" tree "github.com/mudler/luet/pkg/tree" @@ -33,13 +33,11 @@ var convertCmd = &cobra.Command{ Long: `Parses external PM and produces a luet parsable tree`, PreRun: func(cmd *cobra.Command, args []string) { viper.BindPFlag("type", cmd.Flags().Lookup("type")) - viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency")) viper.BindPFlag("database", cmd.Flags().Lookup("database")) }, Run: func(cmd *cobra.Command, args []string) { t := viper.GetString("type") - c := viper.GetInt("concurrency") databaseType := viper.GetString("database") var db pkg.PackageDatabase @@ -54,9 +52,15 @@ var convertCmd = &cobra.Command{ var builder tree.Parser switch t { case "gentoo": - builder = gentoo.NewGentooBuilder(&gentoo.SimpleEbuildParser{}, c, gentoo.InMemory) + builder = gentoo.NewGentooBuilder( + &gentoo.SimpleEbuildParser{}, + LuetCfg.GetGeneral().Concurrency, + gentoo.InMemory) default: // dup - builder = gentoo.NewGentooBuilder(&gentoo.SimpleEbuildParser{}, c, gentoo.InMemory) + builder = gentoo.NewGentooBuilder( + &gentoo.SimpleEbuildParser{}, + LuetCfg.GetGeneral().Concurrency, + gentoo.InMemory) } switch databaseType { @@ -91,7 +95,6 @@ var convertCmd = &cobra.Command{ func init() { convertCmd.Flags().String("type", "gentoo", "source type") - convertCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency") convertCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)") RootCmd.AddCommand(convertCmd) diff --git a/cmd/install.go b/cmd/install.go index 18426a01..34c33fd0 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -18,10 +18,10 @@ import ( "os" "path/filepath" "regexp" - "runtime" installer "github.com/mudler/luet/pkg/installer" + . "github.com/mudler/luet/pkg/config" . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" @@ -35,7 +35,6 @@ var installCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { viper.BindPFlag("system-dbpath", cmd.Flags().Lookup("system-dbpath")) viper.BindPFlag("system-target", cmd.Flags().Lookup("system-target")) - viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency")) }, Long: `Install packages in parallel`, Run: func(cmd *cobra.Command, args []string) { @@ -71,7 +70,7 @@ var installCmd = &cobra.Command{ synced = append(synced, s) } - inst := installer.NewLuetInstaller(viper.GetInt("concurrency")) + inst := installer.NewLuetInstaller(LuetCfg.GetGeneral().Concurrency) inst.Repositories(synced) @@ -92,7 +91,6 @@ func init() { } installCmd.Flags().String("system-dbpath", path, "System db path") installCmd.Flags().String("system-target", path, "System rootpath") - installCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency") RootCmd.AddCommand(installCmd) } diff --git a/cmd/root.go b/cmd/root.go index 2a692852..1b7ccdc5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,6 +18,7 @@ package cmd import ( "os" "path/filepath" + "runtime" "strings" "github.com/marcsauter/single" @@ -101,8 +102,13 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) - RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.luet.yaml)") - RootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output") + pflags := RootCmd.PersistentFlags() + pflags.StringVar(&cfgFile, "config", "", "config file (default is $HOME/.luet.yaml)") + pflags.BoolVarP(&Verbose, "verbose", "v", false, "verbose output") + pflags.Int("concurrency", runtime.NumCPU(), "Concurrency") + + config.LuetCfg.Viper.BindPFlag("general.debug", pflags.Lookup("verbose")) + config.LuetCfg.Viper.BindPFlag("general.concurrency", pflags.Lookup("concurrency")) } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/search.go b/cmd/search.go index 8f130927..9fba0f25 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -18,7 +18,6 @@ import ( "os" "path/filepath" "regexp" - "runtime" installer "github.com/mudler/luet/pkg/installer" @@ -36,7 +35,6 @@ var searchCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { viper.BindPFlag("system-dbpath", cmd.Flags().Lookup("system-dbpath")) viper.BindPFlag("system-target", cmd.Flags().Lookup("system-target")) - viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency")) viper.BindPFlag("installed", cmd.Flags().Lookup("installed")) }, Run: func(cmd *cobra.Command, args []string) { @@ -91,7 +89,6 @@ func init() { } searchCmd.Flags().String("system-dbpath", path, "System db path") searchCmd.Flags().String("system-target", path, "System rootpath") - searchCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency") searchCmd.Flags().Bool("installed", false, "Search between system packages") RootCmd.AddCommand(searchCmd) } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index fc6d080a..3599210d 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -18,11 +18,11 @@ import ( "fmt" "os" "path/filepath" - "runtime" installer "github.com/mudler/luet/pkg/installer" _gentoo "github.com/Sabayon/pkgs-checker/pkg/gentoo" + . "github.com/mudler/luet/pkg/config" . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" @@ -37,7 +37,6 @@ var uninstallCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { viper.BindPFlag("system-dbpath", cmd.Flags().Lookup("system-dbpath")) viper.BindPFlag("system-target", cmd.Flags().Lookup("system-target")) - viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency")) }, Run: func(cmd *cobra.Command, args []string) { for _, a := range args { @@ -57,7 +56,7 @@ var uninstallCmd = &cobra.Command{ Uri: make([]string, 0), } - inst := installer.NewLuetInstaller(viper.GetInt("concurrency")) + inst := installer.NewLuetInstaller(LuetCfg.GetGeneral().Concurrency) os.MkdirAll(viper.GetString("system-dbpath"), os.ModePerm) systemDB := pkg.NewBoltDatabase(filepath.Join(viper.GetString("system-dbpath"), "luet.db")) system := &installer.System{Database: systemDB, Target: viper.GetString("system-target")} @@ -77,6 +76,5 @@ func init() { } uninstallCmd.Flags().String("system-dbpath", path, "System db path") uninstallCmd.Flags().String("system-target", path, "System rootpath") - uninstallCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency") RootCmd.AddCommand(uninstallCmd) } diff --git a/cmd/upgrade.go b/cmd/upgrade.go index cb15fce4..7d6631bb 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -17,10 +17,10 @@ package cmd import ( "os" "path/filepath" - "runtime" installer "github.com/mudler/luet/pkg/installer" + . "github.com/mudler/luet/pkg/config" . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" @@ -34,7 +34,6 @@ var upgradeCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { viper.BindPFlag("system-dbpath", cmd.Flags().Lookup("system-dbpath")) viper.BindPFlag("system-target", cmd.Flags().Lookup("system-target")) - viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency")) }, Long: `Upgrades packages in parallel`, Run: func(cmd *cobra.Command, args []string) { @@ -54,7 +53,7 @@ var upgradeCmd = &cobra.Command{ synced = append(synced, s) } - inst := installer.NewLuetInstaller(viper.GetInt("concurrency")) + inst := installer.NewLuetInstaller(LuetCfg.GetGeneral().Concurrency) inst.Repositories(synced) @@ -75,7 +74,6 @@ func init() { } upgradeCmd.Flags().String("system-dbpath", path, "System db path") upgradeCmd.Flags().String("system-target", path, "System rootpath") - upgradeCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency") RootCmd.AddCommand(upgradeCmd) }