srpmproc/modulemd/modulemd.go

157 lines
5.4 KiB
Go
Raw Normal View History

2021-04-06 19:39:02 +00:00
// Copyright (c) 2021 The Srpmproc Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
2020-12-22 16:28:04 +00:00
package modulemd
import (
"github.com/go-git/go-billy/v5"
"gopkg.in/yaml.v2"
)
type ModuleMd struct {
2021-01-01 15:20:39 +00:00
Document string `yaml:"document,omitempty"`
Version int `yaml:"version,omitempty"`
2020-12-22 16:28:04 +00:00
Data struct {
2021-01-01 15:20:39 +00:00
Name string `yaml:"name,omitempty"`
Stream string `yaml:"stream,omitempty"`
Version int64 `yaml:"version,omitempty"`
StaticContext bool `yaml:"static_context,omitempty"`
Context string `yaml:"context,omitempty"`
Arch string `yaml:"arch,omitempty"`
Summary string `yaml:"summary,omitempty"`
Description string `yaml:"description,omitempty"`
Servicelevels struct {
Rawhide struct {
Eol struct {
} `yaml:"eol,omitempty"`
} `yaml:"rawhide,omitempty"`
StableAPI struct {
Eol struct {
} `yaml:"eol,omitempty"`
} `yaml:"stable_api,omitempty"`
BugFixes struct {
Eol struct {
} `yaml:"eol,omitempty"`
} `yaml:"bug_fixes,omitempty"`
SecurityFixes struct {
Eol struct {
} `yaml:"eol,omitempty"`
} `yaml:"security_fixes,omitempty"`
} `yaml:"servicelevels,omitempty"`
License struct {
Module []string `yaml:"module,omitempty"`
Content []string `yaml:"content,omitempty"`
} `yaml:"license,omitempty"`
Xmd map[string]interface{} `yaml:"xmd,omitempty"`
2020-12-22 16:28:04 +00:00
Dependencies []struct {
2021-04-27 14:39:03 +00:00
Buildrequires map[string][]string `yaml:"buildrequires,omitempty,omitempty"`
Requires map[string][]string `yaml:"requires,omitempty,omitempty"`
2021-01-01 15:20:39 +00:00
} `yaml:"dependencies,omitempty"`
2020-12-22 16:28:04 +00:00
References struct {
2021-01-01 15:20:39 +00:00
Community string `yaml:"community,omitempty"`
Documentation string `yaml:"documentation,omitempty"`
Tracker string `yaml:"tracker,omitempty"`
} `yaml:"references,omitempty"`
2021-01-04 23:27:48 +00:00
Profiles map[string]*struct {
Description string `yaml:"description,omitempty"`
Rpms []string `yaml:"rpms,omitempty"`
2021-01-01 15:20:39 +00:00
} `yaml:"profiles,omitempty"`
2021-04-18 05:59:11 +00:00
Profile map[string]*struct {
Description string `yaml:"description,omitempty"`
Rpms []string `yaml:"rpms,omitempty"`
} `yaml:"profile,omitempty"`
2020-12-22 16:28:04 +00:00
API struct {
2021-01-01 15:20:39 +00:00
Rpms []string `yaml:"rpms,omitempty"`
} `yaml:"api,omitempty"`
Filter struct {
Rpms []string `yaml:"rpms,omitempty"`
} `yaml:"filter,omitempty"`
Buildopts struct {
Rpms struct {
Macros string `yaml:"macros,omitempty"`
Whitelist []string `yaml:"whitelist,omitempty"`
} `yaml:"rpms,omitempty"`
Arches []string `yaml:"arches,omitempty"`
} `yaml:"buildopts,omitempty"`
2020-12-22 16:28:04 +00:00
Components struct {
Rpms map[string]*struct {
2021-01-01 15:20:39 +00:00
Name string `yaml:"name,omitempty"`
Rationale string `yaml:"rationale,omitempty"`
Repository string `yaml:"repository,omitempty"`
Cache string `yaml:"cache,omitempty"`
Ref string `yaml:"ref,omitempty"`
Buildonly bool `yaml:"buildonly,omitempty"`
Buildroot bool `yaml:"buildroot,omitempty"`
SrpmBuildroot bool `yaml:"srpm-buildroot,omitempty"`
Buildorder int `yaml:"buildorder,omitempty"`
Arches []string `yaml:"arches,omitempty"`
Multilib []string `yaml:"multilib,omitempty"`
} `yaml:"rpms,omitempty"`
Modules map[string]*struct {
Rationale string `yaml:"rationale,omitempty"`
Repository string `yaml:"repository,omitempty"`
Ref string `yaml:"ref,omitempty"`
Buildorder int `yaml:"buildorder,omitempty"`
} `yaml:"modules,omitempty"`
} `yaml:"components,omitempty"`
Artifacts struct {
Rpms []string `yaml:"rpms,omitempty"`
RpmMap map[string]map[string]*struct {
Name string `yaml:"name,omitempty"`
Epoch int `yaml:"epoch,omitempty"`
Version float64 `yaml:"version,omitempty"`
Release string `yaml:"release,omitempty"`
Arch string `yaml:"arch,omitempty"`
Nevra string `yaml:"nevra,omitempty"`
} `yaml:"rpm-map,omitempty"`
} `yaml:"artifacts,omitempty"`
} `yaml:"data,omitempty"`
2020-12-22 16:28:04 +00:00
}
func Parse(input []byte) (*ModuleMd, error) {
var ret ModuleMd
err := yaml.Unmarshal(input, &ret)
if err != nil {
return nil, err
}
return &ret, nil
}
func (m *ModuleMd) Marshal(fs billy.Filesystem, path string) error {
bts, err := yaml.Marshal(m)
if err != nil {
return err
}
_ = fs.Remove(path)
f, err := fs.Create(path)
if err != nil {
return err
}
_, err = f.Write(bts)
if err != nil {
return err
}
_ = f.Close()
return nil
}