mirror of
https://github.com/mudler/luet.git
synced 2025-08-31 23:02:16 +00:00
Use DefaultPackageSanitized struct for write specs
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
//"sort"
|
||||
|
||||
. "github.com/mudler/luet/pkg/logger"
|
||||
spectooling "github.com/mudler/luet/pkg/spectooling"
|
||||
tree "github.com/mudler/luet/pkg/tree"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -54,7 +55,7 @@ func NewTreeBumpCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
if toStdout {
|
||||
data, err := pack.Yaml()
|
||||
data, err := spectooling.NewDefaultPackageSanitized(&pack).Yaml()
|
||||
if err != nil {
|
||||
Fatal("Error on yaml conversion: " + err.Error())
|
||||
}
|
||||
|
@@ -26,11 +26,12 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
version "github.com/mudler/luet/pkg/versioner"
|
||||
|
||||
gentoo "github.com/Sabayon/pkgs-checker/pkg/gentoo"
|
||||
"github.com/crillab/gophersat/bf"
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/jinzhu/copier"
|
||||
version "github.com/mudler/luet/pkg/versioner"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
106
pkg/spectooling/definition.go
Normal file
106
pkg/spectooling/definition.go
Normal file
@@ -0,0 +1,106 @@
|
||||
// Copyright © 2019-2020 Ettore Di Giacinto <mudler@gentoo.org>,
|
||||
// Daniele Rondina <geaaru@sabayonlinux.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package spectooling
|
||||
|
||||
import (
|
||||
pkg "github.com/mudler/luet/pkg/package"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type DefaultPackageSanitized struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Version string `json:"version" yaml:"version"`
|
||||
Category string `json:"category" yaml:"category"`
|
||||
UseFlags []string `json:"use_flags,omitempty" yaml:"use_flags,omitempty"`
|
||||
PackageRequires []*DefaultPackageSanitized `json:"requires,omitempty" yaml:"requires,omitempty"`
|
||||
PackageConflicts []*DefaultPackageSanitized `json:"conflicts,omitempty" yaml:"conflicts,omitempty"`
|
||||
IsSet bool `json:"set,omitempty" yaml:"set,omitempty"`
|
||||
Provides []*DefaultPackageSanitized `json:"provides,omitempty" yaml:"provides,omitempty"`
|
||||
|
||||
// Path is set only internally when tree is loaded from disk
|
||||
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
||||
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||
Uri []string `json:"uri,omitempty" yaml:"uri,omitempty"`
|
||||
License string `json:"license,omitempty" yaml:"license,omitempty"`
|
||||
|
||||
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
||||
}
|
||||
|
||||
func NewDefaultPackageSanitized(p pkg.Package) *DefaultPackageSanitized {
|
||||
ans := &DefaultPackageSanitized{
|
||||
Name: p.GetName(),
|
||||
Version: p.GetVersion(),
|
||||
Category: p.GetCategory(),
|
||||
UseFlags: p.GetUses(),
|
||||
IsSet: p.Flagged(),
|
||||
Path: p.GetPath(),
|
||||
Description: p.GetDescription(),
|
||||
Uri: p.GetURI(),
|
||||
License: p.GetLicense(),
|
||||
Labels: p.GetLabels(),
|
||||
}
|
||||
|
||||
if p.GetRequires() != nil && len(p.GetRequires()) > 0 {
|
||||
ans.PackageRequires = []*DefaultPackageSanitized{}
|
||||
for _, r := range p.GetRequires() {
|
||||
// I avoid recursive call of NewDefaultPackageSanitized
|
||||
ans.PackageRequires = append(ans.PackageRequires,
|
||||
&DefaultPackageSanitized{
|
||||
Name: r.Name,
|
||||
Version: r.Version,
|
||||
Category: r.Category,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if p.GetConflicts() != nil && len(p.GetConflicts()) > 0 {
|
||||
ans.PackageConflicts = []*DefaultPackageSanitized{}
|
||||
for _, c := range p.GetConflicts() {
|
||||
// I avoid recursive call of NewDefaultPackageSanitized
|
||||
ans.PackageConflicts = append(ans.PackageConflicts,
|
||||
&DefaultPackageSanitized{
|
||||
Name: c.Name,
|
||||
Version: c.Version,
|
||||
Category: c.Category,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if p.GetProvides() != nil && len(p.GetProvides()) > 0 {
|
||||
ans.Provides = []*DefaultPackageSanitized{}
|
||||
for _, prov := range p.GetProvides() {
|
||||
// I avoid recursive call of NewDefaultPackageSanitized
|
||||
ans.Provides = append(ans.Provides,
|
||||
&DefaultPackageSanitized{
|
||||
Name: prov.Name,
|
||||
Version: prov.Version,
|
||||
Category: prov.Category,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return ans
|
||||
}
|
||||
|
||||
func (p *DefaultPackageSanitized) Yaml() ([]byte, error) {
|
||||
return yaml.Marshal(p)
|
||||
}
|
@@ -26,6 +26,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
pkg "github.com/mudler/luet/pkg/package"
|
||||
spectooling "github.com/mudler/luet/pkg/spectooling"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -42,7 +43,7 @@ type Recipe struct {
|
||||
}
|
||||
|
||||
func WriteDefinitionFile(p pkg.Package, definitionFilePath string) error {
|
||||
data, err := p.Yaml()
|
||||
data, err := spectooling.NewDefaultPackageSanitized(p).Yaml()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user