arbi 1.0.8.4 → 1.0.8.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,7 +32,9 @@ class Server
32
32
 
33
33
  self.parse_args
34
34
 
35
- Arbi::Server.start(@address, @port)
35
+ EventMachine.run {
36
+ Arbi::Server.start(@address, @port)
37
+ }
36
38
  end
37
39
 
38
40
  protected
@@ -40,7 +40,7 @@ class Client
40
40
  def get(what = 'help')
41
41
  @sock.print "#{what.strip}\r\n"
42
42
  @sock.flush
43
- JSON.parse(@sock.gets.strip)
43
+ JSON.parse(@sock.gets.strip, create_additions: true)
44
44
  rescue Errno::EPIPE
45
45
  self.connect
46
46
  retry
@@ -39,6 +39,9 @@ class Config < Hash
39
39
  config[:server] ||= {}
40
40
  config[:server][:address] ||= '127.0.0.1'
41
41
  config[:server][:port] ||= 6969
42
+ config[:server][:acpi] ||= {}
43
+ config[:server][:acpi][:listen] ||= '/var/run/acpid.socket'
44
+ config[:server][:acpi][:bind] ||= '/var/run/arbid.socket'
42
45
  config[:client] ||= {}
43
46
  config[:client][:address] ||= '127.0.0.1'
44
47
  config[:client][:port] ||= 6969
@@ -57,12 +60,29 @@ class Config < Hash
57
60
  end
58
61
 
59
62
  class << self
63
+ alias __method_missing__ method_missing
64
+ def method_missing(sym, *args, &blk)
65
+ if self.instance.respond_to?(sym)
66
+ self.instance.send(sym, *args, &blk)
67
+ else
68
+ self.__method_missing__(sym, *args, &blk)
69
+ end
70
+ end
71
+
60
72
  def [](*args)
61
- self.instance.[](*args)
73
+ self.instance.send(:[], *args)
74
+ end
75
+
76
+ def []=(*args)
77
+ self.instance.send(:[]=, *args)
78
+ end
79
+
80
+ def inspect
81
+ self.instance.inspect
62
82
  end
63
83
 
64
- def parse(*args)
65
- self.instance.parse(*args)
84
+ def to_s
85
+ self.instance.to_s
66
86
  end
67
87
  end
68
88
  end
@@ -39,7 +39,7 @@ class Diskstat < Module
39
39
  diskstat = Sys::Filesystem.stat(device[:point])
40
40
  device.merge!({
41
41
  usage: "#{100 - (100.0 / diskstat.blocks * diskstat.blocks_available).round}%",
42
- space: self.unitize(diskstat.blocks * diskstat.fragment_size)
42
+ space: self.unitize(diskstat.blocks * diskstat.block_size)
43
43
  })
44
44
 
45
45
  @data << device
@@ -63,8 +63,8 @@ protected
63
63
  end
64
64
 
65
65
  def unitize misure
