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.
13 14 15 16 |
# File 'lib/simp/rake/build/code.rb', line 13 def initialize(base_dir) init_member_vars(base_dir) define_tasks end |
Instance Method Details
#define_tasks ⇒ Object
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 |
# File 'lib/simp/rake/build/code.rb', line 18 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 = `git rev-parse --abbrev-ref HEAD`.chomp if cur_branch.empty? raise 'Error: Could not find branch ID!' end changed = 0 new = 0 removed = 0 cmd = 'git log --shortstat --reverse --pretty=oneline' if args.since cmd += " --since=#{args.since}" end if args.until cmd += " --until=#{args.until}" end `#{cmd}`.each_line do |line| next unless encode_line(line) =~ %r{(\d+) files changed, (\d+) insertions\(\+\), (\d+) del.*} changed += ::Regexp.last_match(1).to_i new += ::Regexp.last_match(2).to_i removed += ::Regexp.last_match(3).to_i end cmd = 'git submodule foreach git log --shortstat --reverse --pretty=oneline' if args.since cmd += " --since=#{args.since}" end if args.until cmd += " --until=#{args.until}" end `#{cmd}`.each_line do |line| next unless encode_line(line) =~ %r{(\d+) files changed, (\d+) insertions\(\+\), (\d+) del.*} changed += ::Regexp.last_match(1).to_i new += ::Regexp.last_match(2).to_i removed += ::Regexp.last_match(3).to_i 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 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 = {} 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 { |line| unless %r{^\s*$}.match?(encode_line(line)) loc['rake'] = loc['rake'] + 1 end }.close other_ext = [] Find.find(@src_dir) do |path| if (File.basename(path)[0] == '.') || path.include?('src/rsync') || (path[-3..] =~ %r{\.gz|pem|pub}) || path.include?('developers_guide/rdoc') Find.prune elsif FileTest.symlink?(path) || FileTest.directory?(path) next end ext = File.extname(path)[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| unless %r{^\s*$}.match?(encode_line(line)) loc[ext] = loc[ext] + 1 end end end puts 'Code Count Report:' printf " %-6s %6s\n", 'Ext', 'Count' # rubocop:disable Style/FormatStringToken puts " #{'-' * 13}" total_loc = 0 loc.sort.each do |key, val| printf " %-6s %6d\n", key, val total_loc += val end puts " #{'-' * 13}" printf " %-6s %6d\n", 'Total', total_loc.to_s 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 end |