rush2 0.7.0

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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +13 -0
  3. data/Gemfile.lock +86 -0
  4. data/README.rdoc +125 -0
  5. data/Rakefile +57 -0
  6. data/VERSION +1 -0
  7. data/bin/rush +13 -0
  8. data/bin/rushd +7 -0
  9. data/lib/rush.rb +91 -0
  10. data/lib/rush/access.rb +121 -0
  11. data/lib/rush/array_ext.rb +19 -0
  12. data/lib/rush/box.rb +124 -0
  13. data/lib/rush/commands.rb +76 -0
  14. data/lib/rush/config.rb +147 -0
  15. data/lib/rush/dir.rb +166 -0
  16. data/lib/rush/embeddable_shell.rb +26 -0
  17. data/lib/rush/entry.rb +229 -0
  18. data/lib/rush/exceptions.rb +32 -0
  19. data/lib/rush/file.rb +94 -0
  20. data/lib/rush/find_by.rb +39 -0
  21. data/lib/rush/fixnum_ext.rb +18 -0
  22. data/lib/rush/head_tail.rb +11 -0
  23. data/lib/rush/local.rb +377 -0
  24. data/lib/rush/process.rb +59 -0
  25. data/lib/rush/process_set.rb +62 -0
  26. data/lib/rush/remote.rb +33 -0
  27. data/lib/rush/search_results.rb +71 -0
  28. data/lib/rush/shell.rb +111 -0
  29. data/lib/rush/shell/completion.rb +110 -0
  30. data/lib/rush/string_ext.rb +16 -0
  31. data/spec/access_spec.rb +134 -0
  32. data/spec/array_ext_spec.rb +15 -0
  33. data/spec/base.rb +22 -0
  34. data/spec/box_spec.rb +76 -0
  35. data/spec/commands_spec.rb +47 -0
  36. data/spec/config_spec.rb +108 -0
  37. data/spec/dir_spec.rb +163 -0
  38. data/spec/embeddable_shell_spec.rb +17 -0
  39. data/spec/entry_spec.rb +133 -0
  40. data/spec/file_spec.rb +83 -0
  41. data/spec/find_by_spec.rb +58 -0
  42. data/spec/fixnum_ext_spec.rb +19 -0
  43. data/spec/local_spec.rb +365 -0
  44. data/spec/process_set_spec.rb +50 -0
  45. data/spec/process_spec.rb +73 -0
  46. data/spec/remote_spec.rb +140 -0
  47. data/spec/rush_spec.rb +28 -0
  48. data/spec/search_results_spec.rb +44 -0
  49. data/spec/shell_spec.rb +35 -0
  50. data/spec/ssh_tunnel_spec.rb +122 -0
  51. data/spec/string_ext_spec.rb +23 -0
  52. metadata +209 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 385d84f8643d09bdcccc441ea72f25e2ff699bb5
