frontier 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
- server.load('filesystem')
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
@@ -3,4 +3,4 @@
3
3
  require 'rubygems'
4
4
  require 'frontier'
5
5
 
6
- Frontier::Adapter.new
6
+ Frontier::Adapter.new($stdin, $stdout)
data/lib/frontier.rb CHANGED
@@ -6,6 +6,7 @@ module Frontier
6
6
  autoload :Mixin, 'frontier/mixin'
7
7
  autoload :Proxy, 'frontier/proxy'
8
8
  autoload :Shell, 'frontier/shell'
9
+ autoload :Utils, 'frontier/utils'
9
10
  autoload :Version, 'frontier/version'
10
11
 
11
12
  end
@@ -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
- begin
25
- request = Marshal.load($stdin)
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
 
@@ -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
- @channel = IO.popen("ssh #{host} frontier", "r+")
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 Channel.hydrate(self, Marshal.load(@channel))
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
@@ -3,8 +3,8 @@ require 'pathname'
3
3
 
4
4
  module Frontier::Mixin::Filesystem
5
5
 
6
- def [](glob)
7
- Pathname.glob(glob)
6
+ def [](str)
7
+ str.include?('*') ? Pathname.glob(str) : Pathname.new(str)
8
8
  end
9
9
 
10
10
  end
@@ -14,6 +14,14 @@ module Frontier
14
14
  return @channel.submit(request)
15
15
  end
16
16
 
17
+ def to_s
18
+ method_missing(:to_s)
19
+ end
20
+
21
+ def inspect
22
+ "#<Frontier::Proxy #{method_missing(:inspect)}>"
23
+ end
24
+
17
25
  end
18
26
 
19
27
  end
@@ -4,12 +4,10 @@ module Frontier
4
4
  class Shell
5
5
 
6
6
  def initialize(host = 'localhost', port = 22)
7
- @host = host
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
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Frontier
3
3
 
4
- Version = '0.0.1'
4
+ Version = '0.0.2'
5
5
 
6
6
  end
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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-10-31 01:00:00 +02:00
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