icersplicer 0.8.4 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/icersplicer +26 -16
- data/lib/icersplicer.rb +162 -149
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c79c144aea7b10ae25373863f07871e381b53baf
|
4
|
+
data.tar.gz: 135decaecbfe484b53fef4579e31b8a5477a01bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 201632e6e5dcb26d1c80792a6bfb4a65d4109349622c915c533051ebb147400b68a25eddf4a741c4ee8c96b3312da905c66fbdcd72ffb89de857542c522527d6
|
7
|
+
data.tar.gz: 5e6b0a8962aaa87ccb6e9dcbf263b7dc88544b9c15f8fe3eb29378cfa4d70fdca0f76ac915494ad5d511138de3f697fcb31da443d49facbc82190e30bc05ce3d
|
data/bin/icersplicer
CHANGED
@@ -25,16 +25,18 @@ include Icersplicer
|
|
25
25
|
|
26
26
|
trap("INT") {
|
27
27
|
puts "Goodbye see you soon!"
|
28
|
-
reset_screen
|
28
|
+
ice.reset_screen
|
29
29
|
exit
|
30
30
|
}
|
31
31
|
|
32
32
|
VERSION = Icersplicer::VERSION::STRING
|
33
|
+
ice = FileProcessor.new
|
33
34
|
|
34
35
|
ARGV[0] = "--help" if ARGV[0] == nil
|
35
36
|
|
36
37
|
opts = GetoptLong.new(
|
37
38
|
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
39
|
+
[ '--keywordsfile', '-k', GetoptLong::REQUIRED_ARGUMENT],
|
38
40
|
[ '--lineoffset', '-l', GetoptLong::OPTIONAL_ARGUMENT],
|
39
41
|
[ '--linelimit', '-n', GetoptLong::REQUIRED_ARGUMENT],
|
40
42
|
[ '--head', '-3', GetoptLong::REQUIRED_ARGUMENT],
|
@@ -52,6 +54,7 @@ opts = GetoptLong.new(
|
|
52
54
|
[ '--search', '-1', GetoptLong::REQUIRED_ARGUMENT],
|
53
55
|
[ '--replace', '-2', GetoptLong::REQUIRED_ARGUMENT],
|
54
56
|
[ '--nostats', '-6', GetoptLong::NO_ARGUMENT ],
|
57
|
+
[ '--debug', '-d', GetoptLong::REQUIRED_ARGUMENT ]
|
55
58
|
)
|
56
59
|
|
57
60
|
opts.each do |opt, arg|
|
@@ -61,7 +64,9 @@ opts.each do |opt, arg|
|
|
61
64
|
helper << "\e[1;34m============================\e[0m\ \n"
|
62
65
|
helper << %Q[
|
63
66
|
-h, --help '-h':
|
64
|
-
show help
|
67
|
+
show help, )
|
68
|
+
--keywordsfile '-k' STRING ( Syntax Highlighting Keywords file see examples )
|
69
|
+
Full path not required just keywords-ruby.ice just place it in .icersplicer
|
65
70
|
--lineoffset '-l' INTEGER
|
66
71
|
--linelimit '-n' INTEGER
|
67
72
|
--head '-3' INTEGER
|
@@ -74,10 +79,11 @@ opts.each do |opt, arg|
|
|
74
79
|
--outputfile '-o' filename
|
75
80
|
--countlines '-c' Counts the lines of a file
|
76
81
|
--grep '-g' Filter data
|
77
|
-
--nohighlighter '-t' NO ARGUMENTS ( Turns off
|
82
|
+
--nohighlighter '-t' NO ARGUMENTS ( Turns off Syntax Hightlighting )
|
78
83
|
--search '-1' Text to search for
|
79
84
|
--replace '-2' Replacement string
|
80
85
|
--nostats '-6' Don't process statistics before exit
|
86
|
+
--debug '-d' Verbose debug for hacking on this project
|
81
87
|
|
82
88
|
Example:
|
83
89
|
|
@@ -94,11 +100,13 @@ Written by Brian Hood
|
|
94
100
|
]
|
95
101
|
puts helper
|
96
102
|
exit
|
103
|
+
when '--keywordsfile'
|
104
|
+
ice.keywordsfile = arg.to_s
|
97
105
|
when /^--lineoffset|^--tail/
|
98
106
|
if opt == "--lineoffset"
|
99
107
|
@line_offset = arg.to_i
|
100
108
|
else
|
101
|
-
count = countlines(@inputfile)
|
109
|
+
count = ice.countlines(@inputfile)
|
102
110
|
@line_offset = count - arg.to_i
|
103
111
|
end
|
104
112
|
when /^--linelimit|^--head/
|
@@ -114,7 +122,7 @@ Written by Brian Hood
|
|
114
122
|
@outputfile = arg.to_s
|
115
123
|
puts "Outputfile: #{@outputfile}"
|
116
124
|
when '--skiplines'
|
117
|
-
|
125
|
+
ice.skip_lines = ice.skip_processor(arg)
|
118
126
|
when '--skipblank'
|
119
127
|
@skipblank = "SKIP"
|
120
128
|
when '--quiet'
|
@@ -125,13 +133,15 @@ Written by Brian Hood
|
|
125
133
|
when '--grep'
|
126
134
|
@grep = arg.to_s
|
127
135
|
when '--nohighlighter'
|
128
|
-
|
136
|
+
ice.nohighlighter = "OFF"
|
129
137
|
when '--search'
|
130
138
|
@search = arg.to_s
|
131
139
|
when '--replace'
|
132
140
|
@replace = arg.to_s
|
133
141
|
when '--nostats'
|
134
142
|
@nostats = "SKIP"
|
143
|
+
when '--debug'
|
144
|
+
ice.debug = arg.to_i
|
135
145
|
end
|
136
146
|
end
|
137
147
|
|
@@ -141,7 +151,7 @@ grep = @grep
|
|
141
151
|
|
142
152
|
if instance_variable_defined?("@followtail")
|
143
153
|
lines = @followtail
|
144
|
-
followtail(inputfile, lines)
|
154
|
+
ice.followtail(inputfile, lines)
|
145
155
|
end
|
146
156
|
|
147
157
|
if instance_variable_defined?("@search")
|
@@ -177,7 +187,7 @@ linecounter = 0
|
|
177
187
|
quietmode = false | @quiet_mode
|
178
188
|
|
179
189
|
if @countlines == true
|
180
|
-
countlines(inputfile)
|
190
|
+
ice.countlines(inputfile)
|
181
191
|
exit
|
182
192
|
end
|
183
193
|
|
@@ -204,10 +214,10 @@ begin
|
|
204
214
|
unless instance_variable_defined?("@skipblank") and data_orig.strip == ""
|
205
215
|
if data_orig =~ /#{grep}/
|
206
216
|
filterlines += 1
|
207
|
-
print_to_screen(linecounter, text_processor(data), quietmode) unless skip(linecounter)
|
217
|
+
ice.print_to_screen(linecounter, ice.text_processor(data), quietmode) unless ice.skip(linecounter)
|
208
218
|
if instance_variable_defined?("@outputfile")
|
209
219
|
data_orig.gsub!("#{search}", "#{replace}")
|
210
|
-
processdata(data_orig, outputfile, quietmode) unless skip(linecounter)
|
220
|
+
ice.processdata(data_orig, outputfile, quietmode) unless ice.skip(linecounter)
|
211
221
|
end
|
212
222
|
end
|
213
223
|
end
|
@@ -216,10 +226,10 @@ begin
|
|
216
226
|
unless instance_variable_defined?("@skipblank") and data_orig.strip == ""
|
217
227
|
if data_orig =~ /#{grep}/
|
218
228
|
filterlines += 1
|
219
|
-
print_to_screen(linecounter, text_processor(data), quietmode) unless skip(linecounter)
|
229
|
+
ice.print_to_screen(linecounter, ice.text_processor(data), quietmode) unless ice.skip(linecounter)
|
220
230
|
if instance_variable_defined?("@outputfile")
|
221
231
|
data_orig.gsub!("#{search}", "#{replace}")
|
222
|
-
processdata(data_orig, outputfile, quietmode) unless skip(linecounter)
|
232
|
+
ice.processdata(data_orig, outputfile, quietmode) unless ice.skip(linecounter)
|
223
233
|
end
|
224
234
|
end
|
225
235
|
end
|
@@ -233,11 +243,11 @@ begin
|
|
233
243
|
rescue Errno::EPIPE, IOError
|
234
244
|
raise IOError, "Closing session due to broken pipe"
|
235
245
|
end
|
236
|
-
closefile
|
246
|
+
ice.closefile
|
237
247
|
unless instance_variable_defined?("@nostats")
|
238
|
-
filterlinestats(filterlines)
|
239
|
-
stats(inputfile, outputfile)
|
248
|
+
ice.filterlinestats(filterlines)
|
249
|
+
ice.stats(inputfile, outputfile)
|
240
250
|
timer.watch('stop')
|
241
251
|
timer.print_stats
|
242
252
|
end
|
243
|
-
reset_screen
|
253
|
+
ice.reset_screen
|
data/lib/icersplicer.rb
CHANGED
@@ -15,182 +15,195 @@ module Icersplicer
|
|
15
15
|
module VERSION #:nodoc:
|
16
16
|
MAJOR = 0
|
17
17
|
MINOR = 8
|
18
|
-
TINY =
|
19
|
-
CODENAME = "
|
18
|
+
TINY = 9
|
19
|
+
CODENAME = "Icey Sea !"
|
20
20
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
21
21
|
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
module Icersplicer
|
26
|
+
|
27
|
+
class FileProcessor
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
attr_writer :nohighlighter, :skip_lines, :keywordsfile, :debug
|
30
|
+
|
31
|
+
COLOURS = {"black" => 0,
|
32
|
+
"red" => 1,
|
33
|
+
"green" => 2,
|
34
|
+
"yellow" => 3,
|
35
|
+
"blue" => 4,
|
36
|
+
"purple" => 5,
|
37
|
+
"cyan" => 6,
|
38
|
+
"white" => 7}
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
@fileopen = 0
|
42
|
+
@exp = nil
|
43
|
+
@keywordsfile = "keywords.ice"
|
44
|
+
@debug = 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def reset_screen
|
48
|
+
puts "\e[0m\ "
|
49
|
+
end
|
50
|
+
|
51
|
+
def filterlinestats(filterlines)
|
52
|
+
puts "\nLines Displayed by Filter: #{filterlines}"
|
53
|
+
end
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
55
|
+
def followtail(filename, number)
|
56
|
+
File::Tail::Logfile.open(filename) do |log|
|
57
|
+
log.interval = 3
|
58
|
+
log.backward(10)
|
59
|
+
log.backward(number).tail { |line| puts line }
|
60
|
+
end
|
61
|
+
exit
|
50
62
|
end
|
51
|
-
exit
|
52
|
-
end
|
53
63
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def load_keywords(file)
|
65
|
+
keys = Hash.new
|
66
|
+
linenum = 0
|
67
|
+
unless Dir.exists?("#{Dir.home}/.icersplicer")
|
68
|
+
Dir.mkdir("#{Dir.home}/.icersplicer")
|
69
|
+
end
|
70
|
+
if File.exists?("#{Dir.home}/.icersplicer/#{file}")
|
71
|
+
File.open("#{Dir.home}/.icersplicer/#{file}") {|n|
|
72
|
+
n.each_line {|l|
|
73
|
+
keys.update({linenum => "#{l.strip}"}) unless l.strip == ""
|
74
|
+
puts "L: #{l.strip}" if @debug >= 1
|
75
|
+
linenum += 1
|
76
|
+
}
|
66
77
|
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
78
|
+
return keys
|
79
|
+
else
|
80
|
+
return false
|
81
|
+
end
|
71
82
|
end
|
72
|
-
end
|
73
83
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
84
|
+
def text_processor(data)
|
85
|
+
unless @nohighlighter == "OFF"
|
86
|
+
data = text_highlighter(data)
|
87
|
+
return data
|
88
|
+
else
|
89
|
+
return data
|
90
|
+
end
|
80
91
|
end
|
81
|
-
end
|
82
92
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
cpicker = [2,3,4,1,7,5,6] # Just a selection of colours
|
94
|
-
@keys.each {|n|
|
95
|
-
if n[1].split("##")[1] == nil
|
96
|
-
text.gsub!("#{n[1]}", "\e[4;3#{cpicker[rand(cpicker.size)]}m#{n[1]}\e[0m\ \e[0;32m")
|
97
|
-
else
|
98
|
-
name = n[1].split("##")[1].split("=")[1]; puts "Name: #{name}" if @@debug == true
|
99
|
-
cnum = COLOURS[name].to_i; puts "Colour Number: #{cnum}" if @@debug == true
|
100
|
-
nval = n[1].split("##")[0]; puts "Value: #{nval}" if @@debug == true
|
101
|
-
text.gsub!("#{nval}", "\e[4;3#{cnum}m#{nval}\e[0m\ \e[0;32m")
|
93
|
+
def text_highlighter(text)
|
94
|
+
@keys ||= load_keywords("#{@keywordsfile}")
|
95
|
+
unless @keys.class == Hash
|
96
|
+
@keys = {0 => "Ln:",
|
97
|
+
1 => "SELECT",
|
98
|
+
2 => "CREATE TABLE",
|
99
|
+
3 => "UPDATE",
|
100
|
+
4 => "DELETE",
|
101
|
+
5 => "INSERT"}
|
102
102
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
cpicker = [2,3,4,1,7,5,6] # Just a selection of colours
|
104
|
+
@keys.each {|n|
|
105
|
+
if n[1].split("##")[1] == nil
|
106
|
+
text.gsub!("#{n[1]}", "\e[4;3#{cpicker[rand(cpicker.size)]}m#{n[1]}\e[0m\ \e[0;32m")
|
107
|
+
else
|
108
|
+
name = n[1].split("##")[1].split("=")[1]; puts "Name: #{name}" if @debug >= 3
|
109
|
+
cnum = COLOURS[name].to_i; puts "Colour Number: #{cnum}" if @debug >= 3
|
110
|
+
nval = n[1].split("##")[0]; puts "Value: #{nval}" if @debug >= 3
|
111
|
+
text.gsub!("#{nval}", "\e[4;3#{cnum}m#{nval}\e[0m\ \e[0;32m")
|
112
|
+
end
|
113
|
+
text.gsub!(" \e[0;32m", "\e[0;32m")
|
114
|
+
}
|
115
|
+
return text
|
116
|
+
end
|
107
117
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
118
|
+
def countlines(inputfile)
|
119
|
+
lines = 0
|
120
|
+
unless inputfile == nil
|
121
|
+
if File.exist?(inputfile)
|
122
|
+
File.open(inputfile) {|n|
|
123
|
+
n.each_line {
|
124
|
+
lines += 1
|
125
|
+
}
|
115
126
|
}
|
116
|
-
|
117
|
-
|
127
|
+
puts "Filename: #{inputfile} Total Line Count: #{lines}"
|
128
|
+
end
|
118
129
|
end
|
130
|
+
return lines
|
119
131
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
|
133
|
+
def skip_processor(filter)
|
134
|
+
skip_lines = Hash.new
|
135
|
+
skipcounter = 0
|
136
|
+
filter.to_s.split(",").each {|n|
|
137
|
+
skip_lines.update({skipcounter => n.to_i})
|
138
|
+
# Allow line ranges
|
139
|
+
min = n.split("-")[0].to_i
|
140
|
+
max = n.split("-")[1].to_i
|
141
|
+
puts "Min: #{min} Max: #{max}" if @debug >= 2
|
142
|
+
unless n.split("-")[1] == nil
|
143
|
+
if min > max
|
144
|
+
raise RangeError, "Range Error: Minimun value can't be more than Maxiumun Range value"
|
145
|
+
end
|
146
|
+
min.upto(max) {|s|
|
147
|
+
skip_lines.update({skipcounter => s}) unless skip_lines[skip_lines.size - 1] == s
|
148
|
+
skipcounter += 1
|
149
|
+
}
|
150
|
+
end
|
151
|
+
skipcounter += 1
|
152
|
+
}
|
153
|
+
return skip_lines
|
154
|
+
end
|
155
|
+
|
156
|
+
def skip(line)
|
157
|
+
begin
|
158
|
+
if instance_variable_defined?("@skip_lines")
|
159
|
+
line_element = @skip_lines.key(line)
|
160
|
+
if line_element != nil
|
161
|
+
skiper = @skip_lines[line_element]
|
135
162
|
end
|
136
|
-
min.upto(max) {|s|
|
137
|
-
skip_lines.update({skipcounter => s}) unless skip_lines[skip_lines.size - 1] == s
|
138
|
-
skipcounter += 1
|
139
|
-
}
|
140
|
-
end
|
141
|
-
skipcounter += 1
|
142
|
-
}
|
143
|
-
return skip_lines
|
144
|
-
end
|
145
|
-
|
146
|
-
def skip(line)
|
147
|
-
begin
|
148
|
-
if instance_variable_defined?("@skip_lines")
|
149
|
-
line_element = @skip_lines.key(line)
|
150
|
-
if line_element != nil
|
151
|
-
skiper = @skip_lines[line_element]
|
152
163
|
end
|
164
|
+
rescue NoMethodError
|
165
|
+
return nil
|
153
166
|
end
|
154
|
-
|
155
|
-
return nil
|
167
|
+
return skiper
|
156
168
|
end
|
157
|
-
return skiper
|
158
|
-
end
|
159
169
|
|
160
|
-
|
161
|
-
|
162
|
-
|
170
|
+
def print_to_screen(linenum, text, quiet)
|
171
|
+
puts "\e[1;33mLn: #{linenum}:\e[0m\ #{text}" unless quiet == true
|
172
|
+
end
|
163
173
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
174
|
+
def openfile(outputfile)
|
175
|
+
begin
|
176
|
+
puts "Openfile: #{outputfile}" if @debug == true
|
177
|
+
@export = File.open("#{outputfile}", 'w')
|
178
|
+
rescue Errno::EACCES
|
179
|
+
raise IOError, "Can't create file please check file / directory permissions"
|
180
|
+
end
|
170
181
|
end
|
171
|
-
end
|
172
182
|
|
173
|
-
|
174
|
-
|
175
|
-
|
183
|
+
def writefile(data)
|
184
|
+
@export.write(data)
|
185
|
+
end
|
176
186
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
187
|
+
def closefile
|
188
|
+
begin
|
189
|
+
@export.close
|
190
|
+
puts "Closing file"
|
191
|
+
rescue NoMethodError
|
192
|
+
end
|
182
193
|
end
|
183
|
-
end
|
184
194
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
195
|
+
def processdata(data, outputfile, quietmode)
|
196
|
+
openfile(outputfile) if @fileopen == 0
|
197
|
+
writefile(data)
|
198
|
+
@fileopen += 1
|
199
|
+
end
|
190
200
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
201
|
+
def stats(inputfile, outputfile)
|
202
|
+
puts "Skip Lines #{@skip_lines}" if @debug >= 1
|
203
|
+
print "Inputfile lines: "
|
204
|
+
countlines(inputfile)
|
205
|
+
end
|
195
206
|
|
207
|
+
end
|
208
|
+
|
196
209
|
end
|