mobot 2013.08.1377443265 → 2013.08.1377443804

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac2b523410987c4402b45f280f4827c8657e6f57
4
- data.tar.gz: 8c7675e32e39fbfa1d6b9053dda31b2a5ee70f4a
3
+ metadata.gz: 4e7b6925b1110d96af50652e9cce69d0d682e7b6
4
+ data.tar.gz: 6edb85ed86783b5d57cf5273bbc201559f5dd9ff
5
5
  SHA512:
6
- metadata.gz: e4f97fabaaf1b4910b11f8c4f61368f39c0222b609be3859cc0d6bd9fcf87ddde895c93a78c0195c5e11d21b009ebec4c93bfb75833b1f30448cef34fe557d97
7
- data.tar.gz: 181b5fa85c2f0d4e798924b0e12d058044a9dcf60fcf182ad489224660f5b9cdaceea42c8f8911f873008f64cfdde5f0527067231e0fe144c96cd9fe8080f299
6
+ metadata.gz: b2703b747c09378b3d3c864e1e262a46f3fd7178aa5457a34d674eef6de99c9db150c0b7aaa365548e61502ea8128dd493fd9ad69fd79458480625801249c819
7
+ data.tar.gz: 78b93c693b2218c18e520e6bb65eeb667a44724cdcca329c084d35917977b8a8a7f4fd2d2ee57145337cb2bd25e4352f72803903c94e7e6b4100df09b29edc23
@@ -0,0 +1 @@
1
+ mobot
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mobot'
3
+
4
+ Mobot::Client.run(ARGV[0])
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mobot'
3
+ Mobot::Server.start
@@ -1,4 +1,6 @@
1
1
  require "mobot/version"
2
+ require "mobot/server"
3
+ require "mobot/client"
2
4
 
3
5
  module Mobot
4
6
  # Your code goes here...
@@ -0,0 +1,13 @@
1
+ require "socket"
2
+
3
+ module Mobot
4
+ class Client
5
+ SOCKET_FILE = '/tmp/mobot.sock'
6
+ def self.run(command = ARGV[0])
7
+ socket = UNIXSocket.new(SOCKET_FILE)
8
+ socket.write(command)
9
+ socket.close_write
10
+ puts socket.read
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ require "socket"
2
+
3
+ module Mobot
4
+ class Server
5
+ SOCKET_FILE = '/tmp/mobot.sock'
6
+ def self.start
7
+ lock_file = File.open('/tmp/mobot.lock', 'w')
8
+
9
+ if lock_file.flock(File::LOCK_EX | File::LOCK_NB)
10
+ server = UNIXServer.new(SOCKET_FILE)
11
+
12
+ parent_process_id = Process.pid
13
+ at_exit do
14
+ File.unlink(SOCKET_FILE) if Process.pid == parent_process_id
15
+ end
16
+
17
+ trap(:INT) { exit }
18
+
19
+ puts "mobot reporting for duty"
20
+
21
+ loop do
22
+ client = server.accept
23
+ command = client.read
24
+
25
+ pid = fork do
26
+ $stdout.reopen(client)
27
+ puts "mobot received command: #{command}"
28
+ begin
29
+ exec(command)
30
+ rescue Exception => e
31
+ puts "something very bad happended. #{e.message}"
32
+ end
33
+ end
34
+
35
+ Process.wait(pid)
36
+ client.close
37
+ end
38
+ else
39
+ # exit
40
+ p "there can only be one. bye bye."
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 2013.08.1377443265
4
+ version: 2013.08.1377443804
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
@@ -42,19 +42,23 @@ description: a simple robot
42
42
  email:
43
43
  - mo@mokhan.ca
44
44
  executables:
45
- - mobot-server.rb
46
- - mobot.rb
45
+ - mobot
46
+ - mobot-server
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
50
  - .gitignore
51
+ - .ruby-gemset
52
+ - .ruby-version
51
53
  - Gemfile
52
54
  - LICENSE.txt
53
55
  - README.md
54
56
  - Rakefile
55
- - bin/mobot-server.rb
56
- - bin/mobot.rb
57
+ - bin/mobot
58
+ - bin/mobot-server
57
59
  - lib/mobot.rb
60
+ - lib/mobot/client.rb
61
+ - lib/mobot/server.rb
58
62
  - lib/mobot/version.rb
59
63
  - mobot.gemspec
60
64
  homepage: ''
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require "socket"
3
-
4
- SOCKET_FILE = '/tmp/mobot.sock'
5
-
6
- lock_file = File.open('/tmp/mobot.lock', 'w')
7
-
8
- if lock_file.flock(File::LOCK_EX | File::LOCK_NB)
9
- server = UNIXServer.new(SOCKET_FILE)
10
-
11
- parent_process_id = Process.pid
12
- at_exit do
13
- File.unlink(SOCKET_FILE) if Process.pid == parent_process_id
14
- end
15
-
16
- trap(:INT) { exit }
17
-
18
- puts "mobot reporting for duty"
19
-
20
- loop do
21
- client = server.accept
22
- command = client.read
23
-
24
- pid = fork do
25
- $stdout.reopen(client)
26
- puts "mobot received command: #{command}"
27
- begin
28
- exec(command)
29
- rescue Exception => e
30
- puts "something very bad happended. #{e.message}"
31
- end
32
- end
33
-
34
- Process.wait(pid)
35
- client.close
36
- end
37
- else
38
- # exit
39
- p "there can only be one. bye bye."
40
- end
41
-
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require "socket"
3
-
4
- SOCKET_FILE = '/tmp/mobot.sock'
5
- command = ARGV[0]
6
- socket = UNIXSocket.new(SOCKET_FILE)
7
- socket.write(command)
8
- socket.close_write
9
- puts socket.read