arh 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ *~
2
+ rdoc
3
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ Lidia (0.0.2)
5
+ open4 (= 0.9.6)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ columnize (0.3.2)
11
+ diff-lcs (1.1.2)
12
+ linecache (0.43)
13
+ open4 (0.9.6)
14
+ rspec (2.3.0)
15
+ rspec-core (~> 2.3.0)
16
+ rspec-expectations (~> 2.3.0)
17
+ rspec-mocks (~> 2.3.0)
18
+ rspec-core (2.3.1)
19
+ rspec-expectations (2.3.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.3.0)
22
+ ruby-debug (0.10.4)
23
+ columnize (>= 0.1)
24
+ ruby-debug-base (~> 0.10.4.0)
25
+ ruby-debug-base (0.10.4)
26
+ linecache (>= 0.3)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ Lidia!
33
+ open4 (= 0.9.6)
34
+ rspec (~> 2.3.0)
35
+ ruby-debug (~> 0.10.3)
@@ -0,0 +1,4 @@
1
+ === 0.1.0 2010-12-30
2
+
3
+ * 1 major enhancement:
4
+ * initial release: add class Arh
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ arh.gemspec
7
+ lib/arh.rb
8
+ script/console
9
+ script/destroy
10
+ script/generate
11
+
12
+
@@ -0,0 +1,5 @@
1
+
2
+ For more information on lidia, see http://lidia.rubyforge.org
3
+
4
+
5
+
@@ -0,0 +1,134 @@
1
+ = LIDIA
2
+
3
+ * http://gitorious/gnoxys/lidia
4
+
5
+ == DESCRIPTION:
6
+
7
+ Lidia is a yml based command contructor class. Aims to be easy to use and to provide an easy way to remember tons of commands
8
+
9
+ == SYNOPSIS:
10
+
11
+ Lidia's is written to provide an easy way to manage commands calls. Commands structure can be defined in an easy yaml file.
12
+
13
+ # $your editor ls.lidia.yml
14
+ : ==parameters:
15
+ :columns:
16
+ :option: -l
17
+ :description: listing format@
18
+
19
+ By default, lidia loads definition files from gem installation folder ../source, or you can pass with <tt>:definition_file</tt> the location
20
+
21
+ >> Lidia::Command.new('ls', {}, :definition_file => 'ls.lidia.yml')
22
+ => Lidia::Command
23
+ + name: ls,
24
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
25
+ + parameters:
26
+ * name: columns group: option , value: nil
27
+
28
+ Values can be passed as argument on new, or creating by block
29
+
30
+ >> Lidia::Command.new('ls', {:columns => true })
31
+ ?> Lidia::Command.new('ls') do |l|
32
+ ?> l.columns = true
33
+ >> end
34
+ => Lidia::Command
35
+ + name: ls,
36
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
37
+ + parameters:
38
+ * name: columns group: option , value: true
39
+
40
+ Once u have defined all the parameters that your command will use, define which actions can be done, por example, list_by_columns
41
+
42
+ # your editor ls.lidia.yml
43
+ # :actions:
44
+ # :list_by_columns:
45
+ # :parameters:
46
+ # :required: [ :columns ]
47
+
48
+ Now ask for <tt>command_for</tt> lidia list_by_columns
49
+
50
+ >> l = Lidia::Command.new('ls', {:columns => nil })
51
+ => Lidia::Command
52
+ + name: ls,
53
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
54
+ + parameters:
55
+ * name: columns group: option , value: nil
56
+
57
+ >> l.command_for(:list_by_columns)
58
+ ArgumentError: Parameter columns required but not valid
59
+
60
+ Ooops, parameter -l is required, to list_by_columns action, so set it to true
61
+
62
+ >> l.columns = true
63
+ => true
64
+ >> l.command_for(:list_by_columns)
65
+ => "/bin/ls -l"
66
+
67
+ We want sometimes, list other directory. so prepare defintion file to get an argument
68
+
69
+ # $your editor ls.lidia.yml
70
+ # :parameters:
71
+ # :list_what:
72
+ # :description: what do u want to list?
73
+
74
+ this option can be used for listing_by_columns to, but it is not mandatary
75
+
76
+ # $your editor ls.lidia.yml
77
+ # :actions:
78
+ # :list_by_columns:
79
+ # :parameters:
80
+ # :required: [ :columns ]
81
+ # :optional: [ :list_what ]
82
+
83
+ Now, no exceptions is raised, but argument can be used
84
+
85
+ >> l = Lidia::Command.new('ls', {:columns => true })
86
+ => Lidia::Command
87
+ + name: ls,
88
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
89
+ + parameters:
90
+ * name: columns group: option , value: true
91
+ * name: list_what group: argument , value: nil
92
+
93
+ >> l.command_for(:list_by_columns)
94
+ => "/bin/ls -l "
95
+ >> l.list_what = '/tmp'
96
+ => "/tmp"
97
+ >> l.command_for(:list_by_columns)
98
+ => "/bin/ls -l \"/tmp\" "
99
+
100
+
101
+
102
+
103
+ == REQUIREMENTS:
104
+
105
+ * FIX (list of requirements)
106
+
107
+ == INSTALL:
108
+
109
+ * FIX (sudo gem install, anything else)
110
+
111
+ == LICENSE:
112
+
113
+ (The MIT License)
114
+
115
+ Copyright (c) 2010 FIXME full name
116
+
117
+ Permission is hereby granted, free of charge, to any person obtaining
118
+ a copy of this software and associated documentation files (the
119
+ 'Software'), to deal in the Software without restriction, including
120
+ without limitation the rights to use, copy, modify, merge, publish,
121
+ distribute, sublicense, and/or sell copies of the Software, and to
122
+ permit persons to whom the Software is furnished to do so, subject to
123
+ the following conditions:
124
+
125
+ The above copyright notice and this permission notice shall be
126
+ included in all copies or substantial portions of the Software.
127
+
128
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
129
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
130
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
131
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
132
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
133
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
134
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'rspec/core/rake_task'
7
+ require 'bundler'
8
+ require 'open4'
9
+ require File.join(File.dirname(__FILE__), 'lib', 'arh')
10
+
11
+
12
+ Rspec::Core::RakeTask.new(:spec) do |t|
13
+ t.rspec_opts = ["--color"]
14
+ end
15
+
16
+ task :default => :spec
17
+
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'arh'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README.rdoc')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'arh')
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "arh"
5
+ s.version = Arh::VERSION
6
+ s.summary = "Automatic Remote Hands (!) is a command executer class.Based on Open4, allows you to execute commands in ruby shell and capture output, errors, exit_level and more"
7
+ s.description = "Automatic Remote Hands (!) is a command executer class.Based on Open4, allows you to execute commands in ruby shell and capture output, errors, exit_level and more"
8
+ s.authors = ['Gnoxys' ]
9
+ s.email = ['development@gnoxys.net']
10
+ s.homepage = 'http://gitorious.org/gnoxys/arh'
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+
14
+ s.add_runtime_dependency('open4', '~> 0.9.6')
15
+ s.add_development_dependency('rspec', '~> 2.3.0')
16
+
17
+ if RUBY_VERSION < '1.9'
18
+ s.add_development_dependency('ruby-debug', '~> 0.10.3')
19
+ end
20
+
21
+ end
@@ -0,0 +1,113 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+ require 'open4'
6
+
7
+ class Arh
8
+ VERSION = '0.1.0'
9
+
10
+ attr_reader :start_at
11
+ attr_reader :end_at
12
+ attr_reader :cmd
13
+ attr_reader :output
14
+ attr_reader :errors
15
+ attr_reader :exit_level
16
+ attr_reader :pid
17
+ attr_reader :status
18
+
19
+
20
+ # = Arh.execute
21
+ #
22
+ # Arh executes command with open4. Arh instance is returned with this attributes
23
+ #
24
+ # - start_at: Time instance storing when command was started
25
+ # - end_at: Time instance storing when command was ended
26
+ # - cmd: Command executed
27
+ # - output: Returns String with output at standart output
28
+ # - errors: Returns String with output at errors output
29
+ # - exit_evel: Returns interger command exit level
30
+ # - pid: assigned process identificator
31
+ # - status: Process status object
32
+ #
33
+ # = User example
34
+ #
35
+ # a = Arh.execute('ls /tmp')
36
+ # => #<Arh:0xf7049dac @end_at=Thu Dec 30 18:13:41 +0000 2010, @cmd="ls /tmp", @status=#<Process::Status: pid=10863,exited(0)>, @exit_level=0, @pid=10863, @start_at=Thu Dec 30 18:13:41 +0000 2010, @errors="\n", @pipe=nil, @output="test">
37
+ # a.exit_level
38
+ # >> a.exit_level
39
+ # => 0
40
+ # >> a = Arh.execute('ls /tmps')
41
+ # => #<Arh:0xf7041990 @end_at=Thu Dec 30 18:15:21 +0000 2010, @cmd="ls /tmps", @status=#<Process::Status: pid=10871,exited(2)>, @exit_level=2, @pid=10871, @start_at=Thu Dec 30 18:15:21 +0000 2010, @errors="ls: no se puede acceder a /tmps: No existe el fichero o el directorio\n", @pipe=nil, @output="\n">
42
+ # >> a.errors
43
+ # => "ls: no se puede acceder a /tmps: No existe el fichero o el directorio\n"
44
+ # >> a.exit_level
45
+ # => 2
46
+ def self.execute(shell_command, options = {})
47
+ new(shell_command, options).execute
48
+ end
49
+
50
+ def self.execute!(shell_command, options = {})
51
+ new(shell_command, options).execute!
52
+ end
53
+
54
+ def execute!
55
+ @raise_on_fail = true
56
+ execute
57
+ end
58
+
59
+ def initialize(shell_command, options = {})
60
+ raise ArgumentError, "no command given" unless shell_command
61
+ @cmd = shell_command
62
+ @pipe = options[:pipe]
63
+ end
64
+
65
+ def execute
66
+
67
+ # trap_save = trap( 0, "IGNORE" )
68
+
69
+ @start_at = Time.now
70
+
71
+ read_stdout, write_stdout = IO.pipe
72
+ read_stderr, write_stderr = IO.pipe
73
+
74
+ pid = fork do
75
+ # trap( 0, "IGNORE" )
76
+ read_stdout.close
77
+ read_stderr.close
78
+
79
+ cmd = @cmd
80
+ cmd = "#{ @pipe }|#{ cmd }" if @pipe
81
+
82
+ pid_open4, stdin, stdout, stderr = Open4::popen4 "#{ cmd }"
83
+
84
+ write_stdout.puts stdout.read
85
+ write_stderr.puts stderr.read
86
+
87
+ ignored, status_open4 = Process::waitpid2 pid_open4
88
+ exit status_open4.exitstatus
89
+ end
90
+
91
+ # trap( 0, trap_save )
92
+
93
+ write_stdout.close
94
+ write_stderr.close
95
+
96
+ result_stdout = read_stdout.read
97
+ result_stderr = read_stderr.read
98
+
99
+ @pid, @status = Process.wait2(pid)
100
+
101
+ @output = result_stdout
102
+ @errors = result_stderr
103
+ @exit_level = status.exitstatus
104
+ @pid = pid
105
+ @status = status
106
+ @end_at = Time.now
107
+ self
108
+ end
109
+
110
+ def success?
111
+ @exit_level.zero?
112
+ end
113
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/arh.rb'}"
9
+ puts "Loading arh gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arh
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Gnoxys
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-30 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: open4
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 55
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 6
34
+ version: 0.9.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 0
50
+ version: 2.3.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: ruby-debug
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 0
64
+ - 10
65
+ - 3
66
+ version: 0.10.3
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Automatic Remote Hands (!) is a command executer class.Based on Open4, allows you to execute commands in ruby shell and capture output, errors, exit_level and more
70
+ email:
71
+ - development@gnoxys.net
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - History.txt
83
+ - Manifest.txt
84
+ - PostInstall.txt
85
+ - README.rdoc
86
+ - Rakefile
87
+ - arh.gemspec
88
+ - lib/arh.rb
89
+ - script/console
90
+ - script/destroy
91
+ - script/generate
92
+ has_rdoc: true
93
+ homepage: http://gitorious.org/gnoxys/arh
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.3.7
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Automatic Remote Hands (!) is a command executer class.Based on Open4, allows you to execute commands in ruby shell and capture output, errors, exit_level and more
126
+ test_files: []
127
+