dock_driver 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.pryrc +10 -0
- data/History.rdoc +52 -0
- data/Manifest.txt +9 -10
- data/{README.txt → README.rdoc} +0 -5
- data/Rakefile +27 -3
- data/TODO.rdoc +11 -0
- data/bin/dock_driver +18 -77
- data/data/example.dock_driver.yml +15 -146
- data/lib/dock_driver/dock.rb +116 -165
- data/lib/dock_driver/dock_item.rb +47 -0
- data/lib/dock_driver/dzen2.rb +5 -0
- data/lib/dock_driver/i3.rb +80 -0
- data/lib/dock_driver/mixins.rb +33 -0
- data/lib/dock_driver/workspace_pager.rb +5 -0
- data/lib/dock_driver.rb +79 -13
- data.tar.gz.sig +0 -0
- metadata +20 -21
- metadata.gz.sig +0 -0
- data/.hgignore +0 -2
- data/History.txt +0 -37
- data/Ideas.txt +0 -19
- data/lib/dock_driver/data_rate_poll.rb +0 -136
- data/lib/dock_driver/hashutils.rb +0 -79
- data/lib/dock_driver/poll.rb +0 -90
- data/spec/dock_driver/dock_spec.rb +0 -36
- data/spec/dock_driver/poll_spec.rb +0 -45
- data/spec/dock_driver_spec.rb +0 -17
data/.pryrc
ADDED
data/History.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= History
|
2
|
+
|
3
|
+
=== 0.2.0 / 2012-11-21
|
4
|
+
|
5
|
+
* 1 major enhancement
|
6
|
+
* A complete rewrite.
|
7
|
+
* Basic functionality is complete.
|
8
|
+
* The namespace has been re-arranged and made more general.
|
9
|
+
* Uses Configurability and Loggability gems.
|
10
|
+
* OptionParser has been replaced by Trollop.
|
11
|
+
* Support for INT and HUP signals.
|
12
|
+
* Dock now waits for DockItems to notify it before creating output.
|
13
|
+
* Dock now lazily executes the dock command.
|
14
|
+
* Dock no longer sets sync on the pipe which sometimes made dzen2 exit uncleanly.
|
15
|
+
|
16
|
+
=== 0.1.2 / 2012-08-22
|
17
|
+
|
18
|
+
* 1 minor enhancement
|
19
|
+
* the signal handler for INT now exits.
|
20
|
+
|
21
|
+
=== 0.1.1 / 2012-05-20
|
22
|
+
|
23
|
+
* 2 minor enhancements
|
24
|
+
* logging
|
25
|
+
* bug fixes
|
26
|
+
|
27
|
+
=== 0.1.0 / 2012-05-15
|
28
|
+
|
29
|
+
* 3 minor enhancements
|
30
|
+
|
31
|
+
* bin/dock_driver completed
|
32
|
+
* RSpec tests completed & passing
|
33
|
+
* Several bugs fixed
|
34
|
+
|
35
|
+
=== 0.0.3 / 2012-05-15
|
36
|
+
|
37
|
+
* 1 minor enhancement
|
38
|
+
|
39
|
+
* Doc & Manifest Updates
|
40
|
+
|
41
|
+
=== 0.0.2 / 2012-05-15
|
42
|
+
|
43
|
+
* 1 minor enhancement
|
44
|
+
|
45
|
+
* 100% documentation coverage
|
46
|
+
|
47
|
+
=== 0.0.1 / 2012-05-15
|
48
|
+
|
49
|
+
* 1 major enhancement
|
50
|
+
|
51
|
+
* Birthday!
|
52
|
+
|
data/Manifest.txt
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
.autotest
|
2
|
-
.
|
3
|
-
History.
|
4
|
-
Ideas.txt
|
2
|
+
.pryrc
|
3
|
+
History.rdoc
|
5
4
|
Manifest.txt
|
6
|
-
README.
|
5
|
+
README.rdoc
|
7
6
|
Rakefile
|
7
|
+
TODO.rdoc
|
8
8
|
bin/dock_driver
|
9
9
|
data/example.dock_driver.yml
|
10
10
|
lib/dock_driver.rb
|
11
|
-
lib/dock_driver/hashutils.rb
|
12
|
-
lib/dock_driver/poll.rb
|
13
|
-
lib/dock_driver/data_rate_poll.rb
|
14
11
|
lib/dock_driver/dock.rb
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
lib/dock_driver/dock_item.rb
|
13
|
+
lib/dock_driver/dzen2.rb
|
14
|
+
lib/dock_driver/i3.rb
|
15
|
+
lib/dock_driver/mixins.rb
|
16
|
+
lib/dock_driver/workspace_pager.rb
|
data/{README.txt → README.rdoc}
RENAMED
@@ -17,8 +17,6 @@ started. It's located in this gem's data directory, which is usually:
|
|
17
17
|
|
18
18
|
* easy, flexible configuration
|
19
19
|
* sholud the configuration change, the dock will be automatically restarted
|
20
|
-
* field extraction with +scan_regex+ (no grep or pipes necessary)
|
21
|
-
* automatic running average of data rates
|
22
20
|
|
23
21
|
See 'Ideas' for more info on what's planned for the future.
|
24
22
|
|
@@ -32,9 +30,6 @@ See 'Ideas' for more info on what's planned for the future.
|
|
32
30
|
|
33
31
|
There really isn't an API or interface other than the YAML config file.
|
34
32
|
|
35
|
-
See the +--help+ option for more information on how to use the
|
36
|
-
+dock_config+ binary.
|
37
|
-
|
38
33
|
== REQUIREMENTS:
|
39
34
|
|
40
35
|
* This gem proudly has zero dependencies.
|
data/Rakefile
CHANGED
@@ -5,8 +5,32 @@ require 'hoe'
|
|
5
5
|
Hoe.plugin :mercurial
|
6
6
|
|
7
7
|
Hoe.spec 'dock_driver' do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
self.readme_file = 'README.rdoc'
|
9
|
+
self.history_file = 'History.rdoc'
|
10
|
+
self.extra_rdoc_files = FileList[ '*.rdoc' ]
|
11
|
+
self.developer 'Michael Hix', 'mike@musl.org'
|
12
|
+
self.require_ruby_version '>= 1.8.7'
|
13
|
+
self.require_rubygems_version '>= 1.8'
|
11
14
|
end
|
12
15
|
|
16
|
+
# This task is probably a bad idea but I'm doing it until the project settles
|
17
|
+
# down.
|
18
|
+
desc "Build Manifest.txt automatically, respecting .hgignore."
|
19
|
+
task :manifest do
|
20
|
+
return unless File.exist?( '.hgignore' )
|
21
|
+
|
22
|
+
ignore = Regexp.union(
|
23
|
+
/^\.(hg|rvm)/,
|
24
|
+
*File.readlines( '.hgignore' ).map { |l| l.chomp }
|
25
|
+
)
|
26
|
+
|
27
|
+
manifest = []
|
28
|
+
|
29
|
+
Dir.glob( [ '**/*', '**/.*' ] ).sort.each do |file|
|
30
|
+
next if File.directory?( file )
|
31
|
+
next if file =~ ignore
|
32
|
+
manifest << file
|
33
|
+
end
|
34
|
+
|
35
|
+
File.write( 'Manifest.txt', manifest.join( "\n" ) + "\n" )
|
36
|
+
end
|
data/TODO.rdoc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
= TODO
|
2
|
+
== Important Features
|
3
|
+
* Color & full Dzen2 escape support. (DockDriver::Dzen2)
|
4
|
+
* DockDriver::WorkspacePager
|
5
|
+
* DockItem output scanning
|
6
|
+
* DockItem data rate support
|
7
|
+
== Ideas
|
8
|
+
* DockItem plugins
|
9
|
+
* Multiple Dock support
|
10
|
+
* DockItems with rotating output
|
11
|
+
* Notifications / Slave window support
|
data/bin/dock_driver
CHANGED
@@ -1,90 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
# encoding: utf-8
|
4
|
-
#
|
5
2
|
|
6
|
-
require '
|
7
|
-
require 'dock_driver
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dock_driver'
|
5
|
+
require 'trollop'
|
8
6
|
|
9
7
|
include Signal
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
p.on(
|
15
|
-
'-c',
|
16
|
-
'--conf FILE',
|
17
|
-
"Specify an alternate config file. (Default: #{DockDriver::Dock::DEFAULT_CONFIG_FILE})"
|
18
|
-
) do |file|
|
19
|
-
unless File.exists? file
|
20
|
-
$stderr.puts "That config file doesn't exist." % file
|
21
|
-
$stderr.puts
|
22
|
-
$stderr.puts p
|
23
|
-
exit
|
24
|
-
end
|
25
|
-
opts[:conf] = file
|
26
|
-
end
|
27
|
-
|
28
|
-
p.on(
|
29
|
-
'-l',
|
30
|
-
'--log FILE',
|
31
|
-
"Specify an alternate log file. (Default: #{DockDriver::Dock::DEFAULT_LOG_FILE})"
|
32
|
-
) do |log|
|
33
|
-
if File.exists? log
|
34
|
-
$stderr.puts "That log file exists, and I'm cowardly refusing to overwrite it." % log
|
35
|
-
$stderr.puts
|
36
|
-
$stderr.puts p
|
37
|
-
exit
|
38
|
-
end
|
39
|
-
opts[:log] = log
|
40
|
-
end
|
41
|
-
|
42
|
-
p.on(
|
43
|
-
'-d',
|
44
|
-
'--dock COMMAND',
|
45
|
-
'Override the dock command from the config file.'
|
46
|
-
) do |command|
|
47
|
-
opts[:dock] = command
|
48
|
-
end
|
49
|
-
|
50
|
-
p.on( '-e', '--debug', 'Enable $DEBUG' ) { |debug| $DEBUG = true }
|
51
|
-
|
52
|
-
p.on( '-h', '--help', 'Print this help text.' ) do
|
53
|
-
cmd = File.basename( $0 )
|
54
|
-
$stderr.puts "\n%s\n%s\n\nVersion: %s\n%s\n\n" % [
|
55
|
-
cmd,
|
56
|
-
'=' * cmd.length,
|
57
|
-
DockDriver::VERSION,
|
58
|
-
DockDriver::REVISION,
|
59
|
-
]
|
60
|
-
$stderr.puts p
|
61
|
-
$stderr.puts "\nAuthors:\n\t%s\n\n" % [
|
62
|
-
DockDriver::AUTHORS.join( '\n\t' ),
|
63
|
-
]
|
64
|
-
exit
|
65
|
-
end
|
9
|
+
extend Loggability
|
10
|
+
log_to :dock_driver
|
66
11
|
|
12
|
+
opts = Trollop.options do
|
13
|
+
opt :config,
|
14
|
+
"Specify an alternate config file.",
|
15
|
+
:default => DockDriver::USER_CONFIG_FILE.expand_path.to_s
|
67
16
|
end
|
68
17
|
|
69
|
-
|
70
|
-
#
|
71
|
-
begin
|
72
|
-
parser.parse!
|
73
|
-
rescue => e
|
74
|
-
$stderr.puts "\n%s\n\n%s\n" % [e, parser]
|
75
|
-
exit
|
76
|
-
end
|
77
|
-
|
78
|
-
$stderr.puts "Options: %p" % opts if $DEBUG
|
18
|
+
self.log.debug "DockDriver opts: %p" % [opts]
|
79
19
|
|
80
|
-
dock = DockDriver::Dock.new( opts[:conf], opts[:log], opts[:dock] )
|
81
|
-
|
82
|
-
# Respond to ^C.
|
83
|
-
#
|
84
20
|
trap 'INT' do
|
85
|
-
|
86
|
-
|
21
|
+
self.log.debug "Recieved SIGINT."
|
22
|
+
DockDriver.kill
|
23
|
+
exit 0
|
87
24
|
end
|
88
25
|
|
89
|
-
|
26
|
+
trap 'HUP' do
|
27
|
+
self.log.debug "Recieved SIGHUP."
|
28
|
+
DockDriver.reload opts
|
29
|
+
end
|
90
30
|
|
31
|
+
DockDriver.run opts
|
@@ -1,147 +1,16 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# Determines the layout and styling of the dock.
|
18
|
-
#
|
19
|
-
# Processed by +ERB+. +Poll+ objects as defined by the 'commands' section are
|
20
|
-
# available. Since +Poll+ objects respond to to_s intelligently, it's usually
|
21
|
-
# sufficient to just specify the object name. Since they're also subclasses of
|
22
|
-
# +OpenStruct+, you can also use any attribute defined on the poll here too.
|
23
|
-
#
|
24
|
-
# See the dzen2 documentation.
|
25
|
-
#
|
26
|
-
template:
|
27
|
-
<%= time %>
|
28
|
-
<%= load %>
|
29
|
-
^fg(white)eth0
|
30
|
-
<%= eth0_rx %>^fg(gray30) <%= eth0_tx %>^fg(gray30) <%= eth0_rx.unit %>/s
|
31
|
-
<%= cpu0_temp %>
|
32
|
-
<%= cpu1_temp %>
|
33
|
-
<%= gpu_temp %>
|
34
|
-
^fg(black)
|
35
|
-
|
36
|
-
# Provides a list of commands to poll.
|
37
|
-
#
|
38
|
-
# The key commands needs to be a hash of hashes. The example below shows
|
39
|
-
# some interesting examples. Here's the basic structure:
|
40
|
-
#
|
41
|
-
# commands:
|
42
|
-
# name:
|
43
|
-
# cmd: 'whoami'
|
44
|
-
# frob:
|
45
|
-
# cmd: 'byte_frobber'
|
46
|
-
# type: 'rate'
|
47
|
-
# scan_regex: 'bytes_frobbed: (\d+)'
|
48
|
-
# format: '%0.3f bits per second'
|
49
|
-
#
|
50
|
-
# You'd refer to the above commands in your template like so:
|
51
|
-
#
|
52
|
-
# User '<%= name %>' is frobbing <%= frob %>!
|
53
|
-
#
|
54
|
-
# Which would yield something like the following on your dock.
|
55
|
-
#
|
56
|
-
# User 'mike' is frobbing 0.321 bits per second!
|
57
|
-
#
|
58
|
-
# Standard options for commands are as follows:
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# cmd:
|
62
|
-
#
|
63
|
-
# A required string that will get executed by a shell. If you're comfortable enough with YAML,
|
64
|
-
# this can be a ruby Proc too.
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# scan_regex:
|
68
|
-
#
|
69
|
-
# This optional key provides a way to extract values from command
|
70
|
-
# output. The value should be a regular expression without forward
|
71
|
-
# slashes, and you'll probably want to put it in single quotes. The best
|
72
|
-
# way to use it is to define one capture group with parenthasees. If you
|
73
|
-
# define more than one capture group, they'll be joined up with spaces and
|
74
|
-
# returned as a single string.
|
75
|
-
#
|
76
|
-
#
|
77
|
-
# format:
|
78
|
-
#
|
79
|
-
# A string that allows you to wrap the output from your command in
|
80
|
-
# another string. You can prepend a label, append a unit, convert the
|
81
|
-
# data type in a limited fashion, or whatever you like.
|
82
|
-
#
|
83
|
-
# See: Kernel#format
|
84
|
-
#
|
85
|
-
#
|
86
|
-
# delay:
|
87
|
-
#
|
88
|
-
# How long to cache the command output for. If delay is set to 60, even
|
89
|
-
# if the bar is refreshed every second, the command will only be run every
|
90
|
-
# 60 seconds or so. Timing isn't guaranteed, but it's good enough to
|
91
|
-
# estimate data rates.
|
92
|
-
#
|
93
|
-
#
|
94
|
-
# type:
|
95
|
-
#
|
96
|
-
# This optional key allows you to specify the type of poll to use. If
|
97
|
-
# you don't specify a type, the default 'text' is used. It simply runs the
|
98
|
-
# command, applies any scan_regex or format specified, and returns the
|
99
|
-
# resulting text.
|
100
|
-
#
|
101
|
-
# If you specify 'rate', the command and scan_regex are expected
|
102
|
-
# to return a number. This number will be interpereted as a total in
|
103
|
-
# bytes. For example the number of bits that your network adapter has
|
104
|
-
# sent. A history of how that value changes over time is kept, and the
|
105
|
-
# output from this poll is the average of that history.
|
106
|
-
#
|
107
|
-
#
|
108
|
-
# history_length:
|
109
|
-
#
|
110
|
-
# This only applies to the 'rate' type. The history length is the number
|
111
|
-
# of samples to keep and allows you to control how long of a running
|
112
|
-
# average to keep. The larger this number is, the more the average will
|
113
|
-
# lag behind the actual rate of change.
|
114
|
-
#
|
115
|
-
#
|
116
|
-
commands:
|
117
|
-
load:
|
118
|
-
cmd: 'uptime'
|
119
|
-
scan_regex: '(\d+\.\d+)$'
|
120
|
-
format: '^fg(white)load ^fg(gray60)%s^fg(gray30)/15'
|
121
|
-
delay: 60
|
122
|
-
cpu0_temp:
|
123
|
-
cmd: 'sensors'
|
124
|
-
scan_regex: 'Core 0:\s+\+(\d+\.\d+)'
|
125
|
-
format: '^fg(white)cpu0 ^fg(gray60)%s^fg(gray30)°C'
|
126
|
-
delay: 30
|
127
|
-
cpu1_temp:
|
128
|
-
cmd: 'sensors'
|
129
|
-
scan_regex: 'Core 1:\s+\+(\d+\.\d+)'
|
130
|
-
format: '^fg(white)cpu1 ^fg(gray60)%s^fg(gray30)°C'
|
131
|
-
delay: 30
|
132
|
-
gpu_temp:
|
133
|
-
cmd: 'nvidia-smi -q -d TEMPERATURE'
|
134
|
-
scan_regex: '(\d+) C'
|
135
|
-
format: '^fg(white)gpu ^fg(gray60)%s^fg(gray30)°C'
|
136
|
-
delay: 30
|
137
|
-
eth0_rx:
|
138
|
-
cmd: 'ifconfig eth0'
|
139
|
-
scan_regex: 'RX bytes:(\d+)'
|
140
|
-
format: '^fg(#208020)%0.3f'
|
141
|
-
type: 'rate'
|
142
|
-
eth0_tx:
|
143
|
-
cmd: 'ifconfig eth0'
|
144
|
-
scan_regex: 'TX bytes:(\d+)'
|
145
|
-
format: '^fg(#802020)%0.3f'
|
146
|
-
type: 'rate'
|
147
|
-
|
2
|
+
dock_driver:
|
3
|
+
command: 'dzen2'
|
4
|
+
template: ''
|
5
|
+
dock:
|
6
|
+
items:
|
7
|
+
- name: gronald
|
8
|
+
command: foo --bar baz
|
9
|
+
frequency: 1.5
|
10
|
+
- name: aphrodite
|
11
|
+
command: feeblebeeble -vqnf 42
|
12
|
+
scan: 'Gort: (\d+)'
|
13
|
+
frequency: 3
|
14
|
+
logging:
|
15
|
+
__default__: warn (color)
|
16
|
+
dock_driver: debug (color)
|