Permalink
Browse files

Initial

  • Loading branch information...
0 parents commit 0efaa2f3b920fe00ecd65dd05aede0da9a52fda5 @merlinvn merlinvn committed Nov 17, 2011
Showing with 3,028 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. BIN .rjobs.gemspec.swp
  3. +4 −0 Gemfile
  4. +15 −0 Guardfile
  5. +34 −0 Rakefile
  6. BIN bin/.rjobs.swp
  7. +6 −0 bin/rjobs
  8. BIN features/.listJobs.feature.swp
  9. +21 −0 features/listJobs.feature
  10. +12 −0 features/manual.feature
  11. BIN features/step_definitions/.listJobs_steps.rb.swo
  12. BIN features/step_definitions/.listJobs_steps.rb.swp
  13. +19 −0 features/step_definitions/listJobs_steps.rb
  14. +12 −0 features/submit.feature
  15. BIN features/support/.env.rb.swp
  16. +3 −0 features/support/env.rb
  17. +1 −0 features/support/setup.rb
  18. +5 −0 lib/rjobs.rb
  19. BIN lib/rjobs/.cli.rb.swp
  20. BIN lib/rjobs/.color_helper.rb.swp
  21. BIN lib/rjobs/.command_builder.rb.swp
  22. BIN lib/rjobs/.job.rb.swp
  23. BIN lib/rjobs/.job_handler.rb.swp
  24. BIN lib/rjobs/.jobs_file.rb.swp
  25. +50 −0 lib/rjobs/cli.rb
  26. +12 −0 lib/rjobs/color_helper.rb
  27. +25 −0 lib/rjobs/command_builder.rb
  28. +26 −0 lib/rjobs/job.rb
  29. +15 −0 lib/rjobs/job_handler.rb
  30. +21 −0 lib/rjobs/jobs_file.rb
  31. +15 −0 lib/rjobs/process.rb
  32. +3 −0 lib/rjobs/version.rb
  33. +32 −0 rjobs.gemspec
  34. +31 −0 samples/jobAttributes.xml
  35. +16 −0 samples/jobList.xml
  36. +338 −0 samples/jobSepcification.xml
  37. +38 −0 spec/data_helper.rb
  38. BIN spec/lib/.job_handler_spec.rb.swp
  39. BIN spec/lib/.job_spec.rb.swp
  40. +16 −0 spec/lib/command_builder_spec.rb
  41. +18 −0 spec/lib/job_handler_spec.rb
  42. +42 −0 spec/lib/job_spec.rb
  43. +18 −0 spec/lib/process_spec.rb
  44. +7 −0 tmp/aruba/test_jobs.rjob
  45. +5 −0 vendor/aruba-0.4.7/.document
  46. +25 −0 vendor/aruba-0.4.7/.gitignore
  47. +1 −0 vendor/aruba-0.4.7/.rvmrc
  48. +4 −0 vendor/aruba-0.4.7/.travis.yml
  49. +10 −0 vendor/aruba-0.4.7/Gemfile
  50. +202 −0 vendor/aruba-0.4.7/History.md
  51. +20 −0 vendor/aruba-0.4.7/LICENSE
  52. +160 −0 vendor/aruba-0.4.7/README.md
  53. +15 −0 vendor/aruba-0.4.7/Rakefile
  54. +27 −0 vendor/aruba-0.4.7/aruba.gemspec
  55. +1 −0 vendor/aruba-0.4.7/config/.gitignore
  56. +2 −0 vendor/aruba-0.4.7/cucumber.yml
  57. +42 −0 vendor/aruba-0.4.7/features/exit_statuses.feature
  58. +157 −0 vendor/aruba-0.4.7/features/file_system_commands.feature
  59. +24 −0 vendor/aruba-0.4.7/features/flushing.feature
  60. +40 −0 vendor/aruba-0.4.7/features/interactive.feature
  61. +25 −0 vendor/aruba-0.4.7/features/no_clobber.feature
  62. +248 −0 vendor/aruba-0.4.7/features/output.feature
  63. +28 −0 vendor/aruba-0.4.7/features/step_definitions/aruba_dev_steps.rb
  64. +5 −0 vendor/aruba-0.4.7/features/support/env.rb
  65. +1 −0 vendor/aruba-0.4.7/lib/aruba.rb
  66. +379 −0 vendor/aruba-0.4.7/lib/aruba/api.rb
  67. +261 −0 vendor/aruba-0.4.7/lib/aruba/cucumber.rb
  68. +56 −0 vendor/aruba-0.4.7/lib/aruba/hooks.rb
  69. +71 −0 vendor/aruba-0.4.7/lib/aruba/process.rb
  70. +122 −0 vendor/aruba-0.4.7/lib/aruba/reporting.rb
  71. +24 −0 vendor/aruba-0.4.7/templates/css/console.css
  72. +42 −0 vendor/aruba-0.4.7/templates/css/filesystem.css
  73. +59 −0 vendor/aruba-0.4.7/templates/css/pygments-autumn.css
  74. +14 −0 vendor/aruba-0.4.7/templates/files.erb
  75. +22 −0 vendor/aruba-0.4.7/templates/images/LICENSE
  76. BIN vendor/aruba-0.4.7/templates/images/folder.png
  77. BIN vendor/aruba-0.4.7/templates/images/page_white.png
  78. BIN vendor/aruba-0.4.7/templates/images/page_white_gherkin.png
  79. BIN vendor/aruba-0.4.7/templates/images/page_white_ruby.png
  80. +20 −0 vendor/aruba-0.4.7/templates/index.erb
  81. +5 −0 vendor/aruba-0.4.7/templates/js/filesystem.js
  82. +18 −0 vendor/aruba-0.4.7/templates/js/jquery-1.6.1.min.js
  83. +34 −0 vendor/aruba-0.4.7/templates/main.erb
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
Binary file not shown.
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in rjobs.gemspec
+gemspec
@@ -0,0 +1,15 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'cucumber' do
+ watch(%r{^features/.+\.feature$})
+ watch(%r{^features/support/.+$}) { 'features' }
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
+end
+
+
+guard 'rspec' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) {|m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
@@ -0,0 +1,34 @@
+require "bundler/gem_tasks"
+
+
+desc 'List all defined steps'
+task :steps do
+ require 'hirb'
+ extend Hirb::Console
+ puts "CUCUMBER steps:"
+ puts ""
+ #step_definition_dir = "features/step_definitions"
+ step_definition_dir = "."
+ #step_definition_dir = "/Users/merlin/.rvm/gems/ruby-1.9.2-p290/gems/aruba-0.4.7/lib/aruba/"
+
+ Dir.glob(File.join(step_definition_dir,'**/*.rb')).each do |step_file|
+
+ puts "File: #{step_file}"
+ puts ""
+ results = []
+ File.new(step_file).read.each_line.each_with_index do |line, number|
+
+ next unless line =~ /^\s*(?:Given|When|Then)\s+|\//
+ res = /(?:Given|When|Then)[\s\(]*\/(.*)\/([imxo]*)[\s\)]*do\s*(?:$|\|(.*)\|)/.match(line)
+ next unless res
+ matches = res.captures
+ results << OpenStruct.new(
+ :steps => matches[0],
+ :modifier => matches[1],
+ :args => matches[2]
+ )
+ end
+ table results, :resize => false, :fields=>[:steps, :modifier, :args]
+ puts ""
+ end
+end
Binary file not shown.
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
+
+require 'rjobs/cli'
+Rjobs::CLI.start
Binary file not shown.
@@ -0,0 +1,21 @@
+Feature: List Jobs
+ As a user
+ I want to have a function to list all jobs
+ So as I can see a list of jobs
+
+ Background:
+
+ Scenario: list all jobs
+ Given a file named "test_jobs.rjob" with:
+ """
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ """
+ When I successfully run `rjobs list test_jobs.rjob`
+ Then the output should match /1 - .*Finished.*\n2 - .*Finished.*\n3 - .*Failed.*\n4 - .*Failed.*\n5 - .*Failed.*\n6 - .*Finished.*\n7 - .*Not Exist.*/
+ And show me the output
@@ -0,0 +1,12 @@
+Feature: Manual
+ As a user
+ I want manual feature
+ So that I can see the help instruction for using this gem
+
+ Scenario: It can call from command
+ When I successfully run `rjobs help`
+ Then the output should contain "Hello there!!! This is the manual pages."
+
+
+
+
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,19 @@
+require 'rjobs/process'
+require 'rjobs/job_handler'
+require 'cucumber/rspec/doubles'
+require 'aruba/api'
+require 'aruba/hooks'
+require 'aruba/reporting'
+
+World(Aruba::Api)
+
+Given /^the process was mocked$/ do
+ Rjobs::Process.stub!(:run).and_return("abc")
+ Rjobs::JobHandler.stub!(:get_job_attributes).and_return("abc")
+end
+
+
+Then /^show me the output$/ do
+ puts all_stdout
+end
+
@@ -0,0 +1,12 @@
+Feature: Submit
+ As a user
+ I want to submit jobs
+ So that jobs can be run on the xgrid
+
+ Scenario: Have a submit command
+ When I successfully run `rjobs submit`
+ Then the output should contain "submit [jobs_file]"
+
+
+
+
Binary file not shown.
@@ -0,0 +1,3 @@
+require 'aruba'
+
+ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
@@ -0,0 +1 @@
+require 'aruba/cucumber'
@@ -0,0 +1,5 @@
+require "rjobs/version"
+
+module Rjobs
+ # Your code goes here...
+end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,50 @@
+require 'thor'
+#require 'rcp_gen'
+require 'rjobs/jobs_file'
+require 'rjobs/job_handler'
+require 'rjobs/job'
+require 'rjobs/color_helper'
+
+module Rjobs
+ class CLI < Thor
+ desc "help", "Display the manual of Rjobs"
+ def help
+ puts "Hello there!!! This is the manual pages."
+ end
+
+ desc "submit [jobs_file]", "Submit jobfiles into grid"
+ def submit(jobs_file = "")
+ if (jobs_file=="")
+ man(:submit)
+ return
+ end
+ puts "Hello world"
+
+ end
+
+ desc "list jobs_file","list all jobs contained in the jobs_file"
+ def list(jobs_file="")
+ jf = JobsFile.new(jobs_file)
+
+ @jobs= []
+ jf.ids.each do |jobId|
+ job = Job.new(jobId, Rjobs::JobHandler.get_job_attributes(jobId))
+ @jobs << job
+ end
+
+ @jobs.each do |job|
+ puts "#{job.id} - #{job.status.red}"
+ end
+
+ end
+
+
+ private
+ def man(command)
+ if (command==:submit )
+ puts "rjobs submit [jobs_file]"
+ end
+ end
+
+ end
+end
@@ -0,0 +1,12 @@
+class String
+ def colorize(text, color_code)
+ "#{color_code}#{text}e[0m"
+ end
+
+ def red
+ colorize(self, "e[31m")
+ end
+ def green
+ colorize(self, "e[32m")
+ end
+end
@@ -0,0 +1,25 @@
+module Rjobs
+ class CommandBuilder
+ @@host = "127.0.0.1"
+ @@password = "xgrid"
+
+
+ def initialize()
+
+ end
+
+ def self.build(params)
+ cmd = []
+ cmd << "xgrid"
+ cmd << "-h #{@@host}"
+ cmd << "-p #{@@password}"
+ cmd << "-f xml"
+ params.each do |key, value|
+ cmd << "-#{key}"
+ cmd << value
+ end
+ cmd.join(" ")
+ end
+
+ end
+end
@@ -0,0 +1,26 @@
+require 'plist'
+module Rjobs
+ class Job
+ attr_accessor :id, :name, :status
+ def initialize(id=0,xml="")
+ @id = id
+ parse(xml)
+ end
+
+ def xml=(xml)
+ parse(xml)
+ end
+
+
+ private
+ def parse(xml)
+ return if xml.empty?
+
+ result = Plist::parse_xml(xml)
+ @name = result['jobAttributes'].nil? ? "" : result['jobAttributes']['name']
+ @status = result['jobAttributes'].nil? ? "Not Exist" : result['jobAttributes']['jobStatus']
+ end
+
+ end
+end
+
@@ -0,0 +1,15 @@
+require 'rjobs/command_builder'
+require 'rjobs/process'
+
+module Rjobs
+ class JobHandler
+
+
+ def self.get_job_attributes(id)
+ cm = CommandBuilder.build({:job => :attributes, :id => id})
+ Process.run(cm)
+ end
+
+
+ end
+end
@@ -0,0 +1,21 @@
+module Rjobs
+ class JobsFile
+ def initialize(jobs_file)
+ @jobIds = []
+ File.open(jobs_file, "r") do |infile|
+ while (line = infile.gets)
+ @jobIds << line.sub(/\n/,"")
+ end
+ end
+ end
+
+ def ids
+ @jobIds
+ end
+
+
+ def list_all
+ puts @jobIds.join("\n")
+ end
+ end
+end
@@ -0,0 +1,15 @@
+
+module Rjobs
+ class Process
+ attr_accessor :stdout, :stderr
+ def initialize()
+ end
+
+
+ def self.run(cmd)
+ IO.popen(cmd){ |stdout|
+ stdout.readlines.join
+ }
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module Rjobs
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,32 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "rjobs/version"
+
+Gem::Specification.new do |s|
+ s.name = "rjobs"
+ s.version = Rjobs::VERSION
+ s.authors = ["Merlin"]
+ s.email = ["merlinvn@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{Gem to Handle Jobs for XGrid}
+ s.description = %q{Gem to Handle Jobs for XGrid}
+
+ s.rubyforge_project = "rjobs"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ s.add_development_dependency "rspec"
+ s.add_development_dependency "cucumber"
+ s.add_development_dependency "aruba"
+ s.add_development_dependency "guard"
+ s.add_development_dependency "growl_notify"
+ s.add_development_dependency "guard-rspec"
+ # s.add_runtime_dependency "rest-client"
+ s.add_dependency "thor"
+ #s.add_dependency "nokogiri"
+ s.add_dependency "plist"
+end
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>jobAttributes</key>
+ <dict>
+ <key>activeCPUPower</key>
+ <string>0</string>
+ <key>applicationIdentifier</key>
+ <string>com.apple.xgrid.cli</string>
+ <key>dateNow</key>
+ <date>2011-11-17T04:50:58Z</date>
+ <key>dateStarted</key>
+ <date>2011-11-15T14:44:53Z</date>
+ <key>dateStopped</key>
+ <date>2011-11-15T14:44:53Z</date>
+ <key>dateSubmitted</key>
+ <date>2011-11-15T14:44:53Z</date>
+ <key>jobStatus</key>
+ <string>Finished</string>
+ <key>name</key>
+ <string>./a.out</string>
+ <key>percentDone</key>
+ <real>100</real>
+ <key>taskCount</key>
+ <string>1</string>
+ <key>undoneTaskCount</key>
+ <string>0</string>
+ </dict>
+</dict>
+</plist>
Oops, something went wrong.

0 comments on commit 0efaa2f

Please sign in to comment.