Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 9918e7f487
Fetching contributors…

Cannot retrieve contributors at this time

87 lines (73 sloc) 2.476 kb
require 'fileutils'
module Bludgeon
VERSION = '0.0.2'
DOWNLOAD_LOCATION = '/tmp/bludgeon-project'
LINES_PER_PAGE = 50 # TODO: calculate based on font-size
BLUDGEON_PAGES = 500 # TODO: is this accurate?
def self.calculate(*args)
project = Project.new(*args)
project.download
project.calculate
report(project)
end
def self.report(project)
puts ["== #{project.name} (#{project.url})",
" Pages: #{project.pages}",
"You " + (project.bludgeon? ? "could" : "could not") +
" bludgeon someone to death with a printout."].join("\n")
end
class Project
def initialize(*args)
@url = args.pop
@name = args.pop || extract_name(@url)
@type = if url =~ /^git:\/\// or url =~ /\.git$/
:git
elsif url =~ /^svn/ or url =~ /^http:\/\//
:svn
else
:gem
end
end
attr_reader :name, :url, :pages, :type
def calculate
# TODO: switch over to using pr
# last_file = ''
# `find #{DOWNLOAD_LOCATION} -type f | xargs pr | egrep "Page [0-9]+$"`.split("\n").each do |line|
# time, file, page = line.split(/\s+/)
# end
# @pages = page_counts.map{ |c| c[/Page (\d+)$/, 1].to_i }.inject(0){ |sum, x| sum + x }
line_counts = `find #{DOWNLOAD_LOCATION} -type f | xargs wc -l`.split "\n"
@lines = line_counts.pop.to_i # last line is total
@pages = @lines / LINES_PER_PAGE
end
def bludgeon?
self.pages >= BLUDGEON_PAGES
end
def download
puts "Downloading #{url}..."
system "rm -rf #{DOWNLOAD_LOCATION}"
send "download_#{@type}"
puts "...Done!"
end
def download_git
system "git clone --depth=1 #{@url} #{DOWNLOAD_LOCATION} > /dev/null" or
raise "Could not clone #{@url}"
system "rm -rf #{DOWNLOAD_LOCATION}/.git"
end
def download_svn
system "svn checkout #{@url} #{DOWNLOAD_LOCATION} > /dev/null" or
raise "Could not checkout #{@url}"
system "find #{DOWNLOAD_LOCATION} -type d -name .svn | xargs rm -rf"
end
def download_gem
Dir.mkdir DOWNLOAD_LOCATION
FileUtils.cd DOWNLOAD_LOCATION
system "gem fetch #{@name} && gem unpack #{@name}*.gem" or
raise "Could not fetch and unpack gem #{@name}"
system "rm #{@name}*.gem"
end
def extract_name(url)
url[/\/([^\/]*?)(\.git)?$/, 1] or url
end
end
end
Jump to Line
Something went wrong with that request. Please try again.