4
+ data.tar.gz: d06dc973e041477d3cecc357000ac5ce9cc8eaa7
5
+ SHA512:
6
+ metadata.gz: 88083d80994df10c2c6108f675c76cb068f8d30f650dbee91561ba0fa33ad503a40b96858e8e88d28843cc83ea2df68985c2850be74018e1fdcc4af254028d0a
7
+ data.tar.gz: 911e93db558683391f408b1efe48eb6362e72b3e9ba187a183d9bd6ac8a11aca430dbe50a8f612c92be45aaf9966216f36779d24574de069fca8ef5970f6ab28
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'session'
4
+ gem 'coolline'
5
+ gem 'coderay'
6
+ gem 'net-ssh'
7
+
8
+ group :development do
9
+ gem 'pry'
10
+ gem 'rake'
11
+ gem 'jeweler'
12
+ gem 'rspec'
13
+ end
@@ -0,0 +1,86 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ coderay (1.1.0)
7
+ coolline (0.5.0)
8
+ unicode_utils (~> 1.4)
9
+ descendants_tracker (0.0.4)
10
+ thread_safe (~> 0.3, >= 0.3.1)
11
+ diff-lcs (1.2.5)
12
+ faraday (0.9.0)
13
+ multipart-post (>= 1.2, < 3)
14
+ git (1.2.8)
15
+ github_api (0.12.1)
16
+ addressable (~> 2.3)
17
+ descendants_tracker (~> 0.0.4)
18
+ faraday (~> 0.8, < 0.10)
19
+ hashie (>= 3.2)
20
+ multi_json (>= 1.7.5, < 2.0)
21
+ nokogiri (~> 1.6.3)
22
+ oauth2
23
+ hashie (3.3.1)
24
+ highline (1.6.21)
25
+ jeweler (2.0.1)
26
+ builder
27
+ bundler (>= 1.0)
28
+ git (>= 1.2.5)
29
+ github_api
30
+ highline (>= 1.6.15)
31
+ nokogiri (>= 1.5.10)
32
+ rake
33
+ rdoc
34
+ json (1.8.1)
35
+ jwt (1.0.0)
36
+ method_source (0.8.2)
37
+ mini_portile (0.6.0)
38
+ multi_json (1.10.1)
39
+ multi_xml (0.5.5)
40
+ multipart-post (2.0.0)
41
+ net-ssh (2.9.1)
42
+ nokogiri (1.6.3.1)
43
+ mini_portile (= 0.6.0)
44
+ oauth2 (1.0.0)
45
+ faraday (>= 0.8, < 0.10)
46
+ jwt (~> 1.0)
47
+ multi_json (~> 1.3)
48
+ multi_xml (~> 0.5)
49
+ rack (~> 1.2)
50
+ pry (0.10.1)
51
+ coderay (~> 1.1.0)
52
+ method_source (~> 0.8.1)
53
+ slop (~> 3.4)
54
+ rack (1.5.2)
55
+ rake (10.3.2)
56
+ rdoc (4.1.2)
57
+ json (~> 1.4)
58
+ rspec (3.1.0)
59
+ rspec-core (~> 3.1.0)
60
+ rspec-expectations (~> 3.1.0)
61
+ rspec-mocks (~> 3.1.0)
62
+ rspec-core (3.1.6)
63
+ rspec-support (~> 3.1.0)
64
+ rspec-expectations (3.1.2)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.1.0)
67
+ rspec-mocks (3.1.3)
68
+ rspec-support (~> 3.1.0)
69
+ rspec-support (3.1.2)
70
+ session (3.2.0)
71
+ slop (3.6.0)
72
+ thread_safe (0.3.4)
73
+ unicode_utils (1.4.0)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ coderay
80
+ coolline
81
+ jeweler
82
+ net-ssh
83
+ pry
84
+ rake
85
+ rspec
86
+ session
@@ -0,0 +1,125 @@
1
+ = rush -- manage your unix systems with pure Ruby
2
+
3
+ rush is a unix integration library and an interactive shell which uses pure Ruby syntax. Walk directory trees; create, copy, search, and destroy files; find and kill processes - everything you'd normally do with shell commands, now in the strict and elegant world of Ruby.
4
+
5
+ {<img src="https://travis-ci.org/s-mage/rush.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/s-mage/rush]
6
+
7
+
8
+ == Install
9
+
10
+ Install v.0.6.8 from rubygems.org ~ no longer maintained
11
+
12
+ sudo gem install rush
13
+
14
+
15
+ Or for the bleeding edge:
16
+
17
+ git clone git://github.com/s-mage/rush.git
18
+ cd rush
19
+ gem build *.gemspec
20
+ sudo gem install *.gem
21
+
22
+
23
+ If you want the development version, you will need the development headers for ruby (eg. ruby-dev in most package managers) and change that last command to:
24
+
25
+ git clone git://github.com/s-mage/rush.git
26
+ cd rush
27
+ bundle install # to get the dependencies
28
+ rake spec # to run the tests
29
+ rake rdoc # to generate a local copy of the docs from your sourcetree (optional)
30
+
31
+ sudo rake install # install your default gem location
32
+
33
+
34
+ To uninstall
35
+
36
+ sudo gem uninstall rush
37
+
38
+
39
+ == Usage
40
+
41
+ Count the number of classes in your project using bash:
42
+
43
+ find myproj -name \*.rb | xargs grep '^\s*class' | wc -l
44
+
45
+ In rush, this is:
46
+
47
+ myproj['**/*.rb'].search(/^\s*class/).lines.size
48
+
49
+ Pesky stray mongrels? In bash:
50
+
51
+ kill `ps aux | grep mongrel_rails | grep -v grep | cut -c 10-20`
52
+
53
+ In rush:
54
+
55
+ processes.filter(:cmdline => /mongrel_rails/).kill
56
+
57
+ == As a library
58
+
59
+ require 'rubygems'
60
+ require 'rush'
61
+
62
+ file = Rush['/tmp/myfile']
63
+ file.write "hello"
64
+ puts file.contents
65
+ file.destroy
66
+
67
+ puts Rush.my_process.pid
68
+ puts Rush.processes.size
69
+ puts Rush.bash("echo SHELL COMMAND | tr A-Z a-z")
70
+ puts Rush.launch_dir['*.rb'].search(/Rush/).entries.inspect
71
+
72
+ == Invoking the shell
73
+
74
+ Run the "rush" binary to enter the interactive shell.
75
+
76
+ == Remote access and clustering
77
+
78
+ rush can control any number of remote machines from a single location. Copy files or directories between servers as seamlessly as if it was all local.
79
+
80
+ Example of remote access:
81
+
82
+ local = Rush::Box.new('localhost')
83
+ remote = Rush::Box.new('my.remote.server.com')
84
+ local_dir = local['/Users/adam/myproj/']
85
+ remote_dir = remote['/home/myproj/app/']
86
+
87
+ local_dir.copy_to remote_dir
88
+ remote_dir['**/.svn/'].each { |d| d.destroy }
89
+
90
+ Clustering:
91
+
92
+ local_dir = Rush::Box.new('localhost')['/Users/adam/server_logs/'].create
93
+ servers = %w(www1 www2 www3).map { |n| Rush::Box.new(n) }
94
+ servers.each { |s| s['/var/log/nginx/access.log'].copy_to local_dir["#{s.host}_access.log"] }
95
+
96
+ == Reference
97
+
98
+ For more details on syntax and commands, see:
99
+
100
+ * Rush
101
+ * Rush::Entry
102
+ * Rush::File
103
+ * Rush::Dir
104
+ * Rush::Commands
105
+ * Rush::Box
106
+ * Rush::Process
107
+
108
+ == Meta
109
+
110
+ What follows is the meta from the original project, which is no longer maintained.
111
+ The mailinglist is still functional and the new website for this fork is:
112
+ https://github.com/s-mage/rush
113
+
114
+ Created by Adam Wiggins
115
+
116
+ Patches contributed by Chihiro Ito, Gabriel Ware, Michael Schutte, Ricardo Chimal Jr., and Nicholas Schlueter, Pedro Belo, and Martin Kuehl
117
+
118
+ Logo by James Lindenbaum
119
+
120
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
121
+
122
+ http://rush.heroku.com
123
+
124
+ http://groups.google.com/group/ruby-shell
125
+
@@ -0,0 +1,57 @@
1
+ require 'rake'
2
+ require 'jeweler'
3
+
4
+ Jeweler::Tasks.new do |s|
5
+ s.name = "rush2"
6
+ s.summary = "A Ruby replacement for bash+ssh."
7
+ s.description = "A Ruby replacement for bash+ssh, providing both an interactive shell and a library. Manage both local and remote unix systems from a single client."
8
+ s.author = "Sergey Smagin"
9
+ s.email = "smaginsergey1310@gmail.com"
10
+ s.homepage = "https://github.com/s-mage/rush"
11
+ s.licenses = ['MIT']
12
+ s.executables = [ "rush", "rushd" ]
13
+ s.has_rdoc = true
14
+
15
+ s.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
16
+ end
17
+
18
+ Jeweler::GemcutterTasks.new
19
+
20
+ ######################################################
21
+
22
+ require 'rspec/core/rake_task'
23
+
24
+ desc "Run all specs"
25
+ RSpec::Core::RakeTask.new('spec') do |t|
26
+ t.pattern = 'spec/*_spec.rb'
27
+ end
28
+
29
+ desc "Print specdocs"
30
+ RSpec::Core::RakeTask.new(:doc) do |t|
31
+ t.pattern = 'spec/*_spec.rb'
32
+ t.rspec_opts = ["--format", "specdoc", "--dry-run"]
33
+ end
34
+
35
+ desc "Run all examples with RCov"
36
+ RSpec::Core::RakeTask.new('rcov') do |t|
37
+ t.pattern = 'spec/*_spec.rb'
38
+ t.rcov = true
39
+ t.rcov_opts = ['--exclude', 'examples']
40
+ end
41
+
42
+ task :default => :spec
43
+
44
+ ######################################################
45
+
46
+ require 'rdoc/task'
47
+
48
+ Rake::RDocTask.new do |t|
49
+ t.rdoc_dir = 'rdoc'
50
+ t.title = "rush, a Ruby replacement for bash+ssh"
51
+ t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
52
+ t.options << '--charset' << 'utf-8'
53
+ t.rdoc_files.include('README.rdoc')
54
+ t.rdoc_files.include('lib/rush.rb')
55
+ t.rdoc_files.include('lib/rush/*.rb')
56
+ end
57
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.0
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/rush'
4
+ require_relative '../lib/rush/shell'
5
+
6
+ shell = Rush::Shell.new
7
+
8
+ if ARGV.size > 0
9
+ shell.execute ARGV.join(' ')
10
+ else
11
+ shell.run
12
+ end
13
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative __dir__ + '/../lib/rush'
4
+ require_relative __dir__ + '/../lib/rush/server'
5
+
6
+ RushServer.new.run
7
+
@@ -0,0 +1,91 @@
1
+ require 'etc' # get info from /etc
2
+
3
+ # The top-level Rush module has some convenience methods for accessing the
4
+ # local box.
5
+ module Rush
6
+ # Access the root filesystem of the local box.
7
+ #
8
+ # @param key [String] relative path.
9
+ # @example
10
+ # Rush['/etc/hosts'].contents
11
+ #
12
+ def self.[](key)
13
+ box[key]
14
+ end
15
+
16
+ # Create a dir object from the path of a provided file.
17
+ #
18
+ # @param filename [String] path that should be created.
19
+ # @example
20
+ # Rush.dir(__FILE__).files
21
+ #
22
+ def self.dir(filename)
23
+ box[::File.expand_path(::File.dirname(filename)) + '/']
24
+ end
25
+
26
+ # Create a dir object based on the shell's current working directory at the
27
+ # time the program was run.
28
+ #
29
+ # @example
30
+ # Rush.launch_dir.files
31
+ #
32
+ def self.launch_dir
33
+ box[::Dir.pwd + '/']
34
+ end
35
+
36
+ # Run a bash command in the root of the local machine. Equivalent to
37
+ # Rush::Box.new.bash.
38
+ def self.bash(command, options={})
39
+ box.bash(command, options)
40
+ end
41
+
42
+ # Pull the process list for the local machine.
43
+ #
44
+ # @example
45
+ # Rush.processes.filter(:cmdline => /ruby/)
46
+ #
47
+ def self.processes
48
+ box.processes
49
+ end
50
+
51
+ # Get the process object for this program's PID.
52
+ #
53
+ # @example
54
+ # puts "I'm using #{Rush.my_process.mem} blocks of memory"
55
+ #
56
+ def self.my_process
57
+ box.processes.filter(:pid => ::Process.pid).first
58
+ end
59
+
60
+ # Create a box object for localhost.
61
+ def self.box
62
+ @@box = Rush::Box.new
63
+ end
64
+
65
+ # Quote a path for use in backticks, say.
66
+ def self.quote(path)
67
+ path.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
68
+ end
69
+ end
70
+
71
+ module Rush::Connection; end
72
+
73
+ require_relative 'rush/exceptions'
74
+ require_relative 'rush/config'
75
+ require_relative 'rush/commands'
76
+ require_relative 'rush/access'
77
+ require_relative 'rush/entry'
78
+ require_relative 'rush/file'
79
+ require_relative 'rush/dir'
80
+ require_relative 'rush/search_results'
81
+ require_relative 'rush/head_tail'
82
+ require_relative 'rush/find_by'
83
+ require_relative 'rush/string_ext'
84
+ require_relative 'rush/fixnum_ext'
85
+ require_relative 'rush/array_ext'
86
+ require_relative 'rush/process'
87
+ require_relative 'rush/process_set'
88
+ require_relative 'rush/local'
89
+ require_relative 'rush/remote'
90
+ require_relative 'rush/box'
91
+ require_relative 'rush/embeddable_shell'
@@ -0,0 +1,121 @@
1
+ # A class to hold permissions (read, write, execute) for files and dirs.
2
+ # See Rush::Entry#access= for information on the public-facing interface.
3
+ #
4
+ class Rush::Access
5
+ ROLES = %w(user group other)
6
+ PERMISSIONS = %w(read write execute)
7
+ ACCESS_UNITS = ROLES.product(PERMISSIONS).
8
+ map { |r, p| "#{r}_can_#{p}".to_sym }
9
+
10
+ attr_accessor *ACCESS_UNITS
11
+
12
+ def self.roles
13
+ ROLES
14
+ end
15
+
16
+ def self.permissions
17
+ PERMISSIONS
18
+ end
19
+
20
+ def parse(options)
21
+ options.each do |key, value|
22
+ next unless m = key.to_s.match(/(.*)_can$/)
23
+ key = m[1].to_sym
24
+ roles = extract_list('role', key, self.class.roles)
25
+ perms = extract_list('permission', value, self.class.permissions)
26
+ set_matrix(perms, roles)
27
+ end
28
+ self
29
+ end
30
+
31
+ def self.parse(options)
32
+ new.parse(options)
33
+ end
34
+
35
+ def apply(full_path)
36
+ FileUtils.chmod(octal_permissions, full_path)
37
+ rescue Errno::ENOENT
38
+ raise Rush::DoesNotExist, full_path
39
+ end
40
+
41
+ def to_hash
42
+ ACCESS_UNITS.inject({}) do |hash, unit|
43
+ hash.merge(unit => send(unit) ? 1 : 0)
44
+ end
45
+ end
46
+
47
+ def display_hash
48
+ to_hash.select { |_, v| v == 1 }.
49
+ inject({}) { |r, (k, _)| r.merge k => true }
50
+ end
51
+
52
+ def from_hash(hash)
53
+ ACCESS_UNITS.each do |unit|
54
+ send("#{unit}=".to_sym, hash[unit].to_i == 1 ? true : false)
55
+ end
56
+ self
57
+ end
58
+
59
+ def self.from_hash(hash)
60
+ new.from_hash(hash)
61
+ end
62
+
63
+ def octal_permissions
64
+ perms = [ 0, 0, 0 ]
65
+ perms[0] += 4 if user_can_read
66
+ perms[0] += 2 if user_can_write
67
+ perms[0] += 1 if user_can_execute
68
+
69
+ perms[1] += 4 if group_can_read
70
+ perms[1] += 2 if group_can_write
71
+ perms[1] += 1 if group_can_execute
72
+
73
+ perms[2] += 4 if other_can_read
74
+ perms[2] += 2 if other_can_write
75
+ perms[2] += 1 if other_can_execute
76
+
77
+ eval("0" + perms.join)
78
+ end
79
+
80
+ def from_octal(mode)
81
+ perms = octal_integer_array(mode)
82
+
83
+ self.user_can_read = (perms[0] & 4) > 0 ? true : false
84
+ self.user_can_write = (perms[0] & 2) > 0 ? true : false
85
+ self.user_can_execute = (perms[0] & 1) > 0 ? true : false
86
+
87
+ self.group_can_read = (perms[1] & 4) > 0 ? true : false
88
+ self.group_can_write = (perms[1] & 2) > 0 ? true : false
89
+ self.group_can_execute = (perms[1] & 1) > 0 ? true : false
90
+
91
+ self.other_can_read = (perms[2] & 4) > 0 ? true : false
92
+ self.other_can_write = (perms[2] & 2) > 0 ? true : false
93
+ self.other_can_execute = (perms[2] & 1) > 0 ? true : false
94
+
95
+ self
96
+ end
97
+
98
+ def octal_integer_array(mode)
99
+ mode %= 01000 # filter out everything but the bottom three digits
100
+ mode = sprintf("%o", mode) # convert to string
101
+ mode.split("").map { |p| p.to_i } # and finally, array of integers
102
+ end
103
+
104
+ def set_matrix(perms, roles)
105
+ ROLES.product(PERMISSIONS).
106
+ select { |r, p| perms.include?(p) && roles.include?(r) }.
107
+ map { |r, p| "#{r}_can_#{p}=".to_sym }.
108
+ each { |unit| send unit, true }
109
+ end
110
+
111
+ def extract_list(type, value, choices)
112
+ list = parts_from(value)
113
+ list.each do |value|
114
+ raise(Rush::BadAccessSpecifier, "Unrecognized #{type}: #{value}") unless choices.include? value
115
+ end
116
+ end
117
+
118
+ def parts_from(value)
119
+ value.to_s.split('_').reject { |r| r == 'and' }
120
+ end
121
+ end