rpmchange 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/rpmchange/cli.rb +40 -1
- data/lib/rpmchange/spec.rb +42 -16
- data/lib/rpmchange/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWEzMTc0Y2MzNTg0ZGM4NGFmZWRkMzhhZDAwMDgxNmZmZjFhOGY4Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmNjYzgwY2FkMzEyNWZkZDIyYjVmMzMzNzVhNGIzYmE0NTBiODI3NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDMwMDgwNjljNTc1ZjhhMjkxMzk0MTM3MDJlNjdlMjY2OTdjOGZjMzhmODYy
|
10
|
+
MmZhZTUxZTEzMTk4OGQ0MjRkNDNlNTgwNGFlY2JiZWQzYjBkYmU5ZTEzYWZh
|
11
|
+
NDM2Y2VhOTU2YWE2ZDAxNDY3NjkzMDliM2YwOTVhMmQxMGFhY2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGE0MTY1MWNlNmZiNGI5MWVjNDg2N2NkNTcyOGZlMTg0MGM2MGZlMGIyNjAy
|
14
|
+
MGE5N2Q3MjkxMzM0YTg3MjgzMDdhZTA2ZWEzMDg5MTU3NGQ1YWE2ZmU5ZmY1
|
15
|
+
ZDcxYThhMWMyMmY2NGMzYTEzMmUzODI2NzEyZTExZDk1ODlkODA=
|
data/Gemfile.lock
CHANGED
data/lib/rpmchange/cli.rb
CHANGED
@@ -57,7 +57,7 @@ module Rpmchange
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
desc "patch", "append patch"
|
60
|
+
desc "patch", "append patch tag and macro"
|
61
61
|
shared_options
|
62
62
|
method_option :name, {type: :string, desc: "patch name", required: true}
|
63
63
|
def patch
|
@@ -65,5 +65,44 @@ module Rpmchange
|
|
65
65
|
spec.append_patch(options['name'])
|
66
66
|
self.class.spec_write! spec, options
|
67
67
|
end
|
68
|
+
|
69
|
+
desc "append", "append given value in section"
|
70
|
+
shared_options
|
71
|
+
method_option :section, {type: :string, desc: "spec file section name", required: true}
|
72
|
+
method_option :value, {type: :string, desc: "value to append", required: true}
|
73
|
+
method_option :after, {type: :string, desc: "append value after line matching given regex"}
|
74
|
+
def append
|
75
|
+
spec = self.class.spec_construct options
|
76
|
+
after = options['after']
|
77
|
+
after = Regexp.new(after) if after
|
78
|
+
spec.append(section: options['section'], value: options['value'], after: after)
|
79
|
+
self.class.spec_write! spec, options
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "prepend", "prepend given value in section"
|
83
|
+
shared_options
|
84
|
+
method_option :section, {type: :string, desc: "spec file section name", required: true}
|
85
|
+
method_option :value, {type: :string, desc: "value to prepend", required: true}
|
86
|
+
method_option :before, {type: :string, desc: "prepend value before line matching given regex"}
|
87
|
+
def prepend
|
88
|
+
spec = self.class.spec_construct options
|
89
|
+
before = options['before']
|
90
|
+
before = Regexp.new(before) if before
|
91
|
+
spec.prepend(section: options['section'], value: options['value'], before: before)
|
92
|
+
self.class.spec_write! spec, options
|
93
|
+
end
|
94
|
+
|
95
|
+
desc "replace", "replace line matching given regex in section"
|
96
|
+
shared_options
|
97
|
+
method_option :section, {type: :string, desc: "spec file section name", required: true}
|
98
|
+
method_option :value, {type: :string, desc: "replace with value", required: true}
|
99
|
+
method_option :match, {type: :string, desc: "regex to match line"}
|
100
|
+
def replace
|
101
|
+
spec = self.class.spec_construct options
|
102
|
+
match = options['match']
|
103
|
+
match = Regexp.new(match) if match
|
104
|
+
spec.replace(section: options['section'], value: options['value'], match: match)
|
105
|
+
self.class.spec_write! spec, options
|
106
|
+
end
|
68
107
|
end # Cli
|
69
108
|
end # Rpmchange
|
data/lib/rpmchange/spec.rb
CHANGED
@@ -102,7 +102,7 @@ module Rpmchange
|
|
102
102
|
["* #{Time.now.strftime("%a %b %e %Y")} #{name} <#{email}> - #{full_version}",
|
103
103
|
message_lines.join("\n"),
|
104
104
|
"",
|
105
|
-
].reverse_each {|line|
|
105
|
+
].reverse_each {|line| _prepend_value(lines: changelog_lines, value: line)}
|
106
106
|
end
|
107
107
|
|
108
108
|
def to_tag_name(tag)
|
@@ -116,11 +116,11 @@ module Rpmchange
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def set_tag(tag, value)
|
119
|
-
_replace_line(lines: preamble_lines,
|
119
|
+
_replace_line(lines: preamble_lines, value: "#{to_tag_name(tag)}: #{value.strip}", match: /#{to_tag_name(tag)}:/)
|
120
120
|
end
|
121
121
|
|
122
122
|
def append_tag(tag, value)
|
123
|
-
|
123
|
+
_append_value(lines: preamble_lines, value: "#{to_tag_name(tag)}: #{value}")
|
124
124
|
end
|
125
125
|
|
126
126
|
def append_patch(value)
|
@@ -145,15 +145,31 @@ module Rpmchange
|
|
145
145
|
end
|
146
146
|
"Patch#{patch_num}: #{value}"
|
147
147
|
end
|
148
|
-
|
148
|
+
_append_value(lines: preamble_lines, value: make_line, after: _patch_tag_line_regex)
|
149
149
|
patch_num
|
150
150
|
end
|
151
151
|
|
152
152
|
def append_patch_macro(num)
|
153
|
-
|
153
|
+
_append_value(lines: prep_lines, value: "%patch#{num} -p1", after: _patch_macro_line_regex)
|
154
154
|
nil
|
155
155
|
end
|
156
156
|
|
157
|
+
def append(section:, value:, after: nil)
|
158
|
+
_append_value(lines: section_lines(section), value: value, after: after)
|
159
|
+
end
|
160
|
+
|
161
|
+
def prepend(section:, value:, before: nil)
|
162
|
+
_prepend_value(lines: section_lines(section), value: value, before: before)
|
163
|
+
end
|
164
|
+
|
165
|
+
def replace(section:, value:, match:)
|
166
|
+
_replace_line(lines: section_lines(section), value: value, match: match)
|
167
|
+
end
|
168
|
+
|
169
|
+
def delete(section:, match:)
|
170
|
+
_delete_all_lines(lines: section_lines(section), match: match)
|
171
|
+
end
|
172
|
+
|
157
173
|
def sections
|
158
174
|
@sections ||= {}
|
159
175
|
end
|
@@ -164,7 +180,9 @@ module Rpmchange
|
|
164
180
|
|
165
181
|
SECTIONS = %i{prep build install clean check files changelog}
|
166
182
|
SECTIONS.each do |section|
|
167
|
-
define_method(
|
183
|
+
define_method(:section_lines) {|section, params: nil| (sections[section.to_sym] || {})[params] || []}
|
184
|
+
define_method(:section?) {|section, params: nil| sections.key?(section.to_sym) and sections[section.to_sym].key?(params)}
|
185
|
+
define_method("#{section}_lines") {|**kwargs| section_lines(section, **kwargs)}
|
168
186
|
end
|
169
187
|
|
170
188
|
protected
|
@@ -173,7 +191,7 @@ module Rpmchange
|
|
173
191
|
@_patch_macro_line_regex ||= /^%patch[0-9]*/
|
174
192
|
end
|
175
193
|
|
176
|
-
def
|
194
|
+
def _append_value(lines:, value:, after: nil)
|
177
195
|
find_index = proc do |lines|
|
178
196
|
if after
|
179
197
|
ind = lines.rindex {|line| line.to_s =~ after}
|
@@ -182,10 +200,10 @@ module Rpmchange
|
|
182
200
|
-1
|
183
201
|
end
|
184
202
|
end
|
185
|
-
|
203
|
+
_insert_value(lines: lines, value: value, find_index: find_index)
|
186
204
|
end
|
187
205
|
|
188
|
-
def
|
206
|
+
def _prepend_value(lines:, value:, before: nil)
|
189
207
|
find_index = proc do |lines|
|
190
208
|
if before
|
191
209
|
lines.index {|line| line.to_s =~ before} || 0
|
@@ -193,23 +211,31 @@ module Rpmchange
|
|
193
211
|
0
|
194
212
|
end
|
195
213
|
end
|
196
|
-
|
214
|
+
_insert_value(lines: lines, value: value, find_index: find_index)
|
215
|
+
end
|
216
|
+
|
217
|
+
def _value_to_lines(value, *args)
|
218
|
+
res = (value.respond_to?(:call) ? value.call(*args) : value).to_s
|
219
|
+
res.empty? ? [res] : res.split("\n")
|
197
220
|
end
|
198
221
|
|
199
|
-
def
|
222
|
+
def _insert_value(lines:, value:, find_index:)
|
200
223
|
if ind = find_index.call(lines)
|
201
|
-
|
202
|
-
lines.insert(ind, line)
|
224
|
+
lines.insert(ind, *_value_to_lines(value, ind))
|
203
225
|
end
|
204
226
|
end
|
205
227
|
|
206
|
-
def _replace_line(lines:,
|
228
|
+
def _replace_line(lines:, value:, match:)
|
207
229
|
if ind = lines.index {|line| line.to_s =~ match}
|
208
|
-
|
209
|
-
lines
|
230
|
+
lines.delete_at(ind)
|
231
|
+
lines.insert(ind, *_value_to_lines(value, ind))
|
210
232
|
end
|
211
233
|
end
|
212
234
|
|
235
|
+
def _delete_all_lines(lines:, match:)
|
236
|
+
lines.delete_if {|line| line.to_s =~ match}
|
237
|
+
end
|
238
|
+
|
213
239
|
def _patch_tag_line_parse(line)
|
214
240
|
tag, value = line.split(':', 2)
|
215
241
|
[tag.split('Patch').last.to_i, value.strip] if tag
|
data/lib/rpmchange/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpmchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|