Class: Simp::Rake::Build::Code
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Simp::Rake::Build::Code
- Includes:
- Simp::Rake, Constants
- Defined in:
- lib/simp/rake/build/code.rb
Instance Attribute Summary
Attributes included from Simp::Rake
Instance Method Summary collapse
- #define_tasks ⇒ Object
-
#initialize(base_dir) ⇒ Code
constructor
A new instance of Code.
Methods included from Constants
#distro_build_dir, #init_member_vars
Methods included from Simp::Rake
#clean_yaml, #encode_line, #get_cpu_limit, #help, #load_puppetfile, #run_pager
Methods included from CommandUtils
Constructor Details
#initialize(base_dir) ⇒ Code
Returns a new instance of Code.
12 13 14 15 |
# File 'lib/simp/rake/build/code.rb', line 12 def initialize( base_dir ) init_member_vars( base_dir ) define_tasks end |
Instance Method Details
#define_tasks ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/simp/rake/build/code.rb', line 17 def define_tasks namespace :code do desc "Show some basic stats. Uses git to figure out what has changed. * :since - Do not include any stats before this date. * :until - Do not include any stats after this date." task :stats,[:since,:until] do |t,args| cur_branch = %x{git rev-parse --abbrev-ref HEAD}.chomp if cur_branch.empty? fail "Error: Could not find branch ID!" end changed = 0 new = 0 removed = 0 cmd = "git log --shortstat --reverse --pretty=oneline" if args.since cmd = cmd + " --since=#{args.since}" end if args.until cmd = cmd + " --until=#{args.until}" end %x{#{cmd}}.each_line do |line| if encode_line(line) =~ /(\d+) files changed, (\d+) insertions\(\+\), (\d+) del.*/ changed = changed + $1.to_i new = new + $2.to_i removed = removed + $3.to_i end end cmd = "git submodule foreach git log --shortstat --reverse --pretty=oneline" if args.since cmd = cmd + " --since=#{args.since}" end if args.until cmd = cmd + " --until=#{args.until}" end %x{#{cmd}}.each_line do |line| if encode_line(line) =~ /(\d+) files changed, (\d+) insertions\(\+\), (\d+) del.*/ changed = changed + $1.to_i new = new + $2.to_i removed = removed + $3.to_i end end puts "Code Stats for #{cur_branch}:" printf " Files Changed: %6d\n", changed printf " New Lines: %6d\n", new printf " Removed Lines: %6d\n", removed end # End of :stats task. desc "Show line count. Prints a report of the lines of code in the source. * :show_unknown - Flag for displaying any file extensions not expected." task :count,[:show_unknown] do |t,args| require 'find' loc = Hash.new loc["rake"] = 0 loc["pp"] = 0 loc["rb"] = 0 loc["erb"] = 0 loc["sh"] = 0 loc["csh"] = 0 loc["html"] = 0 loc["spec"] = 0 loc["other"] = 0 File.open("#{@base_dir}/Rakefile","r").each do |line| if encode_line(line) !~ /^\s*$/ loc["rake"] = loc["rake"] + 1 end end.close other_ext = Array.new Find.find(@src_dir) do |path| if ( ( File.basename(path)[0] == ?. ) or ( path =~ /src\/rsync/ ) or ( path[-3..-1] =~ /\.gz|pem|pub/ ) or ( path =~ /developers_guide\/rdoc/ ) ) Find.prune else next if FileTest.symlink?(path) or FileTest.directory?(path) end ext = File.extname(path)[1..-1] ext ||= 'none' unless loc[ext] other_ext.push(ext) unless other_ext.include?(ext) ext = 'other' end File.open(path,'r').each do |line| if encode_line(line) !~ /^\s*$/ loc[ext] = loc[ext] + 1 end end end puts "Code Count Report:" printf " %-6s %6s\n", "Ext", "Count" puts " " + ("-" * 13) total_loc = 0 loc.sort.each do |key,val| printf " %-6s %6d\n", key, val total_loc = total_loc + val end puts " " + ("-" * 13) printf " %-6s %6d\n", "Total", "#{total_loc}" puts puts "Unknown Extension Count: #{other_ext.length}" if args.show_unknown puts "Unknown Extensions:" other_ext.sort.each do |ext| puts " #{ext}" end end end # End of :count task. end # End of :code namespace. end |