fox 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Standard includes
4
+ require 'bundler'
5
+ require 'thor'
6
+ require 'rake'
7
+ require 'ruby-try'
8
+
9
+
10
+ # @class Fox
11
+ # @brief Provides complete solution for scientific authoring
12
+ class Fox
13
+
14
+ # @fn def initialize {{{
15
+ # @brief Default Constructor
16
+ def initialize
17
+ end # }}}
18
+
19
+ end # of module Fox
20
+
21
+ # Load other library files
22
+ Dir[ File.dirname(__FILE__) + '/fox/library/*.rb' ].each { |file| require file }
23
+
24
+
25
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ ## Handle Cucumber # {{{
5
+
6
+ namespace :cucumber do
7
+
8
+ begin
9
+ require 'cucumber'
10
+ require 'cucumber/rake/task'
11
+
12
+ desc "Cucumber Core Tasks" # {{{
13
+ Cucumber::Rake::Task.new(:pretty) do |t|
14
+ t.cucumber_opts = "--format pretty -S"
15
+ end # }}}
16
+
17
+ desc "Cucumber Core Tasks" # {{{
18
+ Cucumber::Rake::Task.new(:progress) do |t|
19
+ t.cucumber_opts = "--format progress -S"
20
+ end # }}}
21
+
22
+ rescue LoadError
23
+ desc 'Cucumber rake task not available'
24
+ task :pretty do
25
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
26
+ end
27
+
28
+ task :progress do
29
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
30
+ end
31
+ end
32
+
33
+ end # pf namespace }}}
34
+
35
+
36
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System
5
+ require 'bundler'
6
+ require 'bundler/gem_tasks'
7
+
8
+ require 'shellwords'
9
+ require 'fileutils'
10
+
11
+ require 'date'
12
+ require 'ostruct'
13
+
14
+
15
+
16
+ ### General
17
+
18
+ desc "Show the default task when executing rake without arguments" # {{{
19
+ task :default => :help # }}}
20
+
21
+ desc "Shows the usage help screen" # {{{
22
+ task :help do |t|
23
+ `rake -T`
24
+ end # }}}
25
+
26
+
27
+
28
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ namespace :docs do
5
+
6
+ desc "Generate Yardoc documentation for this project" # {{{
7
+ task :generate do |t|
8
+
9
+ # Define new tags for yardoc to detect
10
+ tags = {}
11
+ tags[ "module" ] = "Module"
12
+ tags[ "class" ] = "Class"
13
+ tags[ "fn" ] = "Function"
14
+ tags[ "brief" ] = "Description"
15
+
16
+ # Hide tags we don't want in yardoc output
17
+ hidden = %w[module class fn]
18
+ files = %w|lib/*.rb lib/**/*.rb lib/**/**/*.rb - COPYING.md AUTHORS.md|.join " "
19
+
20
+ # Construct tag string for CLI command
21
+ tags_line = ""
22
+ tags.each_pair { |n,v| tags_line += " --tag #{n.to_s}:\"#{v.to_s}\"" }
23
+ hidden.each { |h| tags_line += " --hide-tag #{h.to_s}" }
24
+
25
+ puts "(II) Generating multi-file yardoc output written to doc/yardoc"
26
+ system "yard --markup-provider=redcarpet --markup=markdown #{tags_line.to_s} -o doc/yardoc #{files}"
27
+
28
+ puts "(II) Generating one-file yardoc output written to doc/yardoc_pdf"
29
+ system "yard --markup-provider=redcarpet --markup=markdown --one-file #{tags_line.to_s} -o doc/yardoc_pdf #{files}"
30
+
31
+ # puts "(II) HTML to PDF written to doc/yardoc_pdf"
32
+ # pdf = WickedPdf.new.pdf_from_string( File.read( "doc/yardoc_pdf/index.html" ) )
33
+ # File.write( "doc/yardoc_pdf/index.pdf", pdf )
34
+ end # }}}
35
+
36
+ desc "Generate Yard Graphs for this project" # {{{
37
+ task :graph do |t|
38
+ basedir = "doc/yard-graph"
39
+ FileUtils.mkdir_p( basedir )
40
+ system "yard graph --dependencies --empty-mixins --full > #{basedir.to_s}/graph.dot"
41
+ system "dot -Tpng #{basedir.to_s}/graph.dot > #{basedir.to_s}/graph.png"
42
+ end # }}}
43
+
44
+ end # of namespace :docs
45
+
46
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ namespace :guard do
5
+
6
+ desc "Execute Ruby Guard" # {{{
7
+ task :default do |g|
8
+ sh "bundle exec guard start -G Guardfile"
9
+ end # }}}
10
+
11
+ end
12
+
13
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System
5
+ require 'shellwords'
6
+ require 'fileutils'
7
+
8
+ require 'date'
9
+ require 'ostruct'
10
+
11
+
12
+
13
+ ### Actions
14
+
15
+ desc "Look for TODO and FIXME tags in the code" # {{{
16
+ task :todo do
17
+ egrep /(FIXME|TODO|TBD|FIXME1|FIXME2|FIXME3)/
18
+ end # }}}
19
+
20
+ desc "Git Tag number of this repo" # {{{
21
+ task :version do |t|
22
+ # sh 'git describe --abbrev=0 --tags'
23
+ sh 'git describe --tags'
24
+ end # }}}
25
+
26
+
27
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System
5
+ require 'shellwords'
6
+ require 'fileutils'
7
+
8
+ require 'date'
9
+ require 'ostruct'
10
+
11
+
12
+ ### Helper Functions
13
+
14
+ # @fn def egrep(pattern) # {{{
15
+ # @brief Searches for a given regular expression among all ruby files
16
+ #
17
+ # @param [Regexp] pattern Regular Expression pattern class
18
+ def egrep( pattern )
19
+
20
+ Dir[ "**/*.{rb,thor,rake}" ].each do |fn|
21
+ count = 0
22
+ open(fn) do |f|
23
+
24
+ while line = f.gets
25
+ count += 1
26
+ STDOUT.puts "#{fn}:#{count}:#{line}" if line =~ pattern
27
+ end
28
+
29
+ end # end of open
30
+ end # end of Dir.each
31
+
32
+ end # }}}
33
+
34
+ # @fn def clean target # {{{
35
+ # @brief Clean thrift output from folder
36
+ #
37
+ # @param [String] target Target folder to clean
38
+ def clean target
39
+
40
+ files = Dir.glob( File.join( target, "*" ) )
41
+
42
+ files.each do |file|
43
+ print "(--) "
44
+ sh "rm -vrf #{file.to_s}" if( File.exists?( "#{file.to_s}" ) )
45
+ end
46
+
47
+ end # }}}
48
+
49
+ # @fn def colorize color, message {{{
50
+ # @brief The function colorize takes a message and wraps it into standard color commands such as for bash.
51
+ #
52
+ # @param [String] color The colorname in plain english. e.g. "LightGray", "Gray", "Red", "BrightRed"
53
+ # @param [String] message The message which should be wrapped
54
+ #
55
+ # @return [String] Colorized message string
56
+ #
57
+ # @warning Might not work for your terminal
58
+ #
59
+ # FIXME: Implement bold behavior
60
+ # FIXME: This method is currently b0rked
61
+ def colorize color, message
62
+
63
+ # Black 0;30 Dark Gray 1;30
64
+ # Blue 0;34 Light Blue 1;34
65
+ # Green 0;32 Light Green 1;32
66
+ # Cyan 0;36 Light Cyan 1;36
67
+ # Red 0;31 Light Red 1;31
68
+ # Purple 0;35 Light Purple 1;35
69
+ # Brown 0;33 Yellow 1;33
70
+ # Light Gray 0;37 White 1;37
71
+
72
+ colors = {
73
+ "Gray" => "\e[1;30m",
74
+ "LightGray" => "\e[0;37m",
75
+ "Cyan" => "\e[0;36m",
76
+ "LightCyan" => "\e[1;36m",
77
+ "Blue" => "\e[0;34m",
78
+ "LightBlue" => "\e[1;34m",
79
+ "Green" => "\e[0;32m",
80
+ "LightGreen" => "\e[1;32m",
81
+ "Red" => "\e[0;31m",
82
+ "LightRed" => "\e[1;31m",
83
+ "LightRedBlink" => "\e[5;31m",
84
+ "Purple" => "\e[0;35m",
85
+ "LightPurple" => "\e[1;35m",
86
+ "Brown" => "\e[0;33m",
87
+ "Yellow" => "\e[1;33m",
88
+ "White" => "\e[1;37m"
89
+ }
90
+ nocolor = "\e[0m"
91
+
92
+ colors[ color ] + message + nocolor
93
+ end # of def colorize }}}
94
+
95
+ # @fn def message level, msg {{{
96
+ # @brief The function message will take a message as argument as well as a level (e.g. "info", "ok", "error", "question", "debug") which then would print
97
+ # ( "(--) msg..", "(II) msg..", "(EE) msg..", "(??) msg..")
98
+ #
99
+ # @param [Symbol] level Can either be :info, :success, :error or :question
100
+ # @param [String] msg Represents the message you want to send to stdout (info, ok, question) stderr (error)
101
+ #
102
+ # Helpers: colorize
103
+ def message level, msg
104
+
105
+ symbols = {
106
+ :info => [ "(--)", "Brown" ],
107
+ :success => [ "(II)", "LightGreen" ],
108
+ :error => [ "(EE)", "LightRed" ],
109
+ :question => [ "(??)", "LightCyan" ],
110
+ :debug => [ "(++)", "LightBlue" ],
111
+ :warning => [ "(WW)", "Yellow" ]
112
+ }
113
+
114
+ raise ArugmentError, "Can't find the corresponding symbol for this message level (#{level.to_s}) - is the spelling wrong?" unless( symbols.key?( level ) )
115
+
116
+ if( level == :error )
117
+ STDERR.puts colorize( symbols[ level.to_sym ].last, "#{symbols[ level.to_sym ].first.to_s} #{msg.to_s}" )
118
+ else
119
+ STDOUT.puts colorize( symbols[ level.to_sym ].last, "#{symbols[ level.to_sym ].first.to_s} #{msg.to_s}" )
120
+ end
121
+
122
+ end # of def message }}}
123
+
124
+
125
+
126
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ namespace :metric do
4
+
5
+ desc "Run metric fu for project" # {{{
6
+ task :metric do |t|
7
+ puts "(--) Running metric fu"
8
+ system "metric_fu"
9
+ end # }}}
10
+
11
+ end # of namespace :metric
12
+
13
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ ## Handle RSpec 1.x and 2.x branches # {{{
5
+ #
6
+ # dm-redis-adapter and others maybe need 1.x while we want 2.x is possible.
7
+ begin
8
+
9
+ require 'rspec/core/rake_task'
10
+
11
+ desc "RSpec Core Tasks" # {{{
12
+ RSpec::Core::RakeTask.new(:spec) do |t|
13
+ t.rspec_opts = '--format NyanCatWideFormatter --color --fail-fast --order random'
14
+ end # }}}
15
+
16
+ rescue LoadError
17
+
18
+ puts "(WW) Could not load RSpec 2.x branch, falling back to 1.x."
19
+
20
+ require 'spec/rake/spectask'
21
+
22
+ desc "Run specs" # {{{
23
+ Spec::Rake::SpecTask.new do |t|
24
+ t.spec_files = FileList['spec/**/*_spec.rb']
25
+ t.spec_opts = %w(-fs --color)
26
+ end # }}}
27
+
28
+ end # }}}
29
+
30
+
31
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,291 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System includes
5
+ require 'ostruct'
6
+ require 'andand'
7
+ require 'tempfile'
8
+ require 'os'
9
+
10
+ # Custom includes
11
+ require File.expand_path( File.dirname( __FILE__ ) + '/mixin/shell' )
12
+
13
+
14
+ # @class Info command class
15
+ # @brief Implements the info command
16
+ class Info < Thor
17
+
18
+ include ::Mixin::Shell
19
+ # include ::Mixin::Command
20
+
21
+ default_task :info
22
+
23
+ class_option :'without-general', :type => :boolean, :desc => "Print general system environment information"
24
+ class_option :'without-project', :type => :boolean, :desc => "Print project environment information"
25
+ class_option :'without-ruby', :type => :boolean, :desc => "Print ruby environment information"
26
+
27
+ class_option :pretty, :type => :boolean, :desc => "Pretty print"
28
+
29
+
30
+ ## API
31
+
32
+ # @fn def info {{{
33
+ # @brief Main info task entry point
34
+ desc "overview", "Shows system overview"
35
+ def overview
36
+
37
+ # Default symbol action list to find info for
38
+ default = %i(
39
+ general
40
+ project
41
+ ruby
42
+ )
43
+
44
+ # Make sure if we have a --without-* opts to skip work
45
+ options.each_pair do |option, skip|
46
+ next unless( skip )
47
+ default.delete_if { |item| option =~ %r{#{item.to_s}}i }
48
+ end
49
+
50
+ # Execute scan & print
51
+ default.each do |item|
52
+ data = scan_for item
53
+ next if data.andand.broken.nil?
54
+
55
+ self.send :pretty_print, data
56
+ end # of default.each
57
+
58
+ end # }}}
59
+
60
+
61
+ private
62
+
63
+ no_tasks do
64
+
65
+ ## Actions
66
+
67
+ # @fn def scan_for what # {{{
68
+ # @brief When executed will run "what" method scanner and print relevant information
69
+ #
70
+ # @param [Symbol] what Symbol of scanner method to run, e.g. :general, :java, :ruby etc.
71
+ def scan_for what
72
+ result = nil
73
+
74
+ begin
75
+ result = self.send what
76
+ rescue Exception => e
77
+ say "(EE) " + e.message, :red
78
+ result = OpenStruct.new
79
+ result.broken = true
80
+ end
81
+
82
+ return result
83
+ end # }}}
84
+
85
+ # @fn def pretty_print information, playful = options[:pretty] # {{{
86
+ # @brief Pretty prints given data to stdout
87
+ #
88
+ # @param [OpenStruct] information Information gathered from other scanning methods, e.g. :ruby
89
+ # @param [Boolean] playful Prints some curses like lines if true
90
+ def pretty_print information, playful = options[:pretty]
91
+ begin
92
+ puts ""
93
+ say information.title, :yellow
94
+
95
+ if( playful )
96
+ puts "-"*26
97
+ puts " "*26 + "\\"
98
+ else
99
+ puts ""
100
+ end
101
+
102
+ values = information.send :table
103
+ raise ArgumentError, "Information openstruct is malformed" if( values[ :broken ] )
104
+
105
+ values.each do |key, value|
106
+
107
+ # Skip :broken, :title
108
+ next if( %i(title broken).include?( key.to_sym ) )
109
+
110
+ # Make sure value is a string
111
+ value = value.to_s
112
+
113
+ # Remove pre- and post-padding
114
+ value.strip!
115
+
116
+ # Turn key into a nice printable value
117
+ # e.g. :current_directory => Current directory
118
+ description = key.to_s
119
+ description.gsub!( "_", " " )
120
+ description.capitalize!
121
+
122
+
123
+ # Check if value is multi-line, if so, format accordingly
124
+ output = []
125
+
126
+ if( value =~ %r{\n} )
127
+ lines = value.split( "\n" )
128
+ output << sprintf( "%-25s | %s", description, lines.shift )
129
+ lines.each { |line| output << sprintf( "%-25s | %s", "", line ) }
130
+ else
131
+ output << sprintf( "%-25s | %s", description, value )
132
+ end
133
+
134
+ output.each { |something| say something }
135
+ end
136
+
137
+ if( playful )
138
+ puts " "*26 + "\\"
139
+ puts " "*27 + "-"*80
140
+ end
141
+
142
+ puts ""
143
+
144
+ rescue Exception => e
145
+ say "(EE) " + e.message, :red
146
+ end
147
+ end # }}}
148
+
149
+
150
+ ## Specific Scanners
151
+
152
+ # @fn def general {{{
153
+ # @brief Returns information collected from the general system
154
+ #
155
+ # @return [OpenStruct] Returns openstruct with gathered information
156
+ def general
157
+ result = nil
158
+
159
+ begin
160
+ result = OpenStruct.new
161
+ result.broken = false
162
+
163
+ os = os_report
164
+
165
+ result.title = "System Information"
166
+ result.system = os.host
167
+ result.cpus = OS.cpu_count
168
+ result.architecture = OS.bits
169
+ result.current_user = `whoami`.chomp
170
+
171
+ rescue Exception => e
172
+ result = OpenStruct.new
173
+ result.broken = true
174
+
175
+ say "(EE) " + e.message, :red
176
+ end
177
+
178
+ return result
179
+ end # }}}
180
+
181
+ # @fn def project {{{
182
+ # @brief Print project related information to stdout
183
+ #
184
+ # @return [OpenStruct] Returns openstruct with gathered information
185
+ def project
186
+ result = nil
187
+
188
+ begin
189
+ result = OpenStruct.new
190
+ result.broken = false
191
+
192
+ result.title = "Project information"
193
+
194
+ result.current_directory = Dir.pwd
195
+ result.version = `git describe --tags` || "unknown"
196
+
197
+ rescue Exception => e
198
+ result = OpenStruct.new
199
+ result.broken = true
200
+
201
+ say "(EE) " + e.message, :red
202
+ end
203
+
204
+ return result
205
+ end # }}}
206
+
207
+ # @fn def ruby {{{
208
+ # @brief Prints ruby environment information to stdout
209
+ #
210
+ # @return [OpenStruct] Returns openstruct with gathered information
211
+ def ruby
212
+
213
+ result = nil
214
+
215
+ begin
216
+ result = OpenStruct.new
217
+ result.broken = false
218
+
219
+ result.title = 'Ruby Information'
220
+
221
+ commands = %w(ruby rvm rbenv rake gem)
222
+
223
+ commands.each do |command|
224
+ next unless( self.which( command ) )
225
+
226
+ result.send "#{command}=", self.version( command )
227
+ end
228
+
229
+ rescue Exception => e
230
+ result = OpenStruct.new
231
+ result.broken = true
232
+
233
+ say "(EE) " + e.message, :red
234
+ end
235
+
236
+ return result
237
+ end # }}}
238
+
239
+
240
+ ## Helpers
241
+
242
+ # @fn def os_report {{{
243
+ # @brief Get overview of the Operating System
244
+ #
245
+ # @return [OpenStruct] Returns a openstruct with various information, e.g.
246
+ # arch, target_os, target_vendor, target_cpu, target, host_os, host_vendor, host_cpu, host, RUBY_PLATFORM
247
+ def os_report
248
+ result = nil
249
+
250
+ begin
251
+ yaml = OS.report
252
+ hash = YAML.load( yaml )
253
+ result = hashes_to_ostruct( hash )
254
+ rescue Exception => e
255
+ $stderr.puts set_color "(EE) #{e.message}", :red
256
+ end
257
+
258
+ result
259
+ end # }}}
260
+
261
+ # @fn def hashes_to_ostruct object # {{{
262
+ # @brief This function turns a nested hash into a nested open struct
263
+ #
264
+ # @author Dave Dribin
265
+ # Reference: http://www.dribin.org/dave/blog/archives/2006/11/17/hashes_to_ostruct/
266
+ #
267
+ # @param [Object] object Value can either be of type Hash or Array, if other then it is returned and not changed
268
+ #
269
+ # @return [OStruct] Returns nested open structs
270
+ def hashes_to_ostruct object
271
+
272
+ return case object
273
+ when Hash
274
+ object = object.clone
275
+ object.each { |key, value| object[key] = hashes_to_ostruct(value) }
276
+ OpenStruct.new( object )
277
+ when Array
278
+ object = object.clone
279
+ object.map! { |i| hashes_to_ostruct(i) }
280
+ else
281
+ object
282
+ end
283
+
284
+ end # of def hashes_to_ostruct }}}
285
+
286
+ end # of no_tasks do
287
+
288
+ end # of Class Info
289
+
290
+
291
+ # vim:ts=2:tw=100:wm=100:syntax=ruby