mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-09-06 05:31:50 +00:00
Add excludepkgs option to repo command
This features may help users guarantee correctness of bundles built by mixer in lieu of some shortcomings with dnf where dnf produces an unexpected dependency solution. This mainly happens when a user is intending to fully substitute a package from upstream's repo with one from their own. If anything is wrong with the substitution, a feature like this would expose the issue early on. Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
This commit is contained in:
@@ -1839,6 +1839,33 @@ func (b *Builder) SetURLRepo(name, url string) error {
|
||||
return DNFConf.SaveTo(b.Config.Builder.DNFConf)
|
||||
}
|
||||
|
||||
// SetExcludesRepo sets the ecludes for the repo <name> to [pkgs...]
|
||||
func (b *Builder) SetExcludesRepo(reponame, pkgs string) error {
|
||||
if err := b.NewDNFConfIfNeeded(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
DNFConf, err := ini.Load(b.Config.Builder.DNFConf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := DNFConf.GetSection(reponame)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
k, err := s.GetKey("excludepkgs")
|
||||
if err != nil {
|
||||
if k, err = DNFConf.Section(reponame).NewKey("excludepkgs", pkgs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
k.SetValue(pkgs)
|
||||
return DNFConf.SaveTo(b.Config.Builder.DNFConf)
|
||||
}
|
||||
|
||||
// RemoveRepo removes a configured repo <name> if it exists in the DNF configuration.
|
||||
// This will fail if a DNF conf has not yet been generated.
|
||||
func (b *Builder) RemoveRepo(name string) error {
|
||||
|
||||
@@ -16,6 +16,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/clearlinux/mixer-tools/builder"
|
||||
|
||||
@@ -66,12 +67,21 @@ var setURLRepoCmd = &cobra.Command{
|
||||
Run: runSetURLRepo,
|
||||
}
|
||||
|
||||
var setExcludesRepoCmd = &cobra.Command{
|
||||
Use: "exclude <repo> <pkg> [<pkg>...]",
|
||||
Short: "Exclude packages from a specified repo",
|
||||
Long: `Exclude packages from a specified repo. These packages will be ignored during build bundles. Globbing is supported.`,
|
||||
Args: cobra.MinimumNArgs(2),
|
||||
Run: runExcludesRepo,
|
||||
}
|
||||
|
||||
var repoCmds = []*cobra.Command{
|
||||
addRepoCmd,
|
||||
removeRepoCmd,
|
||||
listReposCmd,
|
||||
initRepoCmd,
|
||||
setURLRepoCmd,
|
||||
setExcludesRepoCmd,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -83,6 +93,19 @@ func init() {
|
||||
RootCmd.AddCommand(repoCmd)
|
||||
}
|
||||
|
||||
func runExcludesRepo(cmd *cobra.Command, args []string) {
|
||||
b, err := builder.NewFromConfig(configFile)
|
||||
if err != nil {
|
||||
fail(err)
|
||||
}
|
||||
|
||||
err = b.SetExcludesRepo(args[0], strings.Join(args[1:], " "))
|
||||
if err != nil {
|
||||
fail(err)
|
||||
}
|
||||
fmt.Printf("Excluded packages from repo %s:\n%s\n", args[0], strings.Join(args[1:], "\n"))
|
||||
}
|
||||
|
||||
func runAddRepo(cmd *cobra.Command, args []string) {
|
||||
b, err := builder.NewFromConfig(configFile)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user