Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 4c30485bae7ea04ceb7f3ccbfb767f31a9fb4f83 @dj2 committed Jun 5, 2009
Showing with 5,829 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 README
  3. +4 −0 Rakefile
  4. +8 −0 config/build.yml
  5. +156 −0 lib/application.rb
  6. +26 −0 lib/menu.rb
  7. +28 −0 lib/preferences.rb
  8. BIN resources/HotCocoa.icns
  9. +277 −0 vendor/amazon-ec2-0.3.8/CHANGELOG
  10. +66 −0 vendor/amazon-ec2-0.3.8/LICENSE
  11. +322 −0 vendor/amazon-ec2-0.3.8/README.rdoc
  12. +37 −0 vendor/amazon-ec2-0.3.8/Rakefile
  13. +67 −0 vendor/amazon-ec2-0.3.8/bin/ec2-gem-example.rb
  14. +62 −0 vendor/amazon-ec2-0.3.8/bin/ec2sh
  15. +25 −0 vendor/amazon-ec2-0.3.8/bin/setup.rb
  16. +270 −0 vendor/amazon-ec2-0.3.8/lib/EC2.rb
  17. +41 −0 vendor/amazon-ec2-0.3.8/lib/EC2/availability_zones.rb
  18. +44 −0 vendor/amazon-ec2-0.3.8/lib/EC2/console.rb
  19. +153 −0 vendor/amazon-ec2-0.3.8/lib/EC2/elastic_ips.rb
  20. +147 −0 vendor/amazon-ec2-0.3.8/lib/EC2/exceptions.rb
  21. +166 −0 vendor/amazon-ec2-0.3.8/lib/EC2/image_attributes.rb
  22. +134 −0 vendor/amazon-ec2-0.3.8/lib/EC2/images.rb
  23. +216 −0 vendor/amazon-ec2-0.3.8/lib/EC2/instances.rb
  24. +94 −0 vendor/amazon-ec2-0.3.8/lib/EC2/keypairs.rb
  25. +43 −0 vendor/amazon-ec2-0.3.8/lib/EC2/products.rb
  26. +64 −0 vendor/amazon-ec2-0.3.8/lib/EC2/responses.rb
  27. +232 −0 vendor/amazon-ec2-0.3.8/lib/EC2/security_groups.rb
  28. +94 −0 vendor/amazon-ec2-0.3.8/lib/EC2/snapshots.rb
  29. +170 −0 vendor/amazon-ec2-0.3.8/lib/EC2/volumes.rb
  30. +68 −0 vendor/amazon-ec2-0.3.8/test/test_EC2.rb
  31. +49 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_availability_zones.rb
  32. +54 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_console.rb
  33. +144 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_elastic_ips.rb
  34. +238 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_image_attributes.rb
  35. +197 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_images.rb
  36. +348 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_instances.rb
  37. +123 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_keypairs.rb
  38. +48 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_products.rb
  39. +52 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_responses.rb
  40. +80 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_s3_xmlsimple.rb
  41. +205 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_security_groups.rb
  42. +83 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_snapshots.rb
  43. +142 −0 vendor/amazon-ec2-0.3.8/test/test_EC2_volumes.rb
  44. +19 −0 vendor/amazon-ec2-0.3.8/test/test_helper.rb
  45. +1,028 −0 vendor/xml-simple-1.0.12/lib/xmlsimple.rb
