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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2MzZGQyM2ZmZWQ3ZTgxYjQ3MjAzYjA1MzcwODdhZjg5MDZlN2QxOQ==
4
+ YWEzMTc0Y2MzNTg0ZGM4NGFmZWRkMzhhZDAwMDgxNmZmZjFhOGY4Mg==
5
5
  data.tar.gz: !binary |-
6
- NzViYzgxOTlmYTEwMzZmMWFhM2NiNjczZWM3MTY2ZjA0Nzk1NGZlMQ==
6
+ YmNjYzgwY2FkMzEyNWZkZDIyYjVmMzMzNzVhNGIzYmE0NTBiODI3NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDEzYjQ4ODI4MjFlOTNkNzNiMmFjOWU0MGNjNzVmYTc2YTVmOTcwYmRkMjcz
10
- YTZlNmJiZTI2ODM0ZTY2ZjlmNWNiZjE0N2U4ODhiYzdjYTRlODgzMmE5MzU1
11
- OGMxMjcwMzJlYTU1NTgyYTVjYTQ4MzRhNDk3ODM3MjcyYjM4MWE=
9
+ ZDMwMDgwNjljNTc1ZjhhMjkxMzk0MTM3MDJlNjdlMjY2OTdjOGZjMzhmODYy
10
+ MmZhZTUxZTEzMTk4OGQ0MjRkNDNlNTgwNGFlY2JiZWQzYjBkYmU5ZTEzYWZh
11
+ NDM2Y2VhOTU2YWE2ZDAxNDY3NjkzMDliM2YwOTVhMmQxMGFhY2E=
12
12
  data.tar.gz: !binary |-
13
- NjZkNWJhZTBlNmFmZTVhYTkwNTJjY2UwZjQxNjFmODExYTlhZDViMWFhYTE5
14
- MGE0ZWExODg0MDU0ZjAxN2NiNWJhZWYwNGI2NjJjMWRhYzNhYjRjNzZlYjc0
15
- NjU5NGU3ODdlMmM0Mzc5MTU0MjkwZjIxNjQyYThiMmYyMGM0MTg=
13
+ OGE0MTY1MWNlNmZiNGI5MWVjNDg2N2NkNTcyOGZlMTg0MGM2MGZlMGIyNjAy
14
+ MGE5N2Q3MjkxMzM0YTg3MjgzMDdhZTA2ZWEzMDg5MTU3NGQ1YWE2ZmU5ZmY1
15
+ ZDcxYThhMWMyMmY2NGMzYTEzMmUzODI2NzEyZTExZDk1ODlkODA=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rpmchange (0.0.4)
4
+ rpmchange (0.0.5)
5
5
  diffy (>= 3.1.0, < 4.0)
6
6
  thor (>= 0.19.1, < 1.0)
7
7
 
@@ -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
@@ -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| _prepend_line(lines: changelog_lines, new_line: 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, new_line: "#{to_tag_name(tag)}: #{value.strip}", match: /#{to_tag_name(tag)}:/)
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
- _append_line(lines: preamble_lines, new_line: "#{to_tag_name(tag)}: #{value}")
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
- _append_line(lines: preamble_lines, new_line: make_line, after: _patch_tag_line_regex)
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
- _append_line(lines: prep_lines, new_line: "%patch#{num} -p1", after: _patch_macro_line_regex)
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("#{section}_lines") {|params=nil| (sections[section] || {})[params] || []}
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 _append_line(lines:, new_line:, after: nil)
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
- _insert_line(lines: lines, new_line: new_line, find_index: find_index)
203
+ _insert_value(lines: lines, value: value, find_index: find_index)
186
204
  end
187
205
 
188
- def _prepend_line(lines:, new_line:, before: nil)
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
- _insert_line(lines: lines, new_line: new_line, find_index: find_index)
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 _insert_line(lines:, new_line:, find_index:)
222
+ def _insert_value(lines:, value:, find_index:)
200
223
  if ind = find_index.call(lines)
201
- line = (new_line.respond_to?(:call) ? new_line.call(ind) : new_line).to_s.chomp
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:, new_line:, match:)
228
+ def _replace_line(lines:, value:, match:)
207
229
  if ind = lines.index {|line| line.to_s =~ match}
208
- line = (new_line.respond_to?(:call) ? new_line.call(ind) : new_line).to_s.chomp
209
- lines[ind] = line
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
@@ -1,3 +1,3 @@
1
1
  module Rpmchange
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end # Rpmchange
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
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-04 00:00:00.000000000 Z
11
+ date: 2016-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor