Skip to content
Browse files

Colorizing cap output

  • Loading branch information...
1 parent 200b48b commit fb9050f75fa517fb336cc951d30f6df43961f947 @joelmoss committed
View
7 Capfile.repos
@@ -0,0 +1,7 @@
+require 'capistrano_colors'
+colorize [
+ { :match => /command finished/, :color => :hide, :prio => 10 },
+ { :match => /executing command/, :color => :blue, :prio => 10, :attribute => :underscore },
+ { :match => /^transaction: commit$/, :color => :magenta, :prio => 10, :attribute => :blink },
+ { :match => /git/, :color => :white, :prio => 20, :attribute => :reverse },
+]
View
2 Gemfile
@@ -21,6 +21,7 @@ gem 'faraday'
gem 'faraday-stack'
gem 'faraday_middleware'
gem 'capistrano', '~> 2.10.0.pre'
+gem 'capistrano_colors'
gem 'grit'
gem 'dotiw'
gem 'inherited_resources'
@@ -28,6 +29,7 @@ gem 'kaminari'
gem 'permanent_records'
gem 'simple_form', :git => 'https://github.com/plataformatec/simple_form.git'
gem 'open4'
+gem 'ansible'
gem 'airbrake', :require => nil
View
4 Gemfile.lock
@@ -40,6 +40,7 @@ GEM
airbrake (3.0.9)
activesupport
builder
+ ansible (0.2.0)
arel (3.0.0)
builder (3.0.0)
capistrano (2.10.0.pre)
@@ -48,6 +49,7 @@ GEM
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
+ capistrano_colors (0.5.5)
coffee-rails (3.2.1)
coffee-script (>= 2.2.0)
railties (~> 3.2.0.beta)
@@ -248,7 +250,9 @@ PLATFORMS
DEPENDENCIES
airbrake
+ ansible
capistrano (~> 2.10.0.pre)
+ capistrano_colors
coffee-rails (~> 3.2.1)
database_cleaner
dotiw
View
27 app/assets/stylesheets/custom.css.scss
@@ -79,6 +79,33 @@ footer {
}
+/* ANSI color conversions
+/* ---------------------------------------------------------------------------- */
+
+#task_results {
+ background-color: #000;
+ color: #FFF;
+
+ .ansible_1 { font-weight: bold; }
+ .ansible_4 { text-decoration: underline; }
+ .ansible_30 { color: black; }
+ .ansible_31 { color: red; }
+ .ansible_32 { color: limegreen; }
+ .ansible_33 { color: yellow;}
+ .ansible_34 { color: aqua;}
+ .ansible_35 { color: magenta;}
+ .ansible_36 { color: cyan;}
+ .ansible_37 { color: white;}
+ .ansible_90 { color: dimgray; }
+ .ansible_none { color: none; }
+
+ p {
+ line-height: 1em;
+ font-size: 12px;
+ }
+}
+
+
/* Icons
/* ---------------------------------------------------------------------------- */
View
17 app/models/job.rb
@@ -1,5 +1,6 @@
require 'kernel'
class Job < ActiveRecord::Base
+ include Ansible
belongs_to :project
belongs_to :user
@@ -16,13 +17,11 @@ def self.deleted
def run_task
status, stdout_output, stderr_output = nil, "", ""
- command = "bundle exec cap -f Capfile -Xx -l STDOUT #{stage} #{task}"
FileUtils.chdir project.repo.path do
- status = Open4::popen4 command do |pid, stdin, stdout, stderr|
+ status = Open4::popen4 full_command do |pid, stdin, stdout, stderr|
stdin.close
- stdout_output += "Running: '#{command}'...\n\n"
stdout_output += stdout.read.strip
stderr_output += stderr.read.strip
end
@@ -38,10 +37,22 @@ def run_task
def complete?
!completed_at.nil?
end
+
+ def command
+ "#{stage} #{task}"
+ end
+
+ def formatted_results
+ ansi_escaped results
+ end
private
+ def full_command
+ "bundle exec cap -f #{Rails.root.join('Capfile.repos')} -f Capfile -Xx -l STDOUT #{command}"
+ end
+
def execute_task
Resque.enqueue CapExecute, id
end
View
6 app/views/jobs/show.html.erb
@@ -1,5 +1,5 @@
<% title "Job ##{resource.id}" %>
-<% subtitle "task: #{resource.task}" %>
+<% subtitle "task: #{resource.task} by #{resource.user}" %>
<% breadcrumb "Projects", projects_path %>
<% breadcrumb parent, parent %>
@@ -20,8 +20,10 @@
<div class="tab-content">
<div class="tab-pane active" id="results">
+ <h3>Running '<%= resource.command.strip %>' ...</h3>
+
<%- if resource.complete? -%>
- <pre><%= resource.results %></pre>
+ <pre id="task_results"><%= raw simple_format(resource.formatted_results) %></pre>
<%- else -%>
<pre id="job-results" data-job_id="<%= resource.id %>" data-project_id="<%= parent.id %>"><%= image_tag("loading.gif", :size => "16x16") %></pre>
<%- end -%>
View
2 app/views/projects/_project.html.erb
@@ -4,7 +4,7 @@
<td><strong><%= link_to project, project %></strong></td>
<td>
<%- if last_run = project.jobs.first -%>
- <%= link_to last_run.task, [project, last_run] %>
+ <%= link_to last_run.task, [project, last_run] %> by <%= last_run.user %>
&nbsp;&nbsp;&nbsp;
<span class="quieter smaller"><%= time_ago_in_words last_run.created_at %> ago</span>
<%- else -%>
View
2 app/views/projects/show/_info.html.erb
@@ -27,7 +27,7 @@
<div class="span13">
<p>
<%- if last_run = resource.jobs.first -%>
- <%= link_to last_run.task, [resource, last_run] %>
+ <%= link_to last_run.task, [resource, last_run] %> by <%= last_run.user %>
&nbsp;&nbsp;&nbsp;
<span class="quieter small">
<%= time_ago_in_words last_run.created_at %> ago

0 comments on commit fb9050f

Please sign in to comment.
Something went wrong with that request. Please try again.