bp 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +11 -0
- data/.gitignore +41 -0
- data/Gemfile +4 -0
- data/README.markdown +37 -0
- data/Rakefile +42 -0
- data/bin/bp +9 -0
- data/bp.gemspec +34 -0
- data/lib/bp.rb +50 -0
- data/lib/bp/cm1.rb +13 -0
- data/lib/bp/emitter.rb +57 -0
- data/lib/bp/gem.rb +28 -0
- data/lib/bp/github.rb +81 -0
- data/lib/bp/heroku.rb +34 -0
- data/lib/bp/hootroot.rb +18 -0
- data/lib/bp/main.rb +81 -0
- data/lib/bp/script.rb +11 -0
- data/lib/bp/templates/emitter/base.rb.tt +9 -0
- data/lib/bp/templates/emitter/characterization.rb.tt +11 -0
- data/lib/bp/templates/emitter/data.rb.tt +15 -0
- data/lib/bp/templates/emitter/impact_model.rb.tt +52 -0
- data/lib/bp/templates/emitter/relationships.rb.tt +9 -0
- data/lib/bp/templates/emitter/summarization.rb.tt +24 -0
- data/lib/bp/version.rb +3 -0
- data/spec/bpdev_spec.rb +7 -0
- data/spec/spec_helper.rb +19 -0
- metadata +195 -0
data/.document
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# .document is used by rdoc and yard to know how to generate documentation
|
2
|
+
# for example, it can be used to control how rdoc gets built when you do `gem install foo`
|
3
|
+
|
4
|
+
README.rdoc
|
5
|
+
lib/**/*.rb
|
6
|
+
bin/*
|
7
|
+
|
8
|
+
# Files below this - are treated as 'extra files', and aren't parsed for ruby code
|
9
|
+
-
|
10
|
+
features/**/*.feature
|
11
|
+
LICENSE
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
*.gem
|
2
|
+
.bundle
|
3
|
+
Gemfile.lock
|
4
|
+
pkg/*
|
5
|
+
*~
|
6
|
+
# rcov generated
|
7
|
+
coverage
|
8
|
+
|
9
|
+
# rdoc generated
|
10
|
+
rdoc
|
11
|
+
|
12
|
+
# yard generated
|
13
|
+
doc
|
14
|
+
.yardoc
|
15
|
+
|
16
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
17
|
+
#
|
18
|
+
# * Create a file at ~/.gitignore
|
19
|
+
# * Include files you want ignored
|
20
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
21
|
+
#
|
22
|
+
# After doing this, these files will be ignored in all your git projects,
|
23
|
+
# saving you from having to 'pollute' every project you touch with them
|
24
|
+
#
|
25
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
26
|
+
#
|
27
|
+
# For MacOS:
|
28
|
+
#
|
29
|
+
#.DS_Store
|
30
|
+
#
|
31
|
+
# For TextMate
|
32
|
+
#*.tmproj
|
33
|
+
#tmtags
|
34
|
+
#
|
35
|
+
# For emacs:
|
36
|
+
#*~
|
37
|
+
#\#*
|
38
|
+
#.\#*
|
39
|
+
#
|
40
|
+
# For vim:
|
41
|
+
#*.swp
|
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# bp
|
2
|
+
|
3
|
+
Develop stuff
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
> git clone git@github.com:brighterplanet/bp.git
|
8
|
+
> cd bp
|
9
|
+
> gem build bp.gemspec
|
10
|
+
> gem install ./
|
11
|
+
|
12
|
+
> echo "github username" > ~/.bprc
|
13
|
+
> echo "github password" >> ~/.bprc
|
14
|
+
|
15
|
+
## Use
|
16
|
+
|
17
|
+
`bp help` lists all available commands.
|
18
|
+
|
19
|
+
`bp emitter:create dirigible` will create a new emitter gem, called Dirigible, in `./dirigible`.
|
20
|
+
|
21
|
+
`bp emitter:ls` will list all emitters. Usable with other unix commands (see xargs) for scripting git/gem tasks.
|
22
|
+
|
23
|
+
`bp gem:ls` lists all BP non-emitter gems.
|
24
|
+
|
25
|
+
`bp gem:set_owners GEM_NAME` will add the default set of owners (Andy, Seamus, Ian, Derek) to the gem on rubygems.org.
|
26
|
+
|
27
|
+
`bp github:create_repo dirigible` will create a dirigible repo for the brighterplanet organization (tyvm).
|
28
|
+
|
29
|
+
`bp github:configure_hooks dirigible` will set up default hooks (campfire, travis-ci) for the repo.
|
30
|
+
|
31
|
+
`bp heroku:apps` lists all heroku-hosted apps.
|
32
|
+
|
33
|
+
`bp heroku:hooks APP_NAME` sets up deploy hooks (campfire, email) for the specified app.
|
34
|
+
|
35
|
+
`bp hootroot:server` runs the hootroot server (must in hootroot project directory) with all needed environment variables set for Hopstop, etc.
|
36
|
+
|
37
|
+
`bp script:run FILE` runs a ruby script that has access to information (list of apps, etc.) contained in the BP gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError
|
6
|
+
$stderr.puts "You must install bundler - run `gem install bundler`"
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
Bundler.setup
|
11
|
+
rescue Bundler::BundlerError => e
|
12
|
+
$stderr.puts e.message
|
13
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
14
|
+
exit e.status_code
|
15
|
+
end
|
16
|
+
require 'rake'
|
17
|
+
|
18
|
+
require 'bueller'
|
19
|
+
Bueller::Tasks.new
|
20
|
+
|
21
|
+
require 'rspec/core/rake_task'
|
22
|
+
RSpec::Core::RakeTask.new(:examples) do |examples|
|
23
|
+
examples.rspec_opts = '-Ispec'
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
27
|
+
spec.rspec_opts = '-Ispec'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default => :examples
|
32
|
+
|
33
|
+
require 'rake/rdoctask'
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
35
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
36
|
+
|
37
|
+
rdoc.main = 'README.rdoc'
|
38
|
+
rdoc.rdoc_dir = 'rdoc'
|
39
|
+
rdoc.title = "bpdev #{version}"
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
data/bin/bp
ADDED
data/bp.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'bp/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'bp'
|
6
|
+
s.version = BP::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.date = '2011-12-13'
|
9
|
+
s.authors = ['Derek Kastner']
|
10
|
+
s.email = 'dkastner@gmail.com'
|
11
|
+
s.homepage = 'http://github.com/brighterplanet/bp'
|
12
|
+
s.summary = %Q{Build stuff for Brighter Planet}
|
13
|
+
s.description = %Q{Tools for building gems and such}
|
14
|
+
s.extra_rdoc_files = %w{README.markdown}
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_dependency 'active_support'
|
22
|
+
s.add_dependency 'gems'
|
23
|
+
s.add_dependency 'github_api', '~> 0.5.2'
|
24
|
+
s.add_dependency 'grit'
|
25
|
+
s.add_dependency 'heroku'
|
26
|
+
s.add_dependency 'httparty'
|
27
|
+
s.add_dependency 'thor'
|
28
|
+
|
29
|
+
s.add_development_dependency 'rspec'
|
30
|
+
s.add_development_dependency 'bundler'
|
31
|
+
s.add_development_dependency 'bueller'
|
32
|
+
s.add_development_dependency 'rake'
|
33
|
+
end
|
34
|
+
|
data/lib/bp.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module BP
|
2
|
+
extend self
|
3
|
+
|
4
|
+
CAMPFIRE_TOKEN = '0fcaae1c3c126c9e9aa96ccee5e604045704a196'
|
5
|
+
TRAVIS_CI_TOKEN = 'JQd4gdfRIe1efxV1MywDYFULY12ESnkpO8tNp5uzEgFaZV9iti5bDEMz'
|
6
|
+
|
7
|
+
STAFF = {
|
8
|
+
:andy => {
|
9
|
+
:rubygems => 'gemcutter@rossmeissl.net',
|
10
|
+
:github => 'rossmeissl'
|
11
|
+
},
|
12
|
+
:derek => {
|
13
|
+
:rubygems => 'dkastner@gmail.com',
|
14
|
+
:github => 'dkastner'
|
15
|
+
},
|
16
|
+
:ian => {
|
17
|
+
:rubygems => 'ijhough@gmail.com',
|
18
|
+
:github => 'ihough'
|
19
|
+
},
|
20
|
+
:seamus => {
|
21
|
+
:rubygems => 'seamus@abshere.net',
|
22
|
+
:github => 'seamusabshere'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
GEMS = %w{carbon charisma data_miner earth loose_tight_dictionary sniff}
|
27
|
+
|
28
|
+
APPS = %w{app1 cm1-rack concur1 data1 dnb1 keyring1 mastercard1 priceline1 root1 status3 zillow1}
|
29
|
+
|
30
|
+
require 'bp/emitter'
|
31
|
+
require 'bp/gem'
|
32
|
+
require 'bp/github'
|
33
|
+
require 'bp/heroku'
|
34
|
+
require 'bp/hootroot'
|
35
|
+
require 'bp/script'
|
36
|
+
require 'bp/version'
|
37
|
+
|
38
|
+
def github_repo_name
|
39
|
+
@origin_url ||= git_remote('origin')
|
40
|
+
File.basename(@origin_url, '.git')
|
41
|
+
end
|
42
|
+
def heroku_repo_name
|
43
|
+
@heroku_url ||= git_remote('heroku')
|
44
|
+
File.basename(@heroku_url, '.git')
|
45
|
+
end
|
46
|
+
|
47
|
+
def git_remote(name)
|
48
|
+
`git remote show #{name} | awk {'print $3'}`.lines.to_a[2].chomp.sub(/.*:/,'')
|
49
|
+
end
|
50
|
+
end
|
data/lib/bp/cm1.rb
ADDED
data/lib/bp/emitter.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
require 'bp/cm1'
|
5
|
+
require 'bp/github'
|
6
|
+
|
7
|
+
module BP
|
8
|
+
class Emitter < Thor
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
namespace :emitter
|
12
|
+
source_root File.expand_path('../templates/emitter', __FILE__)
|
13
|
+
|
14
|
+
desc 'create EMITTER_NAME', 'Create a new emitter gem'
|
15
|
+
def create(name)
|
16
|
+
@name = name # need this for ERB template context
|
17
|
+
github = BP::Github.new
|
18
|
+
|
19
|
+
github.create_repo underscored_name
|
20
|
+
|
21
|
+
puts 'Creating gem'
|
22
|
+
`bueller #{name} --git-remote git@github.com:brighterplanet/#{underscored_name}.git`
|
23
|
+
|
24
|
+
emitter_path = File.join(Dir.pwd, underscored_name)
|
25
|
+
lib_path = File.join(emitter_path, 'lib')
|
26
|
+
|
27
|
+
template 'base.rb.tt',
|
28
|
+
File.join(lib_path, underscored_name + '.rb'),
|
29
|
+
:force => true
|
30
|
+
%w{characterization.rb.tt data.rb.tt impact_model.rb.tt relationships.rb.tt summarization.rb.tt}.each do |file|
|
31
|
+
template file,
|
32
|
+
File.join(lib_path, underscored_name, File.basename(file, '.tt'))
|
33
|
+
end
|
34
|
+
|
35
|
+
empty_directory File.join(Dir.pwd, 'log')
|
36
|
+
create_file File.join(Dir.pwd, 'log', '.gitkeep')
|
37
|
+
|
38
|
+
Dir.chdir emitter_path do
|
39
|
+
puts `git add .`
|
40
|
+
puts `git add log/.gitkeep`
|
41
|
+
puts `git commit -m "#{name} skeleton"`
|
42
|
+
end
|
43
|
+
|
44
|
+
github.configure_hooks underscored_name
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'ls', 'List all the emitters'
|
48
|
+
def ls
|
49
|
+
puts Cm1.emitters.map(&:underscore).join("\n")
|
50
|
+
end
|
51
|
+
map 'list' => :ls
|
52
|
+
|
53
|
+
private
|
54
|
+
def underscored_name; @name.underscore; end
|
55
|
+
def emitter_constant; @name.camelize; end
|
56
|
+
end
|
57
|
+
end
|
data/lib/bp/gem.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
require 'thor'
|
3
|
+
require 'gems'
|
4
|
+
|
5
|
+
module BP
|
6
|
+
class Gem < Thor
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
namespace :gem
|
10
|
+
source_root File.expand_path('../templates/emitter', __FILE__)
|
11
|
+
|
12
|
+
desc 'set_owners GEM_NAME', 'Set default owners for gem'
|
13
|
+
def set_owners(name)
|
14
|
+
puts "Setting owners for #{name}"
|
15
|
+
gems = Gems::Client.new
|
16
|
+
STAFF.each do |staff, accounts|
|
17
|
+
puts "* #{accounts[:rubygems]}"
|
18
|
+
gems.add_owner name, accounts[:rubygems]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'ls', 'List all the BP gems'
|
23
|
+
def ls
|
24
|
+
puts GEMS.join "\n"
|
25
|
+
end
|
26
|
+
map 'list' => :ls
|
27
|
+
end
|
28
|
+
end
|
data/lib/bp/github.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'github_api'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module BP
|
5
|
+
class Github < Thor
|
6
|
+
namespace :github
|
7
|
+
|
8
|
+
HOOKS = {
|
9
|
+
'campfire' => {
|
10
|
+
:events => %w{push issues issue_comment commit_comment pull_request watch fork fork_apply},
|
11
|
+
:config => {
|
12
|
+
:subdomain => 'fingertips', :room => 'Brighter Planet',
|
13
|
+
:token => CAMPFIRE_TOKEN, :play_sound => 1,
|
14
|
+
}
|
15
|
+
},
|
16
|
+
# 'travis_ci' => {
|
17
|
+
# :events => %w{push},
|
18
|
+
# :config => {
|
19
|
+
# :domain => 'travis-ci.org',
|
20
|
+
# :token => TRAVIS_CI_TOKEN
|
21
|
+
# }
|
22
|
+
# }
|
23
|
+
}
|
24
|
+
|
25
|
+
desc 'create_repo REPO_NAME', 'Create a new github repo for user brighterplanet with the given name'
|
26
|
+
method_options %w{private -p} => :boolean
|
27
|
+
method_options %w{account -a} => :string
|
28
|
+
def create_repo(repo)
|
29
|
+
account = options[:account] || 'brighterplanet'
|
30
|
+
say "Creating repository #{repo} on GitHub"
|
31
|
+
github.repos.create_repo :name => repo, :org => account, :public => !options[:private]
|
32
|
+
say 'Done!'
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'configure_hooks REPO_NAME', 'Configure hooks for the repo (e.g. Campfire notifications)'
|
36
|
+
method_options %w{account -a} => :string
|
37
|
+
def configure_hooks(repo_name = nil)
|
38
|
+
account = options[:account] || 'brighterplanet'
|
39
|
+
repo_name ||= BP.github_repo_name
|
40
|
+
say "Configuring hooks for #{account}/#{repo_name}"
|
41
|
+
|
42
|
+
HOOKS.each do |hook_name, hook_data|
|
43
|
+
config = hook_data[:config]
|
44
|
+
config.merge!(:user => account) if hook_name == 'travis_ci'
|
45
|
+
puts "Creating #{hook_name} hook"
|
46
|
+
github.repos.hooks.create account, repo_name,
|
47
|
+
:name => hook_name, :active => true,
|
48
|
+
:events => hook_data[:events],
|
49
|
+
:config => config
|
50
|
+
end
|
51
|
+
say 'Done!'
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'reset_hooks REPO_NAME', 'Reset hooks for the repo to default settings'
|
55
|
+
method_options %w{account -a} => :string
|
56
|
+
def reset_hooks(repo_name = nil)
|
57
|
+
account = options[:account] || 'brighterplanet'
|
58
|
+
repo_name ||= BP.github_repo_name
|
59
|
+
say "Resetting hooks for #{account}/#{repo_name}"
|
60
|
+
|
61
|
+
HOOKS.each do |hook_name, hook_data|
|
62
|
+
config = hook_data[:config]
|
63
|
+
config.merge!(:user => account) if hook_name == 'travis_ci'
|
64
|
+
github.repos.hooks.all(account, repo_name).each do |hook|
|
65
|
+
github.repos.hooks.delete account, repo_name, hook['id']
|
66
|
+
end
|
67
|
+
end
|
68
|
+
say 'Done!'
|
69
|
+
configure_hooks repo_name
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def credentials
|
74
|
+
@credentials ||= File.read("#{ENV['HOME']}/.bprc").split(/\n/)
|
75
|
+
end
|
76
|
+
|
77
|
+
def github
|
78
|
+
@github ||= ::Github.new :login => credentials.first, :password => credentials.last
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/bp/heroku.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module BP
|
2
|
+
class Heroku < Thor
|
3
|
+
include Thor::Actions
|
4
|
+
namespace :heroku
|
5
|
+
|
6
|
+
desc 'config', 'Export config in local env'
|
7
|
+
def config
|
8
|
+
lines = `heroku config`.split(/\n/)
|
9
|
+
output = lines.reject do |l|
|
10
|
+
name = l.split(/\s/).first
|
11
|
+
name =~ /DEPLOYHOOK/ || name !~ /[A-Z]/ || %w{
|
12
|
+
DATABASE_URL GEM_PATH LANG PATH RACK_ENV RAILS_ENV
|
13
|
+
SHARED_DATABASE_URL
|
14
|
+
}.include?(name)
|
15
|
+
end.map do |l|
|
16
|
+
'export ' + l.sub(/\s*=>\s*/,'=')
|
17
|
+
end
|
18
|
+
puts output
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'hooks', 'Set up deploy hooks for an app (see `heroku list`)'
|
22
|
+
def hooks(app = nil)
|
23
|
+
app ||= BP.heroku_repo_name
|
24
|
+
|
25
|
+
run "heroku addons:remove deployhooks:email --app #{app} --confirm #{app}"
|
26
|
+
run %{heroku addons:add deployhooks:email recipient=deploy-list@brighterplanet.com subject="{{user}} deployed #{app} at {{head}}" body="{{user}} deployed #{app} at {{head}}\n\n{{git_log}}" --app #{app} --confirm #{app}}
|
27
|
+
run "heroku addons:remove deployhooks:campfire --app #{app} --confirm #{app}"
|
28
|
+
run %{heroku addons:add deployhooks:campfire url=fingertips ssl=1 api_key=#{CAMPFIRE_TOKEN} room="Brighter Planet" message="{{user}} deployed #{app} at {{head}}" --app #{app} --confirm #{app}}
|
29
|
+
run "heroku addons:remove deployhooks:http --app #{app} --confirm #{app}"
|
30
|
+
run "heroku addons:add deployhooks:http url=http://impact.brighterplanet.com/flush --app #{app} --confirm #{app}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/lib/bp/hootroot.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module BP
|
2
|
+
class Hootroot < Thor
|
3
|
+
include Thor::Actions
|
4
|
+
namespace :hootroot
|
5
|
+
|
6
|
+
LICENSE_KEY = 'c34pg2jxiyukluka'
|
7
|
+
SESSION_SECRET = '2a231132d739c87cad2aa2c7c669e9d8865d7f5e088693c603a5cb4980e75ceebff950d98cbb307f5504d4f9a1cb4b0b46b8596a5a353a0bdec18cf70103ba6d'
|
8
|
+
HOPTOAD_KEY = '32584c58d01ba76c204e708631b911e4'
|
9
|
+
|
10
|
+
desc 'server', 'Run hootroot locally with env set'
|
11
|
+
def server
|
12
|
+
ENV['LICENSE_KEY'] = LICENSE_KEY
|
13
|
+
ENV['SESSION_SECRET'] = SESSION_SECRET
|
14
|
+
ENV['HOPTOAD_KEY'] = HOPTOAD_KEY
|
15
|
+
exec "rails s"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/bp/main.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
require 'thor/util'
|
4
|
+
|
5
|
+
module BP
|
6
|
+
class Main < Thor
|
7
|
+
# If a task is not found on BP::Main, method missing is invoked and
|
8
|
+
# BP::Main is then responsable for finding the task in all classes.
|
9
|
+
#
|
10
|
+
def method_missing(meth, *args)
|
11
|
+
meth = meth.to_s
|
12
|
+
klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
|
13
|
+
self.class.handle_no_task_error(task, false) if klass.nil?
|
14
|
+
args.unshift(task) if task
|
15
|
+
klass.start(args, :shell => self.shell)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "help [COMMAND]", "List the available bp tasks (--substring means .*SEARCH)"
|
19
|
+
method_options :substring => :boolean, :group => :string, :all => :boolean, :debug => :boolean
|
20
|
+
def help(search="")
|
21
|
+
if search == ''
|
22
|
+
print_table({ 'bp help COMMAND' => 'Print help for a command' } , :truncate => true)
|
23
|
+
say
|
24
|
+
end
|
25
|
+
|
26
|
+
search = ".*#{search}" if options["substring"]
|
27
|
+
search = /^#{search}.*/i
|
28
|
+
group = options[:group] || "standard"
|
29
|
+
|
30
|
+
klasses = Thor::Base.subclasses.select do |k|
|
31
|
+
(options[:all] || k.group == group) && k.namespace =~ search
|
32
|
+
end
|
33
|
+
|
34
|
+
display_klasses(klasses)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.banner(task, all = false, subcommand = false)
|
40
|
+
"bp " + task.formatted_usage(self, all, subcommand)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.exit_on_failure?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
# Display information about the given klasses. If with_module is given,
|
48
|
+
# it shows a table with information extracted from the yaml file.
|
49
|
+
#
|
50
|
+
def display_klasses(klasses = Thor::Base.subclasses)
|
51
|
+
klasses -= [Thor, BP::Main, Thor::Group]
|
52
|
+
|
53
|
+
raise Error, "No Thor tasks available" if klasses.empty?
|
54
|
+
|
55
|
+
list = Hash.new { |h,k| h[k] = [] }
|
56
|
+
groups = klasses.select { |k| k.ancestors.include?(Thor::Group) }
|
57
|
+
|
58
|
+
# Get classes which inherit from Thor
|
59
|
+
(klasses - groups).each { |k| list[k.namespace.split(":").first] += k.printable_tasks(false) }
|
60
|
+
|
61
|
+
# Get classes which inherit from Thor::Base
|
62
|
+
groups.map! { |k| k.printable_tasks(false).first }
|
63
|
+
list["root"] = groups
|
64
|
+
|
65
|
+
# Order namespaces with default coming first
|
66
|
+
list = list.sort{ |a,b| a[0].sub(/^default/, '') <=> b[0].sub(/^default/, '') }
|
67
|
+
list.each { |n, tasks| display_tasks(n, tasks) unless tasks.empty? }
|
68
|
+
end
|
69
|
+
|
70
|
+
def display_tasks(namespace, list) #:nodoc:
|
71
|
+
list.sort!{ |a,b| a[0] <=> b[0] }
|
72
|
+
|
73
|
+
list = list.inject({}) do |hsh, (k, v)|
|
74
|
+
hsh["bp #{namespace}:#{k.sub(/bp /,'')}"] = v
|
75
|
+
hsh
|
76
|
+
end
|
77
|
+
print_table(list, :truncate => true)
|
78
|
+
say
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/bp/script.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'emitter'
|
2
|
+
|
3
|
+
module BrighterPlanet
|
4
|
+
module <%= emitter_constant %>
|
5
|
+
extend BrighterPlanet::Emitter
|
6
|
+
# FIXME TODO each impact should have its own scope; this is the scope of the greenhouse gas emission (carbon) impact
|
7
|
+
scope 'The <%= emitter_constant.humanize %> greenhouse gas emission is the anthropogenic greenhouse gas emissions attributed to TODO'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright <%= Time.now.year %> Brighter Planet.
|
2
|
+
# See LICENSE for details.
|
3
|
+
# Contact Brighter Planet for dual-license arrangements.
|
4
|
+
|
5
|
+
## <%= emitter_constant.humanize %> impact model
|
6
|
+
# This model is used by the [Brighter Planet](http://brighterplanet.com) [CM1 web service](http://impact.brighterplanet.com) to calculate the TODO, such as energy use and greenhouse gas emissions.
|
7
|
+
|
8
|
+
##### Timeframe
|
9
|
+
# The model calculates impacts that occured during a particular time period (`timeframe`).
|
10
|
+
# For example if the `timeframe` is February 2010, a <%= emitter_constant %> that occurred (`date`) on February 15, 2010 will have impacts, but a <%= emitter_constant %> that occurred on January 31, 2010 will have zero impacts.
|
11
|
+
#
|
12
|
+
# The default `timeframe` is the current calendar year.
|
13
|
+
|
14
|
+
##### Calculations
|
15
|
+
# The final impacts are the result of the calculations below. These are performed in reverse order, starting with the last calculation listed and finishing with the greenhouse gas emissions calculation.
|
16
|
+
#
|
17
|
+
# Each calculation listing shows:
|
18
|
+
#
|
19
|
+
# * value returned (*units of measurement*)
|
20
|
+
# * description of the value
|
21
|
+
# * calculation methods, listed from most to least preferred
|
22
|
+
#
|
23
|
+
# Some methods use `values` returned by prior calculations. If any of these `values` are unknown the method is skipped.
|
24
|
+
# If all the methods for a calculation are skipped, the value the calculation would return is unknown.
|
25
|
+
|
26
|
+
##### Standard compliance
|
27
|
+
# When compliance with a particular standard is requested, all methods that do not comply with that standard are ignored.
|
28
|
+
# Thus any `values` a method needs will have been calculated using a compliant method or will be unknown.
|
29
|
+
# To see which standards a method complies with, look at the `:complies =>` section of the code in the right column.
|
30
|
+
#
|
31
|
+
# Client input complies with all standards.
|
32
|
+
|
33
|
+
##### Collaboration
|
34
|
+
# Contributions to this impact model are actively encouraged and warmly welcomed. This library includes a comprehensive test suite to ensure that your changes do not cause regressions. All changes should include test coverage for new functionality. Please see [sniff](https://github.com/brighterplanet/sniff#readme), our emitter testing framework, for more information.
|
35
|
+
|
36
|
+
module BrighterPlanet
|
37
|
+
module <%= emitter_constant %>
|
38
|
+
module ImpactModel
|
39
|
+
def self.included(base)
|
40
|
+
base.decide :impact, :with => :characteristics do
|
41
|
+
# * * *
|
42
|
+
|
43
|
+
#### Carbon (*kg CO<sub>2</sub>e*)
|
44
|
+
# *The greenhouse emissions during `timeframe`.*
|
45
|
+
committee :carbon do
|
46
|
+
# TODO
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'summary_judgement'
|
2
|
+
|
3
|
+
module BrighterPlanet
|
4
|
+
module <%= emitter_constant %>
|
5
|
+
module Summarization
|
6
|
+
def self.included(base)
|
7
|
+
base.extend SummaryJudgement
|
8
|
+
base.summarize do |has|
|
9
|
+
# TODO
|
10
|
+
# has.adjective 'one-way', :if => lambda { |flight| flight.trips == 1 }
|
11
|
+
# has.adjective 'round-trip', :if => lambda { |flight| flight.trips == 2 }
|
12
|
+
# has.adjective 'nonstop', :if => lambda { |flight| flight.segments_per_trip == 1 }
|
13
|
+
# has.identity 'flight'
|
14
|
+
# has.modifier lambda { |flight| "from #{flight.origin_airport.name}" }, :if => :origin_airport
|
15
|
+
# has.modifier lambda { |flight| "to #{flight.destination_airport.name}" }, :if => :destination_airport
|
16
|
+
# has.modifier lambda { |flight| "on a #{flight.vehicle}" }, :if => :vehicle
|
17
|
+
# has.modifier lambda { |flight| "on #{flight.date.to_formatted_s(:archive)}"}, :if => :date
|
18
|
+
# has.verb :take
|
19
|
+
# has.aspect :perfect
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/bp/version.rb
ADDED
data/spec/bpdev_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
begin
|
3
|
+
Bundler.setup
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
7
|
+
exit e.status_code
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rspec'
|
11
|
+
require 'bpdev'
|
12
|
+
|
13
|
+
# Requires supporting files with custom matchers and macros, etc,
|
14
|
+
# in ./support/ and its subdirectories.
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Derek Kastner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-13 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active_support
|
16
|
+
requirement: &2165610460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2165610460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: gems
|
27
|
+
requirement: &2165610000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2165610000
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: github_api
|
38
|
+
requirement: &2165609460 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.5.2
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2165609460
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: grit
|
49
|
+
requirement: &2165609020 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2165609020
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: heroku
|
60
|
+
requirement: &2165608520 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2165608520
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: &2165608080 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2165608080
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: thor
|
82
|
+
requirement: &2165607620 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2165607620
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec
|
93
|
+
requirement: &2165607180 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2165607180
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: bundler
|
104
|
+
requirement: &2165606720 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *2165606720
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: bueller
|
115
|
+
requirement: &2165606280 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *2165606280
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: rake
|
126
|
+
requirement: &2165605820 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *2165605820
|
135
|
+
description: Tools for building gems and such
|
136
|
+
email: dkastner@gmail.com
|
137
|
+
executables:
|
138
|
+
- bp
|
139
|
+
extensions: []
|
140
|
+
extra_rdoc_files:
|
141
|
+
- README.markdown
|
142
|
+
files:
|
143
|
+
- .document
|
144
|
+
- .gitignore
|
145
|
+
- Gemfile
|
146
|
+
- README.markdown
|
147
|
+
- Rakefile
|
148
|
+
- bin/bp
|
149
|
+
- bp.gemspec
|
150
|
+
- lib/bp.rb
|
151
|
+
- lib/bp/cm1.rb
|
152
|
+
- lib/bp/emitter.rb
|
153
|
+
- lib/bp/gem.rb
|
154
|
+
- lib/bp/github.rb
|
155
|
+
- lib/bp/heroku.rb
|
156
|
+
- lib/bp/hootroot.rb
|
157
|
+
- lib/bp/main.rb
|
158
|
+
- lib/bp/script.rb
|
159
|
+
- lib/bp/templates/emitter/base.rb.tt
|
160
|
+
- lib/bp/templates/emitter/characterization.rb.tt
|
161
|
+
- lib/bp/templates/emitter/data.rb.tt
|
162
|
+
- lib/bp/templates/emitter/impact_model.rb.tt
|
163
|
+
- lib/bp/templates/emitter/relationships.rb.tt
|
164
|
+
- lib/bp/templates/emitter/summarization.rb.tt
|
165
|
+
- lib/bp/version.rb
|
166
|
+
- spec/bpdev_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
homepage: http://github.com/brighterplanet/bp
|
169
|
+
licenses: []
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ! '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 1.8.11
|
189
|
+
signing_key:
|
190
|
+
specification_version: 3
|
191
|
+
summary: Build stuff for Brighter Planet
|
192
|
+
test_files:
|
193
|
+
- spec/bpdev_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
has_rdoc:
|