watson-ruby 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,293 +1,293 @@
1
1
  module Watson
2
-
3
- # Color definitions for pretty printing
4
- # Defined here because we need Global scope but makes sense to have them
5
- # in the printer.rb file at least
6
-
7
- BOLD = "\e[01m"
8
- UNDERLINE = "\e[4m"
9
- RESET = "\e[00m"
10
-
11
- GRAY = "\e[38;5;0m"
12
- RED = "\e[38;5;1m"
13
- GREEN = "\e[38;5;2m"
14
- YELLOW = "\e[38;5;3m"
15
- BLUE = "\e[38;5;4m"
16
- MAGENTA = "\e[38;5;5m"
17
- CYAN = "\e[38;5;6m"
18
- WHITE = "\e[38;5;7m"
19
-
20
-
21
- # Printer class that handles all formatting and printing of parsed dir/file structure
22
- class Printer
23
- # [review] - Not sure if the way static methods are defined is correct
24
- # Ok to have same name as instance methods?
25
- # Only difference is where the output gets printed to
26
- # [review] - No real setup in initialize method, combine it and run method?
27
-
28
- # Include for debug_print (for class methods)
29
- include Watson
30
-
31
- # Debug printing for this class
32
- DEBUG = false
33
-
34
- class << self
35
-
36
- # Include for debug_print (for static methods)
37
- include Watson
38
-
39
- ###########################################################
40
- # Custom color print for static call (only writes to STDOUT)
41
- def cprint (msg = "", color = "")
42
-
43
- # Identify method entry
44
- debug_print "#{ self } : #{ __method__ }\n"
45
-
46
- # This little check will allow us to take a Constant defined color
47
- # As well as a [0-256] value if specified
48
- if (color.is_a?(String))
49
- debug_print "Custom color specified for cprint\n"
50
- STDOUT.write(color)
51
- elsif (color.between?(0, 256))
52
- debug_print "No or Default color specified for cprint\n"
53
- STDOUT.write("\e[38;5;#{ color }m")
54
- end
55
-
56
- STDOUT.write(msg)
57
- end
58
-
59
-
60
- ###########################################################
61
- # Standard header print for static call (uses static cprint)
62
- def print_header
63
-
64
- # Identify method entry
65
- debug_print "#{ self } : #{ __method__ }\n"
66
-
67
- # Header
68
- cprint BOLD + "------------------------------\n" + RESET
69
- cprint BOLD + "watson" + RESET
70
- cprint " - " + RESET
71
- cprint BOLD + YELLOW + "inline issue manager\n" + RESET
72
- cprint BOLD + "------------------------------\n\n" + RESET
73
-
74
- return true
75
- end
76
-
77
-
78
- ###########################################################
79
- # Status printer for static call (uses static cprint)
80
- # Print status block in standard format
81
- def print_status(msg, color)
82
- cprint RESET + BOLD
83
- cprint WHITE + "[ "
84
- cprint "#{ msg } ", color
85
- cprint WHITE + "] " + RESET
86
- end
87
-
88
- end
89
-
90
- ###########################################################
91
- # Printer initialization method to setup necessary parameters, states, and vars
92
- def initialize(config)
93
-
94
- # Identify method entry
95
- debug_print "#{ self } : #{ __method__ }\n"
96
-
97
- @config = config
98
- return true
99
- end
100
-
101
-
102
- ###########################################################
103
- # Take parsed structure and print out in specified formatting
104
- def run(structure)
105
-
106
- # Identify method entry
107
- debug_print "#{ self } : #{ __method__ }\n"
108
-
109
- # Check Config to see if we have access to less for printing
110
- # If so, open our temp file as the output to write to
111
- # Else, just print out to STDOUT
112
- if @config.use_less
113
- debug_print "Unix less avaliable, setting output to #{ @config.tmp_file }\n"
114
- @output = File.open(@config.tmp_file, 'w')
115
- elsif
116
- debug_print "Unix less is unavaliable, setting output to STDOUT\n"
117
- @output = STDOUT
118
- end
119
-
120
- # Print header for output
121
- debug_print "Printing Header\n"
122
- print_header
123
-
124
- # Print out structure that was passed to this Printer
125
- debug_print "Starting structure printing\n"
126
- print_structure(structure)
127
-
128
- # If we are using less, close the output file, display with less, then delete
129
- if @config.use_less
130
- @output.close
131
- # [review] - Way of calling a native Ruby less?
132
- system("less #{ @config.tmp_file }")
133
- debug_print "File displayed with less, now deleting...\n"
134
- File.delete(@config.tmp_file)
135
- end
136
-
137
- return true
138
- end
139
-
140
-
141
- ###########################################################
142
- # Custom color print for member call
143
- # Allows not only for custom color printing but writing to file vs STDOUT
144
- def cprint (msg = "", color = "")
145
-
146
- # Identify method entry
147
- debug_print "#{ self } : #{ __method__ }\n"
148
-
149
- # This little check will allow us to take a Constant defined color
150
- # As well as a [0-256] value if specified
151
- if (color.is_a?(String))
152
- debug_print "Custom color specified for cprint\n"
153
- @output.write(color)
154
- elsif (color.between?(0, 256))
155
- debug_print "No or Default color specified for cprint\n"
156
- @output.write("\e[38;5;#{ color }m")
157
- end
158
-
159
- @output.write(msg)
160
- end
161
-
162
-
163
- ###########################################################
164
- # Standard header print for class call (uses member cprint)
165
- def print_header
166
- # Identify method entry
167
-
168
- debug_print "#{ self } : #{ __method__ }\n"
169
-
170
- # Header
171
- cprint BOLD + "------------------------------\n" + RESET
172
- cprint BOLD + "watson" + RESET
173
- cprint " - " + RESET
174
- cprint BOLD + YELLOW + "inline issue manager\n\n" + RESET
175
- cprint "Run in: #{ Dir.pwd }\n"
176
- cprint "Run @ #{ Time.now.asctime }\n"
177
- cprint BOLD + "------------------------------\n\n" + RESET
178
-
179
- return true
180
- end
181
-
182
-
183
- ###########################################################
184
- # Status printer for member call (uses member cprint)
185
- # Print status block in standard format
186
- def print_status(msg, color)
187
- cprint RESET + BOLD
188
- cprint WHITE + "[ "
189
- cprint "#{ msg } ", color
190
- cprint WHITE + "] " + RESET
191
- end
192
-
193
-
194
- ###########################################################
195
- # Go through all files and directories and call necessary printing methods
196
- # Print all individual entries, call print_structure on each subdir
197
- def print_structure(structure)
198
-
199
- # Identify method entry
200
- debug_print "#{ self } : #{ __method__ }\n"
201
-
202
- # First go through all the files in the current structure
203
- # The current "structure" should reflect a dir/subdir
204
- structure[:files].each do | _file |
205
- debug_print "Printing info for #{ _file }\n"
206
- print_entry(_file)
207
- end
208
-
209
- # Next go through all the subdirs and pass them to print_structure
210
- structure[:subdirs].each do | _subdir |
211
- debug_print "Entering #{ _subdir } to print further\n"
212
- print_structure(_subdir)
213
- end
214
- end
215
-
216
-
217
- ###########################################################
218
- # Individual entry printer
219
- # Uses issue hash to format printed output
220
- def print_entry(entry)
221
-
222
- # Identify method entry
223
- debug_print "#{ self } : #{ __method__ }\n"
224
-
225
- # If no issues for this file, print that and break
226
- # The filename print is repetative, but reduces another check later
227
- if entry[:has_issues] == false
228
- debug_print "No issues for #{ entry }\n"
229
- print_status "o", GREEN
230
- cprint BOLD + UNDERLINE + GREEN + "#{ entry[:relative_path] }" + RESET + "\n"
231
- return true
232
- else
233
- debug_print "Issues found for #{ entry }\n"
234
- cprint "\n"
235
- print_status "x", RED
236
- cprint BOLD + UNDERLINE + RED + "#{entry[:relative_path]}" + RESET + "\n"
237
- end
238
-
239
-
240
- # [review] - Should the tag structure be self contained in the hash
241
- # Or is it ok to reference @config to figure out the tags
242
- @config.tag_list.each do | _tag |
243
- debug_print "Checking for #{ _tag }\n"
244
-
245
- # [review] - Better way to ignore tags through structure (hash) data
246
- # Maybe have individual has_issues for each one?
247
- if entry[_tag].size.zero?
248
- debug_print "#{ _tag } has no issues, skipping\n"
249
- cprint "\n"
250
- next
251
- end
252
-
253
- debug_print "#{ _tag } has issues in it, print!\n"
254
- print_status "#{ _tag }", BLUE
255
- cprint "\n"
256
-
257
- # Go through each issue in tag
258
- entry[_tag].each do | _issue |
259
- cprint WHITE + " line #{ _issue[:line_number] } - " + RESET
260
- cprint BOLD + "#{ _issue[:title] }" + RESET
261
-
262
-
263
- # Check to see if it has been resolved on GitHub/Bitbucket
264
- debug_print "Checking if issue has been resolved\n"
265
- @config.github_issues[:closed].each do | _closed |
266
- if _closed["body"].include?(_issue[:md5])
267
- debug_print "Found in #{ _closed[:comment] }, not posting\n"
268
- cprint BOLD + " [" + RESET
269
- cprint GREEN + BOLD + "Resolved on GitHub" + RESET
270
- cprint BOLD + "]" + RESET
271
- end
272
- debug_print "Did not find in #{ _closed[:comment] }\n"
273
- end
274
-
275
- debug_print "Checking if issue has been resolved\n"
276
- @config.bitbucket_issues[:closed].each do | _closed |
277
- if _closed["content"].include?(_issue[:md5])
278
- debug_print "Found in #{ _closed["content"] }, not posting\n"
279
- cprint BOLD + " [" + RESET
280
- cprint GREEN + BOLD + "Resolved on Bitbucket" + RESET
281
- cprint BOLD + "]\n" + RESET
282
- end
283
- debug_print "Did not find in #{ _closed["title"] }\n"
284
- end
285
- cprint "\n"
286
-
287
- end
288
- cprint "\n"
289
- end
290
- end
291
-
292
- end
2
+
3
+ # Color definitions for pretty printing
4
+ # Defined here because we need Global scope but makes sense to have them
5
+ # in the printer.rb file at least
6
+
7
+ BOLD = "\e[01m"
8
+ UNDERLINE = "\e[4m"
9
+ RESET = "\e[00m"
10
+
11
+ GRAY = "\e[38;5;0m"
12
+ RED = "\e[38;5;1m"
13
+ GREEN = "\e[38;5;2m"
14
+ YELLOW = "\e[38;5;3m"
15
+ BLUE = "\e[38;5;4m"
16
+ MAGENTA = "\e[38;5;5m"
17
+ CYAN = "\e[38;5;6m"
18
+ WHITE = "\e[38;5;7m"
19
+
20
+
21
+ # Printer class that handles all formatting and printing of parsed dir/file structure
22
+ class Printer
23
+ # [review] - Not sure if the way static methods are defined is correct
24
+ # Ok to have same name as instance methods?
25
+ # Only difference is where the output gets printed to
26
+ # [review] - No real setup in initialize method, combine it and run method?
27
+
28
+ # Include for debug_print (for class methods)
29
+ include Watson
30
+
31
+ # Debug printing for this class
32
+ DEBUG = false
33
+
34
+ class << self
35
+
36
+ # Include for debug_print (for static methods)
37
+ include Watson
38
+
39
+ ###########################################################
40
+ # Custom color print for static call (only writes to STDOUT)
41
+ def cprint (msg = "", color = "")
42
+
43
+ # Identify method entry
44
+ debug_print "#{ self } : #{ __method__ }\n"
45
+
46
+ # This little check will allow us to take a Constant defined color
47
+ # As well as a [0-256] value if specified
48
+ if (color.is_a?(String))
49
+ debug_print "Custom color specified for cprint\n"
50
+ STDOUT.write(color)
51
+ elsif (color.between?(0, 256))
52
+ debug_print "No or Default color specified for cprint\n"
53
+ STDOUT.write("\e[38;5;#{ color }m")
54
+ end
55
+
56
+ STDOUT.write(msg)
57
+ end
58
+
59
+
60
+ ###########################################################
61
+ # Standard header print for static call (uses static cprint)
62
+ def print_header
63
+
64
+ # Identify method entry
65
+ debug_print "#{ self } : #{ __method__ }\n"
66
+
67
+ # Header
68
+ cprint BOLD + "------------------------------\n" + RESET
69
+ cprint BOLD + "watson" + RESET
70
+ cprint " - " + RESET
71
+ cprint BOLD + YELLOW + "inline issue manager\n" + RESET
72
+ cprint BOLD + "------------------------------\n\n" + RESET
73
+
74
+ return true
75
+ end
76
+
77
+
78
+ ###########################################################
79
+ # Status printer for static call (uses static cprint)
80
+ # Print status block in standard format
81
+ def print_status(msg, color)
82
+ cprint RESET + BOLD
83
+ cprint WHITE + "[ "
84
+ cprint "#{ msg } ", color
85
+ cprint WHITE + "] " + RESET
86
+ end
87
+
88
+ end
89
+
90
+ ###########################################################
91
+ # Printer initialization method to setup necessary parameters, states, and vars
92
+ def initialize(config)
93
+
94
+ # Identify method entry
95
+ debug_print "#{ self } : #{ __method__ }\n"
96
+
97
+ @config = config
98
+ return true
99
+ end
100
+
101
+
102
+ ###########################################################
103
+ # Take parsed structure and print out in specified formatting
104
+ def run(structure)
105
+
106
+ # Identify method entry
107
+ debug_print "#{ self } : #{ __method__ }\n"
108
+
109
+ # Check Config to see if we have access to less for printing
110
+ # If so, open our temp file as the output to write to
111
+ # Else, just print out to STDOUT
112
+ if @config.use_less
113
+ debug_print "Unix less avaliable, setting output to #{ @config.tmp_file }\n"
114
+ @output = File.open(@config.tmp_file, 'w')
115
+ else
116
+ debug_print "Unix less is unavaliable, setting output to STDOUT\n"
117
+ @output = STDOUT
118
+ end
119
+
120
+ # Print header for output
121
+ debug_print "Printing Header\n"
122
+ print_header
123
+
124
+ # Print out structure that was passed to this Printer
125
+ debug_print "Starting structure printing\n"
126
+ print_structure(structure)
127
+
128
+ # If we are using less, close the output file, display with less, then delete
129
+ if @config.use_less
130
+ @output.close
131
+ # [review] - Way of calling a native Ruby less?
132
+ system("less #{ @config.tmp_file }")
133
+ debug_print "File displayed with less, now deleting...\n"
134
+ File.delete(@config.tmp_file)
135
+ end
136
+
137
+ return true
138
+ end
139
+
140
+
141
+ ###########################################################
142
+ # Custom color print for member call
143
+ # Allows not only for custom color printing but writing to file vs STDOUT
144
+ def cprint (msg = "", color = "")
145
+
146
+ # Identify method entry
147
+ debug_print "#{ self } : #{ __method__ }\n"
148
+
149
+ # This little check will allow us to take a Constant defined color
150
+ # As well as a [0-256] value if specified
151
+ if (color.is_a?(String))
152
+ debug_print "Custom color specified for cprint\n"
153
+ @output.write(color)
154
+ elsif (color.between?(0, 256))
155
+ debug_print "No or Default color specified for cprint\n"
156
+ @output.write("\e[38;5;#{ color }m")
157
+ end
158
+
159
+ @output.write(msg)
160
+ end
161
+
162
+
163
+ ###########################################################
164
+ # Standard header print for class call (uses member cprint)
165
+ def print_header
166
+ # Identify method entry
167
+
168
+ debug_print "#{ self } : #{ __method__ }\n"
169
+
170
+ # Header
171
+ cprint BOLD + "------------------------------\n" + RESET
172
+ cprint BOLD + "watson" + RESET
173
+ cprint " - " + RESET
174
+ cprint BOLD + YELLOW + "inline issue manager\n\n" + RESET
175
+ cprint "Run in: #{ Dir.pwd }\n"
176
+ cprint "Run @ #{ Time.now.asctime }\n"
177
+ cprint BOLD + "------------------------------\n\n" + RESET
178
+
179
+ return true
180
+ end
181
+
182
+
183
+ ###########################################################
184
+ # Status printer for member call (uses member cprint)
185
+ # Print status block in standard format
186
+ def print_status(msg, color)
187
+ cprint RESET + BOLD
188
+ cprint WHITE + "[ "
189
+ cprint "#{ msg } ", color
190
+ cprint WHITE + "] " + RESET
191
+ end
192
+
193
+
194
+ ###########################################################
195
+ # Go through all files and directories and call necessary printing methods
196
+ # Print all individual entries, call print_structure on each subdir
197
+ def print_structure(structure)
198
+
199
+ # Identify method entry
200
+ debug_print "#{ self } : #{ __method__ }\n"
201
+
202
+ # First go through all the files in the current structure
203
+ # The current "structure" should reflect a dir/subdir
204
+ structure[:files].each do | _file |
205
+ debug_print "Printing info for #{ _file }\n"
206
+ print_entry(_file)
207
+ end
208
+
209
+ # Next go through all the subdirs and pass them to print_structure
210
+ structure[:subdirs].each do | _subdir |
211
+ debug_print "Entering #{ _subdir } to print further\n"
212
+ print_structure(_subdir)
213
+ end
214
+ end
215
+
216
+
217
+ ###########################################################
218
+ # Individual entry printer
219
+ # Uses issue hash to format printed output
220
+ def print_entry(entry)
221
+
222
+ # Identify method entry
223
+ debug_print "#{ self } : #{ __method__ }\n"
224
+
225
+ # If no issues for this file, print that and break
226
+ # The filename print is repetative, but reduces another check later
227
+ if entry[:has_issues] == false
228
+ debug_print "No issues for #{ entry }\n"
229
+ print_status "o", GREEN
230
+ cprint BOLD + UNDERLINE + GREEN + "#{ entry[:relative_path] }" + RESET + "\n"
231
+ return true
232
+ else
233
+ debug_print "Issues found for #{ entry }\n"
234
+ cprint "\n"
235
+ print_status "x", RED
236
+ cprint BOLD + UNDERLINE + RED + "#{entry[:relative_path]}" + RESET + "\n"
237
+ end
238
+
239
+
240
+ # [review] - Should the tag structure be self contained in the hash
241
+ # Or is it ok to reference @config to figure out the tags
242
+ @config.tag_list.each do | _tag |
243
+ debug_print "Checking for #{ _tag }\n"
244
+
245
+ # [review] - Better way to ignore tags through structure (hash) data
246
+ # Maybe have individual has_issues for each one?
247
+ if entry[_tag].size.zero?
248
+ debug_print "#{ _tag } has no issues, skipping\n"
249
+ cprint "\n"
250
+ next
251
+ end
252
+
253
+ debug_print "#{ _tag } has issues in it, print!\n"
254
+ print_status "#{ _tag }", BLUE
255
+ cprint "\n"
256
+
257
+ # Go through each issue in tag
258
+ entry[_tag].each do | _issue |
259
+ cprint WHITE + " line #{ _issue[:line_number] } - " + RESET
260
+ cprint BOLD + "#{ _issue[:title] }" + RESET
261
+
262
+
263
+ # Check to see if it has been resolved on GitHub/Bitbucket
264
+ debug_print "Checking if issue has been resolved\n"
265
+ @config.github_issues[:closed].each do | _closed |
266
+ if _closed["body"].include?(_issue[:md5])
267
+ debug_print "Found in #{ _closed[:comment] }, not posting\n"
268
+ cprint BOLD + " [" + RESET
269
+ cprint GREEN + BOLD + "Resolved on GitHub" + RESET
270
+ cprint BOLD + "]" + RESET
271
+ end
272
+ debug_print "Did not find in #{ _closed[:comment] }\n"
273
+ end
274
+
275
+ debug_print "Checking if issue has been resolved\n"
276
+ @config.bitbucket_issues[:closed].each do | _closed |
277
+ if _closed["content"].include?(_issue[:md5])
278
+ debug_print "Found in #{ _closed["content"] }, not posting\n"
279
+ cprint BOLD + " [" + RESET
280
+ cprint GREEN + BOLD + "Resolved on Bitbucket" + RESET
281
+ cprint BOLD + "]\n" + RESET
282
+ end
283
+ debug_print "Did not find in #{ _closed["title"] }\n"
284
+ end
285
+ cprint "\n"
286
+
287
+ end
288
+ cprint "\n"
289
+ end
290
+ end
291
+
292
+ end
293
293
  end