frontier 0.0.1 → 0.0.2
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.
- data/README.md +16 -5
- data/bin/frontier +1 -1
- data/lib/frontier.rb +1 -0
- data/lib/frontier/adapter.rb +15 -19
- data/lib/frontier/channel.rb +19 -14
- data/lib/frontier/mixin/filesystem.rb +2 -2
- data/lib/frontier/proxy.rb +8 -0
- data/lib/frontier/shell.rb +1 -3
- data/lib/frontier/utils.rb +29 -0
- data/lib/frontier/version.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -49,18 +49,29 @@ Example
|
|
49
49
|
-------
|
50
50
|
|
51
51
|
require 'frontier'
|
52
|
-
|
53
52
|
server = Frontier::Shell.new('user@server.tld')
|
54
53
|
|
54
|
+
# Run commands in the unix shell (bash or whatever you use)
|
55
55
|
puts server.uname
|
56
56
|
puts server.ls '*.rb'
|
57
|
-
|
58
|
-
|
59
|
-
puts server['*.rb'].last
|
60
|
-
|
57
|
+
|
58
|
+
# Find all ruby processes
|
61
59
|
server.load('process')
|
62
60
|
puts local.process.where(:command => /ruby/).fields(:pid, :rss).all
|
63
61
|
|
62
|
+
# Get a list of all *.rb files
|
63
|
+
server.load('filesystem')
|
64
|
+
puts server['*.rb']
|
65
|
+
|
66
|
+
# Recursively copy the ./config directory to the server
|
67
|
+
require 'pathname'
|
68
|
+
config = Pathname.new('./config/')
|
69
|
+
Frontier::Utils.xfer(server['destination/directory'], config)
|
70
|
+
|
71
|
+
# Copy file.txt from server to server2
|
72
|
+
server2 = Frontier::Shell.new('user@server2.tld')
|
73
|
+
Frontier::Utils.xfer(server2['.'], server['file.txt'])
|
74
|
+
|
64
75
|
|
65
76
|
References
|
66
77
|
----------
|
data/bin/frontier
CHANGED
data/lib/frontier.rb
CHANGED
data/lib/frontier/adapter.rb
CHANGED
@@ -5,7 +5,7 @@ module Frontier
|
|
5
5
|
|
6
6
|
def self.wrap(object)
|
7
7
|
case object
|
8
|
-
when Numeric, String, Exception
|
8
|
+
when NilClass, TrueClass, FalseClass, Symbol, Numeric, String, Exception
|
9
9
|
return object
|
10
10
|
when Array
|
11
11
|
return object.map { |o| wrap(o) }
|
@@ -16,27 +16,23 @@ module Frontier
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.process(object, rx, tx)
|
20
|
+
req = Marshal.load(rx)
|
21
|
+
object = ObjectSpace._id2ref(req[:object]) if req.key?(:object)
|
22
|
+
reply = object.send(req[:name], *req[:args])
|
23
|
+
Marshal.dump(Adapter.wrap(reply), tx)
|
24
|
+
rescue Exception => e
|
25
|
+
Marshal.dump(e, tx)
|
26
|
+
ensure
|
27
|
+
tx.flush
|
28
|
+
return reply
|
29
|
+
end
|
19
30
|
|
20
|
-
def initialize
|
21
|
-
@cache = {}
|
22
31
|
|
32
|
+
def initialize(rx, tx, cache = {})
|
23
33
|
while true do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if request[:object]
|
28
|
-
object = ObjectSpace._id2ref(request[:object])
|
29
|
-
else
|
30
|
-
object = self
|
31
|
-
end
|
32
|
-
|
33
|
-
reply = object.send(request[:name], *request[:args])
|
34
|
-
@cache[reply.object_id] = reply
|
35
|
-
Marshal.dump(Adapter.wrap(reply), $stdout)
|
36
|
-
rescue Exception => e
|
37
|
-
Marshal.dump(e, $stdout)
|
38
|
-
end
|
39
|
-
$stdout.flush
|
34
|
+
reply = Adapter.process(self, rx, tx)
|
35
|
+
cache[reply.object_id] = reply if reply
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
data/lib/frontier/channel.rb
CHANGED
@@ -3,27 +3,32 @@ module Frontier
|
|
3
3
|
|
4
4
|
class Channel
|
5
5
|
|
6
|
-
def self.hydrate(channel, object)
|
7
|
-
case object
|
8
|
-
when Array, Hash
|
9
|
-
object.each { |o| Channel.hydrate(channel, o) }
|
10
|
-
when Proxy
|
11
|
-
object.channel = channel
|
12
|
-
end
|
13
|
-
|
14
|
-
return object
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
6
|
def initialize(host, port)
|
19
|
-
@
|
7
|
+
@remote = "#{host}:#{port}"
|
8
|
+
@channel = IO.popen("ssh -p #{port} #{host} frontier", "r+")
|
20
9
|
end
|
21
10
|
|
22
11
|
def submit(request)
|
23
12
|
Marshal.dump(request, @channel)
|
24
|
-
return
|
13
|
+
return hydrate(Marshal.load(@channel))
|
25
14
|
end
|
26
15
|
|
16
|
+
def inspect
|
17
|
+
"#<Frontier::Channel #{@remote}>"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def hydrate(object)
|
23
|
+
case object
|
24
|
+
when Array, Hash
|
25
|
+
object.each { |o| hydrate(o) }
|
26
|
+
when Proxy
|
27
|
+
object.channel = self
|
28
|
+
end
|
29
|
+
|
30
|
+
return object
|
31
|
+
end
|
27
32
|
end
|
28
33
|
|
29
34
|
end
|
data/lib/frontier/proxy.rb
CHANGED
data/lib/frontier/shell.rb
CHANGED
@@ -4,12 +4,10 @@ module Frontier
|
|
4
4
|
class Shell
|
5
5
|
|
6
6
|
def initialize(host = 'localhost', port = 22)
|
7
|
-
@
|
8
|
-
@port = port
|
7
|
+
@channel = Channel.new(host, port)
|
9
8
|
end
|
10
9
|
|
11
10
|
def method_missing(name, *args)
|
12
|
-
@channel ||= Channel.new(@host, @port)
|
13
11
|
return @channel.submit({ :name => name, :args => args })
|
14
12
|
end
|
15
13
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Frontier
|
3
|
+
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
def self.xfer(dst, src)
|
7
|
+
if src.file?
|
8
|
+
dst = dst + src.basename.to_s if dst.directory?
|
9
|
+
copy(dst, src)
|
10
|
+
elsif src.directory?
|
11
|
+
src.children.each do |child|
|
12
|
+
xfer(dst + src.basename.to_s, child)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.copy(dst, src)
|
20
|
+
dst.dirname.mkpath
|
21
|
+
dst, src = dst.open("w+"), src.open("r")
|
22
|
+
while chunk = src.read(4096)
|
23
|
+
dst.write(chunk)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/frontier/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frontier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tomas Carnecky
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-06 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/frontier/mixin.rb
|
37
37
|
- lib/frontier/proxy.rb
|
38
38
|
- lib/frontier/shell.rb
|
39
|
+
- lib/frontier/utils.rb
|
39
40
|
- lib/frontier/version.rb
|
40
41
|
- lib/frontier.rb
|
41
42
|
- LICENSE
|