deal 0.0.2 → 0.0.3
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 +4 -4
- data/lib/deal/command.rb +102 -37
- data/lib/deal/gem_version.rb +1 -1
- data/lib/deal/utils/deal_config.rb +101 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2082d55419ba7736db28c1fb684bc756b407ee50c4f8536cbf80a45b03d1d72
|
4
|
+
data.tar.gz: fddcb40d4610726f8b4baf2bec47e1a6e30f410648701bf6553538cb260b22bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3154cccbb421c83f452dc91d89127a2b82ff50a9145967583f7f84e48de5a1dea1e951b2c758001370874d8d5994b1184058edd803e40b12f43c20bbb278b3f4
|
7
|
+
data.tar.gz: f7118afebf976b15e6ec417b6c2030ea4b2700d66626bff69704bda42c0f610c0f6701e40840d2cbc8e89f6a50e1a87f1b46387d1a925938cf7ad055b9d29bf0
|
data/lib/deal/command.rb
CHANGED
@@ -87,7 +87,6 @@ module Deal
|
|
87
87
|
@jump_file = {}
|
88
88
|
@results = []
|
89
89
|
inputs = argv.option('inputs',"").split('|')
|
90
|
-
logN "--inputs:#{inputs.join("\n")}"
|
91
90
|
@inputs = []
|
92
91
|
for input in inputs
|
93
92
|
ls = Dir.glob(input,File::FNM_DOTMATCH|File::FNM_PATHNAME)
|
@@ -115,8 +114,6 @@ module Deal
|
|
115
114
|
i += 1
|
116
115
|
end
|
117
116
|
end
|
118
|
-
logN "input glob:\n "+@inputs.join("\n")
|
119
|
-
|
120
117
|
|
121
118
|
end
|
122
119
|
|
@@ -143,13 +140,50 @@ module Deal
|
|
143
140
|
# end
|
144
141
|
|
145
142
|
|
146
|
-
def
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
return
|
143
|
+
def judeg_file_line(configs,path)
|
144
|
+
line_configs = []
|
145
|
+
for config in configs
|
146
|
+
line_configs.push config if config.judge_text_line?
|
151
147
|
end
|
148
|
+
if line_configs.length > 0
|
149
|
+
lines = []
|
150
|
+
File.open(path, "r") do |aFile|
|
151
|
+
is_binary = false
|
152
|
+
while line=aFile.gets
|
153
|
+
need_replace = false
|
154
|
+
for i in 0...(line.length)
|
155
|
+
begin
|
156
|
+
if line[i].ord == 0
|
157
|
+
is_binary = true
|
158
|
+
break
|
159
|
+
end
|
160
|
+
rescue Exception =>e
|
161
|
+
is_binary = true
|
162
|
+
# logE "file prase error:#{e.to_s},path:#{path}"
|
163
|
+
break
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
if is_binary
|
168
|
+
break
|
169
|
+
end
|
152
170
|
|
171
|
+
for config in line_configs
|
172
|
+
replace = config.judge_line path,line,lines.length
|
173
|
+
if replace && line != replace
|
174
|
+
need_replace
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
if !need_replace
|
179
|
+
lines.push line
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
def deal_item(configs,input)
|
153
187
|
@judge_count += 1
|
154
188
|
progress = @judge_count*1.0/@total_count
|
155
189
|
if progress - @progress > 0.01
|
@@ -157,53 +191,84 @@ module Deal
|
|
157
191
|
logW "处理进度:#{format("%.2f",progress*100).to_f}%"
|
158
192
|
end
|
159
193
|
|
160
|
-
|
161
|
-
|
194
|
+
configs = []+configs
|
195
|
+
line_configs = []
|
196
|
+
multi_configs = []
|
197
|
+
directory = File.directory?(input)
|
198
|
+
for config in configs
|
199
|
+
if directory
|
200
|
+
if !config.judge_dir_path(input)
|
201
|
+
configs.delete config
|
202
|
+
end
|
203
|
+
else
|
204
|
+
config.judge_file_path(input)
|
205
|
+
end
|
206
|
+
if config.judge_text_line?
|
207
|
+
line_configs.push config
|
208
|
+
end
|
209
|
+
if config.judge_text_multi?
|
210
|
+
multi_configs.push config
|
211
|
+
end
|
162
212
|
end
|
163
213
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
214
|
+
|
215
|
+
if !directory
|
216
|
+
if line_configs.length > 0
|
217
|
+
judeg_file_line(line_configs,input)
|
218
|
+
end
|
219
|
+
else
|
220
|
+
Dir.entries(input).each do |sub|
|
221
|
+
if sub != '.' && sub != '..'
|
222
|
+
deal_item(configs,"#{input}/#{sub}")
|
223
|
+
else
|
224
|
+
@judge_count += 0.5
|
225
|
+
end
|
169
226
|
end
|
170
227
|
end
|
171
228
|
end
|
172
229
|
|
173
230
|
def run
|
231
|
+
logN "--inputs glob:\n "+@inputs.join("\n")
|
232
|
+
logN '--configs'
|
174
233
|
for config in @configs
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
234
|
+
logN config.to_s verbose?
|
235
|
+
end
|
236
|
+
|
237
|
+
for input in @inputs
|
238
|
+
if FileTest.directory? input
|
239
|
+
match = Pathname.new(input).join('**/*').to_s
|
240
|
+
@total_count += Dir.glob(match,File::FNM_DOTMATCH).size
|
241
|
+
else
|
242
|
+
@total_count += 1
|
182
243
|
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
244
|
+
end
|
245
|
+
logW "开始扫描,总共#{@total_count}个文件"
|
246
|
+
for input in @inputs
|
247
|
+
if FileTest.exist?(input)
|
248
|
+
deal_item @configs, input
|
249
|
+
else
|
250
|
+
logE input+' file does not exist'
|
190
251
|
end
|
191
|
-
|
192
252
|
end
|
253
|
+
|
193
254
|
progress = @judge_count*1.0/@total_count
|
194
255
|
logW "处理进度:100%"
|
195
256
|
|
196
257
|
logN '=============================='
|
197
258
|
logN "共进行了#{@judge_count}次匹配"
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
logN
|
259
|
+
for config in @configs
|
260
|
+
logW "config:#{config.to_s verbose?}"
|
261
|
+
if config.results.length == 0
|
262
|
+
logN '没有匹配到结果'
|
263
|
+
else
|
264
|
+
logN "匹配到 #{config.results.length} 个结果,如下:"
|
265
|
+
for result in config.results
|
266
|
+
logN result.to_s verbose?
|
267
|
+
end
|
204
268
|
end
|
269
|
+
logN '=============================='
|
205
270
|
end
|
206
|
-
|
271
|
+
|
207
272
|
end
|
208
273
|
end
|
209
274
|
end
|
data/lib/deal/gem_version.rb
CHANGED
@@ -19,7 +19,7 @@ module Deal
|
|
19
19
|
class DealResult
|
20
20
|
def initialize(type,item,match_key,action,path)
|
21
21
|
@type = type
|
22
|
-
@item = item.strip
|
22
|
+
@item = item.strip if item
|
23
23
|
@match_key = match_key
|
24
24
|
@action = action
|
25
25
|
@file_path = path
|
@@ -32,25 +32,32 @@ module Deal
|
|
32
32
|
def set_path(path)
|
33
33
|
@file_path = path
|
34
34
|
end
|
35
|
-
def to_s
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
35
|
+
def to_s(verbose = false )
|
36
|
+
if verbose
|
37
|
+
s = []
|
38
|
+
s.push '{'
|
39
|
+
# s.push "type:#{@type}" if @type
|
40
|
+
s.push "match_item:#{@item}" if @item
|
41
|
+
s.push "match_key:#{@match_key}" if @match_key
|
42
|
+
s.push "action:#{@action}" if @action && @action.length > 0
|
43
|
+
s.push "file_path:#{@file_path}" if @file_path
|
44
|
+
s.push "line_number:#{@line_n}" if @line_n
|
45
|
+
s.push '}'
|
46
|
+
|
47
|
+
return s.join("\n")
|
48
|
+
else
|
49
|
+
s = []
|
50
|
+
s.push "#{@file_path}" if @file_path
|
51
|
+
s.push "#{@item}" if @item
|
52
|
+
return s.join(":")
|
53
|
+
end
|
54
|
+
|
48
55
|
end
|
49
56
|
|
50
57
|
end
|
51
58
|
class DealRule
|
52
59
|
include DealUtils
|
53
|
-
|
60
|
+
attr_reader :results
|
54
61
|
def initialize(config)
|
55
62
|
config['signs'] = [] if not config['signs']
|
56
63
|
config['exclude_paths'] = [] if not config['exclude_paths']
|
@@ -76,21 +83,25 @@ module Deal
|
|
76
83
|
|
77
84
|
check_type
|
78
85
|
@need_content = @judge_types.include?(JUDEG_TYPE[:TEXT]) || @judge_types.include?(JUDEG_TYPE[:MACH])
|
79
|
-
|
86
|
+
@results = []
|
80
87
|
end
|
81
88
|
|
82
|
-
def to_s
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
def to_s(verbose = false )
|
90
|
+
ls = []
|
91
|
+
ls.push "{"
|
92
|
+
ls.push "signs:#{@signs.map{|item| if item.respond_to?(:source)
|
93
|
+
item.source
|
94
|
+
else
|
95
|
+
item
|
96
|
+
end
|
97
|
+
}.join(",")}" if @signs.length > 0
|
98
|
+
ls.push "exclude_paths:#{@exclude_paths.map{|item|item.source}.join("|")}" if @exclude_paths.length > 0
|
99
|
+
ls.push "include_paths:#{@include_paths.map{|item|item.source}.join("|")}" if @include_paths.length > 0
|
100
|
+
ls.push "judge_types:#{@judge_types.join("|")}" if @judge_types.length > 0
|
101
|
+
ls.push "judge_action:#{@judge_action}"
|
102
|
+
ls.push "replace:#{@replace}" if @replace
|
103
|
+
ls.push "}"
|
104
|
+
return ls.join("\n")
|
94
105
|
end
|
95
106
|
def check_type
|
96
107
|
pass = true
|
@@ -149,6 +160,22 @@ module Deal
|
|
149
160
|
return line
|
150
161
|
end
|
151
162
|
end
|
163
|
+
def judge_dir?
|
164
|
+
return @judge_types.include?(JUDEG_TYPE[:DIR])
|
165
|
+
end
|
166
|
+
|
167
|
+
def judge_file?
|
168
|
+
return @judge_types.include?(JUDEG_TYPE[:FILE])
|
169
|
+
end
|
170
|
+
|
171
|
+
def judge_text_line?
|
172
|
+
return @judge_types.include?(JUDEG_TYPE[:TEXT])
|
173
|
+
end
|
174
|
+
|
175
|
+
def judge_text_multi?
|
176
|
+
return @judge_types.include?(JUDEG_TYPE[:TEXT])
|
177
|
+
end
|
178
|
+
|
152
179
|
def judge_item(path)
|
153
180
|
if !include_path(path)
|
154
181
|
logW 'jump path :'+path
|
@@ -260,10 +287,52 @@ module Deal
|
|
260
287
|
# end
|
261
288
|
# return result
|
262
289
|
|
290
|
+
end
|
291
|
+
def judge_file_path(path)
|
292
|
+
if !include_path(path)
|
293
|
+
logW 'jump path :'+path
|
294
|
+
return
|
295
|
+
end
|
296
|
+
|
297
|
+
if @judge_types.include?(JUDEG_TYPE[:FILE])
|
298
|
+
_judge_path(path)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def judge_dir_path(path)
|
303
|
+
if !include_path(path)
|
304
|
+
logW 'jump path :'+path
|
305
|
+
return
|
306
|
+
end
|
307
|
+
|
308
|
+
if @judge_types.include?(JUDEG_TYPE[:DIR])
|
309
|
+
_judge_path(path)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def judge_line(path,line,line_n)
|
314
|
+
for sign in @signs
|
315
|
+
if sign.match? line
|
316
|
+
action_tip = ''
|
317
|
+
ret = action sign,line,path
|
318
|
+
if ret
|
319
|
+
if ret != line
|
320
|
+
action_tip = "rename to #{ret}"
|
321
|
+
end
|
322
|
+
else
|
323
|
+
action_tip = 'remove'
|
324
|
+
end
|
325
|
+
@results.push DealResult.new('text',line,sign.source,action_tip,path)
|
326
|
+
break
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def judge_context(path)
|
332
|
+
|
263
333
|
end
|
264
334
|
|
265
|
-
def
|
266
|
-
results = []
|
335
|
+
def _judge_path(path)
|
267
336
|
for sign in @signs
|
268
337
|
if sign.match? path.to_s
|
269
338
|
action_tip = ''
|
@@ -279,10 +348,10 @@ module Deal
|
|
279
348
|
action_tip='remove files'
|
280
349
|
FileUtils.rm_rf path
|
281
350
|
end
|
282
|
-
|
351
|
+
@results.push DealResult.new('path',nil ,sign.source,action_tip,path)
|
352
|
+
break
|
283
353
|
end
|
284
354
|
end
|
285
|
-
return results
|
286
355
|
end
|
287
356
|
|
288
357
|
def judge_mach_o(line)
|