modulemd.go 5.23 KB
Newer Older
Mustafa Gezen's avatar
Mustafa Gezen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 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.

Mustafa Gezen's avatar
Mustafa Gezen committed
21
22
23
24
25
26
27
28
package modulemd

import (
	"github.com/go-git/go-billy/v5"
	"gopkg.in/yaml.v2"
)

type ModuleMd struct {
29
30
	Document string `yaml:"document,omitempty"`
	Version  int    `yaml:"version,omitempty"`
Mustafa Gezen's avatar
Mustafa Gezen committed
31
	Data     struct {
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
		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"`
Mustafa Gezen's avatar
Mustafa Gezen committed
63
		Dependencies []struct {
64
65
			Buildrequires map[string]interface{} `yaml:"buildrequires,omitempty,omitempty"`
			Requires      map[string]interface{} `yaml:"requires,omitempty,omitempty"`
66
		} `yaml:"dependencies,omitempty"`
Mustafa Gezen's avatar
Mustafa Gezen committed
67
		References struct {
68
69
70
71
			Community     string `yaml:"community,omitempty"`
			Documentation string `yaml:"documentation,omitempty"`
			Tracker       string `yaml:"tracker,omitempty"`
		} `yaml:"references,omitempty"`
72
73
74
		Profiles map[string]*struct {
			Description string   `yaml:"description,omitempty"`
			Rpms        []string `yaml:"rpms,omitempty"`
75
		} `yaml:"profiles,omitempty"`
Mustafa Gezen's avatar
Mustafa Gezen committed
76
		API struct {
77
78
79
80
81
82
83
84
85
86
87
88
			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"`
Mustafa Gezen's avatar
Mustafa Gezen committed
89
90
		Components struct {
			Rpms map[string]*struct {
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
				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"`
Mustafa Gezen's avatar
Mustafa Gezen committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
}

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
}