66
- u = 'b'
67
- %w(Kb Mb Gb Tb).each {|i|
66
+ u = 'B'
67
+ %w(kB MB GB TB).each {|i|
68
68
  if misure >= 1024
69
69
  misure /= 1024.0
70
70
  u = i
@@ -19,6 +19,24 @@
19
19
 
20
20
  require 'socket'
21
21
 
22
+ module Wireless
23
+ def self.quality(ifname)
24
+ File.read('/proc/net/wireless').match(/^\s*#{Regexp.escape(ifname)}:.*$/)[0].strip.split(/:?\s+/)[2].gsub('.', '') + "%"
25
+ rescue
26
+ nil
27
+ end
28
+
29
+ def self.essid (ifname)
30
+ iwreq = [ifname, " " * 32, 32, 0].pack("a16pII")
31
+ sock = ::Socket.new(:INET, :DGRAM, 0)
32
+ sock.ioctl(0x8B1B, iwreq)
33
+ return iwreq.unpack("a16pII")[1].strip
34
+ rescue Exception => e
35
+ Arbi.debug(e.backtrace[0] + ': ' + e.to_s + "\n" + e.backtrace[1..-1].join("\n"))
36
+ nil
37
+ end
38
+ end
39
+
22
40
  module Arbi
23
41
 
24
42
  module Modules
@@ -72,8 +90,8 @@ protected
72
90
  }
73
91
 
74
92
  if stats[name][:state]
75
- stats[name][:quality] = quality(name)
76
- stats[name][ :essid ] = essid(name) if stats[name][:quality]
93
+ stats[name][:quality] = Wireless.quality(name)
94
+ stats[name][ :essid ] = Wireless.essid(name) if stats[name][:quality]
77
95
  end
78
96
 
79
97
  @prev[ :up ][name] = up
@@ -85,21 +103,6 @@ protected
85
103
  Arbi.debug(e.to_s)
86
104
  end
87
105
 
88
- def quality(interface)
89
- File.read('/proc/net/wireless').match(/^\s*#{Regexp.escape(interface)}:.*$/)[0].strip.split(/:?\s+/)[2].gsub('.', '') + "%"
90
- rescue
91
- nil
92
- end
93
-
94
- def essid(interface)
95
- iwreq = [interface, " " * 32, 32, 0].pack("a16pII")
96
- sock = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
97
- sock.ioctl(0x8B1B, iwreq)
98
- return iwreq.unpack("a16pII")[1].strip
99
- rescue
100
- nil
101
- end
102
-
103
106
  def datas=(stats)
104
107
  @mutex.synchronize {
105
108
  @datas = []
@@ -24,26 +24,67 @@ module Arbi
24
24
  module Modules
25
25
 
26
26
  class Ram < Arbi::Modules::Module
27
+ begin
28
+ require 'Win32API'
29
+
30
+ class MEMORYSTATUS < Struct.new(:dwLength, :dwMemoryLoad, :dwTotalPhys, :dwAvailPhys, :dwTotalPageFile, :dwAvailPageFile, :dwTotalVirtual, :dwAvailVritualPhys)
31
+ end
32
+
33
+ def valid?
34
+ true
35
+ end
36
+
37
+ def usage
38
+ self.status.dwMemoryLoad
39
+ end
40
+
41
+ def total
42
+ self.status.dwTotalPageFile.to_i
43
+ end
44
+
45
+ def status
46
+ @__status__ ||= Win32API.new('kernel32', 'GlobalMemoryStatus', 'P', 'V')
47
+ x = ([1] * 8).pack('LLIIIIII')
48
+ @__status__.call(x)
49
+ x = MEMORYSTATUS.new(*x.unpack('LLIIIIII'))
50
+ x.dwMemoryLoad = 100.0 - 100.0 / x.dwTotalPageFile * x.dwAvailPageFile
51
+ x
52
+ end
53
+ rescue LoadError
27
54
  include Arbi::Modules::Acpi::Utils
28
55
 
29
56
  def valid?
30
57
  File.exist?('/proc/meminfo')
31
58
  end
32
59
 
60
+ def usage
61
+ stat = self.status
62
+ 100.0 - 100.0 / stat[:memtotal] * (stat[:memfree] + stat[:buffers] + stat[:cached])
63
+ end
64
+
65
+ def total
66
+ self.status[:memtotal].to_i
67
+ end
68
+
69
+ def status
70
+ hashize('/proc/meminfo')
71
+ end
72
+ end
73
+
33
74
  def refresh
34
75
  @data = []
35
76
 
36
- mem = hashize('/proc/meminfo')
37
- perc = 100.0 / mem[:memtotal] * (mem[:memfree] + mem[:buffers] + mem[:cached])
77
+ usage = self.usage
38
78
 
39
79
  @data = [
40
- ("%.1f%%" % [100.0 - perc]),
41
- ("%.1f%%" % [perc])
80
+ ("%.1f%%" % [usage]),
81
+ ("%.1f%%" % [100.0 - usage]),
82
+ self.total
42
83
  ]
43
84
  end
44
85
 
45
86
  def format
46
- tablize([['USED', 'FREE'], @data])
87
+ tablize([['USED', 'FREE', 'SIZE'], @data])
47
88
  end
48
89
  end
49
90
 
@@ -29,7 +29,7 @@ class Version < Module
29
29
  end
30
30
 
31
31
  def refresh
32
- @data = Arbi::VERSION
32
+ @data ||= Arbi::VERSION
33
33
  end
34
34
 
35
35
  def format
@@ -52,15 +52,18 @@ class Server
52
52
  end
53
53
 
54
54
  def start
55
- EventMachine.run {
56
- TimeLine.run
57
- EventMachine.start_server(@address, @port, Arbi::Server::Server)
58
- Arbi.debug("Starting server on #{@address}:#{@port}")
59
- }
55
+ EventMachine.epoll = true if EventMachine.epoll?
56
+ EventMachine.kqueue = true if EventMachine.kqueue?
57
+ TimeLine.run
58
+ EventMachine.start_server(@address, @port, Arbi::Server::Server)
59
+ Arbi.debug("Starting server on #{@address}:#{@port}")
60
+ nil
60
61
  end
61
62
 
62
63
  def self.start(address = '127.0.0.1', port = 6969)
63
- self.new(address, port).start
64
+ self.new(address, port).tap {|s|
65
+ s.start
66
+ }
64
67
  end
65
68
  end
66
69
 
@@ -46,24 +46,34 @@ module TimeLine
46
46
  raise ArgumentError, "proc must be a Proc" unless blk.is_a?(Proc)
47
47
  @proc = blk
48
48
  end
49
+
50
+ def run
51
+ EventMachine::PeriodicTimer.new(self.every) {
52
+ ::Timeout.timeout(self.timeout) {
53
+ self.proc.call
54
+ }
55
+ }
56
+ end
49
57
  end
50
58
 
51
59
  class << self
60
+ def running?
61
+ @running ||= false
62
+ end
63
+
52
64
  def register(job)
53
65
  raise ArgumentError, "job must be a TimeLine::Job" unless job.is_a?(TimeLine::Job)
54
66
  @@jobs ||= []
67
+ job.run if running?
55
68
  @@jobs << job
56
69
  end
57
70
 
58
71
  def run
59
72
  @@jobs ||= []
60
73
  @@jobs.each {|job|
61
- EventMachine::PeriodicTimer.new(job.every) do
62
- timeout(job.timeout) {
63
- job.proc.call
64
- }
65
- end
74
+ job.run
66
75
  }
76
+ @running = true
67
77
  self
68
78
  end
69
79
  end
@@ -19,5 +19,5 @@
19
19
 
20
20
 
21
21
  module Arbi
22
- VERSION = '1.0.8.4'
22
+ VERSION = '1.0.8.6'
23
23
  end
metadata CHANGED
@@ -1,131 +1,123 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: arbi
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 8
9
- - 4
10
- version: 1.0.8.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8.6
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - shura
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-14 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: sys-filesystem
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: eventmachine
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: eventmachine
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
45
38
  type: :runtime
46
- version_requirements: *id002
47
- - !ruby/object:Gem::Dependency
48
- name: json
49
39
  prerelease: false
50
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
51
41
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
58
54
  type: :runtime
59
- version_requirements: *id003
60
- description: ""
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ''
61
63
  email: shura1991@gmail.com
62
- executables:
64
+ executables:
63
65
  - arbid
64
66
  - arbi
65
67
  extensions: []
66
-
67
68
  extra_rdoc_files: []
68
-
69
- files:
70
- - lib/arbi.rb
71
- - lib/arbi/modules.rb
72
- - lib/arbi/timeline.rb
73
- - lib/arbi/server.rb
74
- - lib/arbi/cli/server.rb
69
+ files:
75
70
  - lib/arbi/cli/client.rb
76
- - lib/arbi/utils/table.rb
77
- - lib/arbi/utils/numeric.rb
71
+ - lib/arbi/cli/server.rb
78
72
  - lib/arbi/client.rb
73
+ - lib/arbi/modules.rb
79
74
  - lib/arbi/version.rb
80
- - lib/arbi/modules/adapter.rb
75
+ - lib/arbi/config.rb
76
+ - lib/arbi/server.rb
77
+ - lib/arbi/timeline.rb
81
78
  - lib/arbi/modules/net.rb
82
- - lib/arbi/modules/ram.rb
83
- - lib/arbi/modules/cpu.rb
84
- - lib/arbi/modules/sys/adapter.rb
85
- - lib/arbi/modules/sys/thermal.rb
86
- - lib/arbi/modules/sys/battery.rb
87
- - lib/arbi/modules/thermal.rb
88
79
  - lib/arbi/modules/version.rb
89
- - lib/arbi/modules/help.rb
90
- - lib/arbi/modules/battery.rb
80
+ - lib/arbi/modules/thermal.rb
91
81
  - lib/arbi/modules/diskstat.rb
82
+ - lib/arbi/modules/adapter.rb
92
83
  - lib/arbi/modules/acpi/adapter.rb
93
84
  - lib/arbi/modules/acpi/utils.rb
94
85
  - lib/arbi/modules/acpi/battery.rb
95
- - lib/arbi/config.rb
86
+ - lib/arbi/modules/help.rb
87
+ - lib/arbi/modules/sys/thermal.rb
88
+ - lib/arbi/modules/sys/adapter.rb
89
+ - lib/arbi/modules/sys/battery.rb
90
+ - lib/arbi/modules/cpu.rb
91
+ - lib/arbi/modules/battery.rb
92
+ - lib/arbi/modules/ram.rb
93
+ - lib/arbi/utils/numeric.rb
94
+ - lib/arbi/utils/table.rb
95
+ - lib/arbi.rb
96
96
  - bin/arbid
97
97
  - bin/arbi
98
- has_rdoc: true
99
98
  homepage: http://github.com/shurizzle/arbi
100
99
  licenses: []
101
-
102
100
  post_install_message:
103
101
  rdoc_options: []
104
-
105
- require_paths:
102
+ require_paths:
106
103
  - lib
107
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
108
105
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- segments:
113
- - 0
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
111
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- segments:
121
- - 0
122
- version: "0"
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
123
116
  requirements: []
124
-
125
117
  rubyforge_project:
126
- rubygems_version: 1.3.7
118
+ rubygems_version: 1.8.23
127
119
  signing_key:
128
120
  specification_version: 3
129
- summary: ""
121
+ summary: ''
130
122
  test_files: []
131
-
123
+ has_rdoc: true