@@ -0,0 +1 @@
+*.app
4 README
@@ -0,0 +1,4 @@
+- Need to patch MacRuby trunk with http://www.macruby.org/trac/attachment/ticket/215/fix_openssl_215.3.diff
+ - 2 hunks will fail, this is fine.
+
+- Also probably need http://www.macruby.org/trac/attachment/ticket/275/mapper_method_dispatch.diff applied
@@ -0,0 +1,4 @@
+require 'hotcocoa/application_builder'
+require 'hotcocoa/standard_rake_tasks'
+
+task :default => [:run]
@@ -0,0 +1,8 @@
+name: Silverlining
+load: lib/application.rb
+version: "1.0"
+icon: resources/HotCocoa.icns
+resources:
+ - resources/**/*.*
+sources:
+ - lib/**/*.rb
@@ -0,0 +1,156 @@
+require 'hotcocoa'
+require 'lib/preferences'
+
+require 'rexml/xmltokens'
+module REXML
+ class Attribute
+ include ::REXML::XMLTokens
+ end
+end
+
+require 'vendor/xml-simple-1.0.12/lib/xmlsimple'
+require 'vendor/amazon-ec2-0.3.8/lib/EC2'
+
+class SilverLining
+ include HotCocoa
+
+ def start
+ @prefs = Preferences.instance
+
+ application(:name => "Silverlining") do |app|
+ app.delegate = self
+ @window = window(:frame => [@prefs[:position], @prefs[:size]].flatten, :title => "Silver Lining") do |win|
+ win.will_close { exit }
+
+ win << scroll_view(:layout => {:expand => [:width, :height]}) do |scroll|
+ sd = [sort_descriptor(:key => :id),
+ sort_descriptor(:key => :type),
+ sort_descriptor(:key => :dns_private),
+ sort_descriptor(:key => :dns_public),
+ sort_descriptor(:key => :launch_time),
+ sort_descriptor(:key => :size),
+ sort_descriptor(:key => :zone)]
+ scroll << @table = table_view(:data => [], :layout => {:expand => [:width, :height]},
+ :uses_alternating_row_background_colors => true,
+ :delegate => self,
+ :sort_descriptors => sd,
+ :columns => [
+ column(:id => :id, :title => 'id',
+ :sort_descriptor_prototype => sd[0]),
+ column(:id => :type, :title => 'type' ,
+ :sort_descriptor_prototype => sd[1]),
+ column(:id => :dns_private, :title => 'private name',
+ :sort_descriptor_prototype => sd[2]),
+ column(:id => :dns_public, :title => 'public name',
+ :sort_descriptor_prototype => sd[3]),
+ column(:id => :launch_time, :title => 'launch',
+ :sort_descriptor_prototype => sd[4]),
+ column(:id => :size, :title => 'size',
+ :sort_descriptor_prototype => sd[5]),
+ column(:id => :zone, :title => 'zone',
+ :sort_descriptor_prototype => sd[6])]) do |table|
+
+ object = Object.new
+ object.instance_variable_set("@behavior", Proc.new {launch_terminal})
+ def object.perform_action(sender)
+ @behavior.call(sender)
+ end
+ table.setTarget(object)
+ table.setDoubleAction("perform_action:")
+ end
+ end
+ end
+
+ if @prefs[:key] && @prefs[:secret]
+ load_instances
+ else
+ show_credentials_sheet(@window)
+ end
+ end
+ end
+
+ def show_credentials_sheet(window)
+ f = window.frame
+
+ credentialsSheet = window(:frame => [f.origin.x + (f.origin.x / 2) + 100,
+ f.origin.y + f.size.height - 400,
+ 400, 400]) do |win|
+
+ win << label(:text => "Key", :layout => {:start => false})
+ win << @key_field = text_field(:layout => {:start => false, :expand => [:width]})
+
+ win << label(:text => "Secret", :layout => {:start => false})
+ win << @secret_field = text_field(:layout => {:start => false, :expand => [:width]})
+
+ win << label(:text => "User", :layout => {:start => false})
+ win << @user_field = text_field(:layout => {:start => false, :expand => [:width]})
+
+ win << label(:text => "SSH Key File", :layout => {:start => false})
+ win << @ssh_key_field = text_field(:layout => {:start => false, :expand => [:width]})
+
+ win << button(:title => "save", :layout => {:start => false}) do |button|
+ button.on_action { endSheet(win) }
+ end
+ end
+
+ NSApp.beginSheet(credentialsSheet, modalForWindow:window, modalDelegate:self,
+ didEndSelector:nil,
+ contextInfo:nil)
+ end
+
+ def endSheet(sheet)
+ @prefs[:key] = @key_field.stringValue
+ @prefs[:secret] = @secret_field.stringValue
+ @prefs[:user] = @user_field.stringValue
+ @prefs[:ssh_key] = @ssh_key_field.stringValue
+
+ sheet.orderOut(self)
+ sheet.close
+
+ load_instances
+ end
+
+ def launch_terminal
+ # launch command grabbed from elastic fox
+ `/usr/bin/osascript -e 'on run argv' -e 'tell app "System Events" to set termOn to (exists process "Terminal")' -e 'set cmd to "ssh -i " & item 1 of argv & " " & item 2 of argv' -e 'if (termOn) then' -e 'tell app "Terminal" to do script cmd' -e 'else' -e 'tell app "Terminal" to do script cmd in front window' -e 'end if' -e 'tell app "Terminal" to activate' -e 'end run' #{@prefs[:ssh_key]} #{@prefs[:user]}@#{@table.dataSource.data[@table.selectedRow][:dns_public]}`
+ end
+
+ def load_instances
+ data = @table.dataSource.data
+ types = Hash.new(0)
+ ec2.describe_instances['reservationSet']['item'].each do |group|
+ group_name = []
+ group['groupSet']['item'].each do |i|
+ group_name << i['groupId']
+ types[i['groupId']] += 1
+ end
+
+ group['instancesSet']['item'].each do |instance|
+ data << {:id => instance['instanceId'],
+ :type_array => group_name,
+ :dns_private => instance['privateDnsName'],
+ :dns_public => instance['dnsName'],
+ :launch_time => Time.parse(instance['launchTime']).to_s,
+ :size => instance['instanceType'],
+ :zone => instance['placement']['availabilityZone']}
+ end
+ end
+
+ data.sort! do |a, b|
+ a[:type_array].sort! { |first, second| types[second] <=> types[first] }
+ b[:type_array].sort! { |first, second| types[second] <=> types[first] }
+ [a[:type_array], a[:launch_time]].flatten <=> [b[:type_array], b[:launch_time]].flatten
+ end
+
+ # do this at the end so we have the names sorted in order of usage
+ data.each { |d| d[:type] = d[:type_array].join(", ") }
+
+ @table.reload
+ end
+
+ def ec2
+ @ec2 ||= EC2::Base.new(:access_key_id => @prefs[:key], :secret_access_key => @prefs[:secret])
+ end
+end
+
+SilverLining.new.start
@@ -0,0 +1,26 @@
+module HotCocoa
+ def application_menu
+ menu do |main|
+ main.submenu :apple do |apple|
+ apple.item :about, :title => "About #{NSApp.name}"
+ apple.separator
+ apple.item :preferences, :key => ","
+ apple.separator
+ apple.submenu :services
+ apple.separator
+ apple.item :hide, :title => "Hide #{NSApp.name}", :key => "h"
+ apple.item :hide_others, :title => "Hide Others", :key => "h", :modifiers => [:command, :alt]
+ apple.item :show_all, :title => "Show All"
+ apple.separator
+ apple.item :quit, :title => "Quit #{NSApp.name}", :key => "q"
+ end
+ main.submenu :edit do |edit|
+ edit.item :copy, :key => 'c', :action => 'copy:'
+ edit.item :paste, :key => 'v', :action => "paste:"
+ end
+ main.submenu :help do |help|
+ help.item :help, :title => "#{NSApp.name} Help"
+ end
+ end
+ end
+end
@@ -0,0 +1,28 @@
+require 'singleton'
+
+class Preferences
+ include Singleton
+
+ def initialize
+ @preferences = NSUserDefaults.standardUserDefaults
+ @preferences.registerDefaults(
+ {
+ :size => [800, 600],
+ :position => [200, 200]
+ }
+ )
+ end
+
+ def []=(key, value)
+ if value.nil?
+ @preferences.removeObjectForKey(key.to_s)
+ else
+ @preferences.setObject(value, forKey:key.to_s)
+ end
+ @preferences.synchronize
+ end
+
+ def [](key)
+ @preferences.objectForKey(key.to_sym)
+ end
+end
Binary file not shown.
Oops, something went wrong.

0 comments on commit 4c30485

Please sign in to comment.