findr 0.0.7 → 0.0.8.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 264462a154498bd31f1314af9efa5dad2361ec1b
4
- data.tar.gz: 160cc1ac2b4cbad3fa14d973566f516f57be7dac
2
+ SHA256:
3
+ metadata.gz: b6de1fc5f3d2a5d0cb4cc25098d1fdad726ba1c7ce531e75a451792a9f403545
4
+ data.tar.gz: d5f0341e4712ed3d25ccff81cb0a6ef6902bdee32bb08927b0f15cfcb0267fc0
5
5
  SHA512:
6
- metadata.gz: 7066b9fe2a434f04eaa5e5f591b33b30d9ca1c758ab54ca1297df406ba3eeeb1239cb16f2cb5040a5f20d9cd52d2404e627d80bc31a6041a337334c3daf78b05
7
- data.tar.gz: 3cee5b2a3acb9242ab1895e02f4a9b73ecb17ea64ec1c73bb0b3d3ec60b00a164af9765c440df4c261a91bff102297f94c7921a5216cebe1972176d4a30a45ab
6
+ metadata.gz: 2e7b0a90bbc0739009df34e8813687931e01a9febfebe80df569b9c835cb29b8aaae292a507dd80608f4b64667e30c82ad0089e7c6006e4c75a18c0f61a2cc41
7
+ data.tar.gz: 6d3493e7cbc56f1b7c5820dba8106927e52765c1736bc8c80e3fcbe3698fc0d5b4f067d221ccb11e6c9d1f16cd005f17b2c02963e98f57a292a37b9645c9ee81
@@ -5,6 +5,7 @@ require 'optparse'
5
5
  require 'yaml'
6
6
  require 'pp'
7
7
 
8
+
8
9
  module Findr
9
10
 
10
11
  class CLI
@@ -16,6 +17,7 @@ module Findr
16
17
  end
17
18
 
18
19
  def red(text); colorize(text, 31); end
20
+ def light_red(text); colorize(text, 91); end
19
21
  def green(text); colorize(text, 32); end
20
22
  def yellow(text); colorize(text, 33); end
21
23
  def blue(text); colorize(text, 34); end
@@ -136,6 +138,7 @@ module Findr
136
138
  verbose "Building file tree..."
137
139
  files = Pathname.glob("#{options[:gglob]}")
138
140
  verbose [' ', files.count, ' files found.']
141
+ stats[:exceptions] = 0
139
142
  files.each do |current_file|
140
143
  next unless current_file.file?
141
144
  verbose ["Reading file ", current_file]
@@ -145,48 +148,62 @@ module Findr
145
148
  linenumber = 0
146
149
  tempfile = Tempfile.new( 'current_file.basename' ) and verbose([' Create tempfile ',tempfile.path]) if options[:replace] && options[:force]
147
150
  clear_context(); print_post_context = 0
148
- current_file.each_line do |l|
149
- begin
150
- l, coding = coder.decode(l)
151
- rescue Encoder::Error
152
- stdout.puts "Skipping file #{current_file} because of error on line #{linenumber}: #{$!.original.class} #{$!.original.message}"
153
- if tempfile
154
- tempfile_path = tempfile.path
155
- tempfile.unlink and verbose([' Delete tempfile ', tempfile_path])
156
- end
157
- break
158
- end
159
- linenumber += 1
160
- if l=~ options[:find]
161
- stats[:local_hits] += 1
162
- if firstmatch
163
- stdout.puts red("#{current_file.cleanpath}:")
164
- end
165
- if @context_lines > 0
166
- pop_context.map do |linenumber, l|
167
- print_line( linenumber, l, coding, false )
151
+ begin
152
+ current_file.each_line do |l|
153
+ begin
154
+ l, coding = coder.decode(l)
155
+ rescue Encoder::Error
156
+ stdout.puts red "Skipping file #{current_file} because of error on line #{linenumber}: #{$!.original.class} #{$!.original.message}"
157
+ if tempfile
158
+ tempfile_path = tempfile.path
159
+ tempfile.unlink and verbose([' Delete tempfile ', tempfile_path])
168
160
  end
