rupi 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rupi_service ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rupi'
5
+ require 'daemons'
6
+ require 'yaml'
7
+
8
+ include Rupi
9
+
10
+ def sudome
11
+ return if ENV["USER"] == 'root'
12
+ exec("rvmsudo #{ENV['_']} #{ARGV.join(' ')}")
13
+ end
14
+
15
+ if ARGV[0] == 'install'
16
+ file_name = ARGV[1]
17
+
18
+ if file_name.nil?
19
+ puts "please specify a rupi script to run"
20
+ exit(1)
21
+ end
22
+
23
+ file_name = File.absolute_path(file_name)
24
+
25
+ unless File.exist?(file_name)
26
+ puts "#{file_name} not found"
27
+ exit(1)
28
+ end
29
+
30
+ sudome
31
+
32
+ File.open('/etc/rupi_service.yml', 'w') do |config|
33
+ config.write(YAML::dump('path' => file_name))
34
+ end
35
+
36
+ system('rvm wrapper 1.9.3 init rupi_service')
37
+ system('mv `which init_rupi_service` /etc/init.d/rupi_service')
38
+ system('update-rc.d rupi_service defaults')
39
+ system('/etc/init.d/rupi_service restart')
40
+ exit
41
+ end
42
+
43
+
44
+ Daemons.run_proc('rupi_service') do
45
+ config = YAML.load(File.read('/etc/rupi_service.yml'))
46
+ file_name = config['path']
47
+ update_at = nil
48
+ run_thread = nil
49
+
50
+ loop do
51
+ new_updated_at = File.mtime(file_name).to_i
52
+
53
+ if new_updated_at != update_at
54
+ Rupi::Pin.unwatch(:all)
55
+ Rupi::Pin.stop_watching
56
+ Rupi::Pin.join_watch_thread
57
+ run_thread.terminate if run_thread
58
+
59
+ run_thread = Thread.new { load(file_name) }
60
+
61
+ update_at = new_updated_at
62
+ end
63
+
64
+ sleep 1
65
+ end
66
+ end
data/lib/rupi/pin.rb CHANGED
@@ -64,6 +64,15 @@ module Rupi
64
64
  start_watching
65
65
  end
66
66
 
67
+ def self.unwatch(pin)
68
+ return unless @watched_pins
69
+ if pin == :all
70
+ @watched_pins.clear
71
+ else
72
+ @watched_pins.delete(pin)
73
+ end
74
+ end
75
+
67
76
  def self.start_watching
68
77
  @watching = true
69
78
 
@@ -88,6 +97,7 @@ module Rupi
88
97
 
89
98
  def self.stop_watching
90
99
  @watching = false
100
+ join_watch_thread
91
101
  end
92
102
 
93
103
  def self.watching?
@@ -95,6 +105,7 @@ module Rupi
95
105
  end
96
106
 
97
107
  def self.join_watch_thread
108
+ return unless @watch_thread
98
109
  @watch_thread.join
99
110
  end
100
111
 
data/lib/rupi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rupi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rupi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-30 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: wiringpi
@@ -27,15 +27,49 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: daemons
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
30
62
  description: A avery simple ruby library for Raspberry Pi GPIO
31
63
  email:
32
64
  - mick@staugaard.com
33
65
  executables:
34
66
  - rupi
67
+ - rupi_service
35
68
  extensions: []
36
69
  extra_rdoc_files: []
37
70
  files:
38
71
  - bin/rupi
72
+ - bin/rupi_service
39
73
  - lib/rupi/pin.rb
40
74
  - lib/rupi/version.rb
41
75
  - lib/rupi.rb
@@ -52,12 +86,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
86
  - - ! '>='
53
87
  - !ruby/object:Gem::Version
54
88
  version: '0'
89
+ segments:
90
+ - 0
91
+ hash: 3089349428251366121
55
92
  required_rubygems_version: !ruby/object:Gem::Requirement
56
93
  none: false
57
94
  requirements:
58
95
  - - ! '>='
59
96
  - !ruby/object:Gem::Version
60
97
  version: '0'
98
+ segments:
99
+ - 0
100
+ hash: 3089349428251366121
61
101
  requirements: []
62
102
  rubyforge_project:
63
103
  rubygems_version: 1.8.24