169
- print_post_context = @context_lines
161
+ break
170
162
  end
171
- print_line( linenumber, l.gsub( /(#{options[:find]})/, bold('\1') ), coding, :bold )
172
- firstmatch = false
173
- if options[:replace]
174
- l_repl = l.gsub( options[:find], options[:replace] )
175
- tempfile.puts coder.encode(l_repl, coding) if tempfile
176
- replacement_done = true
177
- print_line( linenumber, l_repl, coding, :blue )
178
- end
179
- else
180
- if tempfile
181
- tempfile.puts coder.encode(l, coding)
182
- end
183
- if print_post_context > 0
184
- print_post_context -= 1
185
- print_line( linenumber, l, coding )
163
+ linenumber += 1
164
+ if l=~ options[:find]
165
+ stats[:local_hits] += 1
166
+ if firstmatch
167
+ stdout.puts red("#{current_file.cleanpath}:")
168
+ end
169
+ if @context_lines > 0
170
+ pop_context.map do |linenumber, l|
171
+ print_line( linenumber, l, coding, false )
172
+ end
173
+ print_post_context = @context_lines
174
+ end
175
+ print_line( linenumber, l.gsub( /(#{options[:find]})/, bold('\1') ), coding, :bold )
176
+ firstmatch = false
177
+ if options[:replace]
178
+ l_repl = l.gsub( options[:find], options[:replace] )
179
+ tempfile.puts coder.encode(l_repl, coding) if tempfile
180
+ replacement_done = true
181
+ print_line( linenumber, l_repl, coding, :blue )
182
+ end
186
183
  else
187
- push_context([linenumber, l])
184
+ if tempfile
185
+ tempfile.puts coder.encode(l, coding)
186
+ end
187
+ if print_post_context > 0
188
+ print_post_context -= 1
189
+ print_line( linenumber, l, coding )
190
+ else
191
+ push_context([linenumber, l])
192
+ end
188
193
  end
189
194
  end
195
+ rescue SystemCallError
196
+ puts light_red "EXCEPTION: #$!"
197
+ stats[:exceptions] += 1
198
+ next
199
+ rescue SignalException
200
+ puts light_red "\n#{$!.class} received."
201
+ return
202
+ ensure
203
+ if tempfile
204
+ tempfile.close
205
+ tempfile.unlink
206
+ end
190
207
  end
191
208
  if tempfile
192
209
  tempfile.close
@@ -207,6 +224,9 @@ module Findr
207
224
 
208
225
  # some statistics
209
226
  stdout.puts green( "#{stats[:total_hits]} occurences (lines) in #{stats[:hit_files]} of #{stats[:total_files]} files found." )
227
+ if stats[:exceptions] > 0
228
+ stdout.puts light_red( "#{stats[:exceptions]} exceptions occurenced." )
229
+ end
210
230
  end
211
231
 
212
232
  def print_line( linenumber, line, coding, color = nil )
@@ -1,3 +1,3 @@
1
1
  module Findr
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8.pre1'
3
3
  end
Binary file
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: findr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Strauss
@@ -89,6 +89,7 @@ files:
89
89
  - lib/findr/strategy_proxy.rb
90
90
  - lib/findr/version.rb
91
91
  - pkg/findr-0.0.7.gem
92
+ - pkg/findr-0.0.8.pre1.gem
92
93
  - spec/findr/encoder_spec.rb
93
94
  - spec/spec_helper.rb
94
95
  homepage: https://github.com/mstrauss/findr
@@ -106,12 +107,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
107
  version: 1.8.7
107
108
  required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  requirements:
109
- - - ">="
110
+ - - ">"
110
111
  - !ruby/object:Gem::Version
111
- version: '0'
112
+ version: 1.3.1
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.5.2.1
115
+ rubygems_version: 2.7.6
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: A ruby find and replace tool for mass editing text files.