epitools 0.4.18 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +7 -7
- data/VERSION +1 -1
- data/epitools.gemspec +4 -3
- data/lib/epitools/sys.rb +74 -54
- metadata +28 -4
data/README.rdoc
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
Useful miscellaneous improvements for base Ruby objects, plus some extra
|
4
4
|
data structures and handy wrappers.
|
5
5
|
|
6
|
-
Base classess have been enhanced: {Enumerable}[http://rdoc.info/
|
6
|
+
Base classess have been enhanced: {Enumerable}[http://rdoc.info/github/epitron/epitools/master/Enumerable], {Hash}[http://rdoc.info/github/epitron/epitools/master/Hash], {String}[http://rdoc.info/github/epitron/epitools/master/String], {Array}[http://rdoc.info/github/epitron/epitools/master/Array], {Object}[http://rdoc.info/github/epitron/epitools/master/Object], {Integer}[http://rdoc.info/github/epitron/epitools/master/Integer], etc.
|
7
7
|
|
8
8
|
Extras:
|
9
9
|
|
10
|
-
* {Colored}[http://rdoc.info/
|
11
|
-
* {Path}[http://rdoc.info/
|
12
|
-
* {Rash}[http://rdoc.info/
|
13
|
-
* {Progressbar}[http://rdoc.info/
|
14
|
-
* {Browser}[http://rdoc.info/
|
10
|
+
* {Colored}[http://rdoc.info/github/epitron/epitools/master/Colored] (enhanced version of defunkt's colored -- adds ANSI colouring methods to String, eg: #red, #green, #light_blue, etc.)
|
11
|
+
* {Path}[http://rdoc.info/github/epitron/epitools/master/Path] (a better Pathname)
|
12
|
+
* {Rash}[http://rdoc.info/github/epitron/epitools/master/Rash] (a hash which can have Regexps as keys, allowing a single (key,value) pair to match many keys.)
|
13
|
+
* {Progressbar}[http://rdoc.info/github/epitron/epitools/master/Progressbar] (better than the progressbar gem)
|
14
|
+
* {Browser}[http://rdoc.info/github/epitron/epitools/master/Browser] (a fake browser, using mechanize, Progressbar, and CacheDB)
|
15
15
|
|
16
16
|
== Installing
|
17
17
|
|
@@ -21,7 +21,7 @@ Extras:
|
|
21
21
|
|
22
22
|
This is basically a collection of enhancements to the ruby base types (Hash, Array,
|
23
23
|
Enumerable, etc.). To learn how it works, read the specs in spec/*.rb,
|
24
|
-
or check out the rdoc: http://rdoc.info/
|
24
|
+
or check out the rdoc: http://rdoc.info/github/epitron/epitools/master/frames
|
25
25
|
|
26
26
|
== Copyright
|
27
27
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.19
|
data/epitools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{epitools}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.19"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["epitron"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-30}
|
13
13
|
s.description = %q{Miscellaneous utility libraries to make my life easier.}
|
14
14
|
s.email = %q{chris@ill-logic.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -61,7 +61,7 @@ Gem::Specification.new do |s|
|
|
61
61
|
s.homepage = %q{http://github.com/epitron/epitools}
|
62
62
|
s.licenses = ["WTFPL"]
|
63
63
|
s.require_paths = ["lib"]
|
64
|
-
s.rubygems_version = %q{1.
|
64
|
+
s.rubygems_version = %q{1.3.7}
|
65
65
|
s.summary = %q{NOT UTILS... METILS!}
|
66
66
|
s.test_files = [
|
67
67
|
"spec/basetypes_spec.rb",
|
@@ -79,6 +79,7 @@ Gem::Specification.new do |s|
|
|
79
79
|
]
|
80
80
|
|
81
81
|
if s.respond_to? :specification_version then
|
82
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
82
83
|
s.specification_version = 3
|
83
84
|
|
84
85
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/epitools/sys.rb
CHANGED
@@ -8,6 +8,56 @@ module Sys
|
|
8
8
|
|
9
9
|
#-----------------------------------------------------------------------------
|
10
10
|
|
11
|
+
#
|
12
|
+
# Return the current operating system: Darwin, Linux, or Windows.
|
13
|
+
#
|
14
|
+
def self.os
|
15
|
+
return @os if @os
|
16
|
+
|
17
|
+
require 'rbconfig'
|
18
|
+
host_os = Config::CONFIG['host_os']
|
19
|
+
case host_os
|
20
|
+
when /darwin/
|
21
|
+
@os = "Darwin"
|
22
|
+
when /linux/
|
23
|
+
@os = "Linux"
|
24
|
+
when /mingw|mswin|cygwin/
|
25
|
+
@os = 'Windows'
|
26
|
+
else
|
27
|
+
raise "Unknown OS: #{host_os.inspect}"
|
28
|
+
end
|
29
|
+
|
30
|
+
@os
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Is this Linux?
|
35
|
+
#
|
36
|
+
def self.linux?
|
37
|
+
os == "Linux"
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Is this Windows?
|
42
|
+
#
|
43
|
+
def self.windows?
|
44
|
+
os == "Windows"
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Is this Darwin?
|
49
|
+
#
|
50
|
+
def self.darwin?
|
51
|
+
os == "Darwin"
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Is this a Mac? (aka. Darwin?)
|
56
|
+
#
|
57
|
+
def self.mac?; darwin?; end
|
58
|
+
|
59
|
+
#-----------------------------------------------------------------------------
|
60
|
+
|
11
61
|
PS_FIELD_TABLE = [
|
12
62
|
[:pid, :to_i],
|
13
63
|
[:pcpu, :to_f],
|
@@ -33,6 +83,8 @@ module Sys
|
|
33
83
|
# The following attribute accessor methods are available:
|
34
84
|
#
|
35
85
|
# pid (integer)
|
86
|
+
# command (string -- the 'ps' name)
|
87
|
+
# name (alias for 'command')
|
36
88
|
# pcpu (float)
|
37
89
|
# pmem (float)
|
38
90
|
# stat (string)
|
@@ -41,9 +93,12 @@ module Sys
|
|
41
93
|
# user (string)
|
42
94
|
# majflt (integer)
|
43
95
|
# minflt (integer)
|
44
|
-
# command (string)
|
45
96
|
# state (array of symbols; see DARWIN_STATES or LINUX_STATES)
|
46
97
|
#
|
98
|
+
# Only on linux:
|
99
|
+
# exename (string -- path to the binary)
|
100
|
+
# fds (array -- list of open file descriptors)
|
101
|
+
#
|
47
102
|
class ProcessInfo < Struct.new(*PS_FIELDS+[:state])
|
48
103
|
|
49
104
|
DARWIN_STATES = {
|
@@ -125,7 +180,23 @@ module Sys
|
|
125
180
|
members.each { |member| self[member] = updated_process[member] }
|
126
181
|
self
|
127
182
|
end
|
183
|
+
|
184
|
+
alias_method :name, :command
|
128
185
|
|
186
|
+
# Linux-specific methods
|
187
|
+
if Sys.linux?
|
188
|
+
|
189
|
+
def exename
|
190
|
+
@exename ||= File.readlink("/proc/#{pid}/exe") rescue :unknown
|
191
|
+
@exename == :unknown ? nil : @exename
|
192
|
+
end
|
193
|
+
|
194
|
+
def fds
|
195
|
+
Dir["/proc/#{pid}/fd/*"].map { |fd| File.readlink(fd) rescue nil }
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
129
200
|
private
|
130
201
|
|
131
202
|
def stat_to_state(str)
|
@@ -137,7 +208,6 @@ module Sys
|
|
137
208
|
|
138
209
|
str.scan(/./).map { |char| states[char] }.compact
|
139
210
|
end
|
140
|
-
|
141
211
|
end
|
142
212
|
|
143
213
|
#-----------------------------------------------------------------------------
|
@@ -150,12 +220,12 @@ module Sys
|
|
150
220
|
options = PS_FIELDS.join(',')
|
151
221
|
|
152
222
|
if pids.any?
|
153
|
-
command = "ps -p #{pids.join(',')} -o #{options}"
|
223
|
+
command = "ps -p #{pids.map(&:to_i).join(',')} -o #{options}"
|
154
224
|
else
|
155
225
|
command = "ps ax -o #{options}"
|
156
226
|
end
|
157
227
|
|
158
|
-
lines = `#{command}`.to_a
|
228
|
+
lines = `#{command}`.lines.to_a
|
159
229
|
|
160
230
|
lines[1..-1].map do |line|
|
161
231
|
fields = line.split
|
@@ -171,56 +241,6 @@ module Sys
|
|
171
241
|
|
172
242
|
#-----------------------------------------------------------------------------
|
173
243
|
|
174
|
-
#
|
175
|
-
# Return the current operating system: Darwin, Linux, or Windows.
|
176
|
-
#
|
177
|
-
def self.os
|
178
|
-
return @os if @os
|
179
|
-
|
180
|
-
require 'rbconfig'
|
181
|
-
host_os = Config::CONFIG['host_os']
|
182
|
-
case host_os
|
183
|
-
when /darwin/
|
184
|
-
@os = "Darwin"
|
185
|
-
when /linux/
|
186
|
-
@os = "Linux"
|
187
|
-
when /mingw|mswin|cygwin/
|
188
|
-
@os = 'Windows'
|
189
|
-
else
|
190
|
-
raise "Unknown OS: #{host_os.inspect}"
|
191
|
-
end
|
192
|
-
|
193
|
-
@os
|
194
|
-
end
|
195
|
-
|
196
|
-
#
|
197
|
-
# Is this Linux?
|
198
|
-
#
|
199
|
-
def self.linux?
|
200
|
-
os == "Linux"
|
201
|
-
end
|
202
|
-
|
203
|
-
#
|
204
|
-
# Is this Windows?
|
205
|
-
#
|
206
|
-
def self.windows?
|
207
|
-
os == "Windows"
|
208
|
-
end
|
209
|
-
|
210
|
-
#
|
211
|
-
# Is this Darwin?
|
212
|
-
#
|
213
|
-
def self.darwin?
|
214
|
-
os == "Darwin"
|
215
|
-
end
|
216
|
-
|
217
|
-
#
|
218
|
-
# Is this a Mac? (aka. Darwin?)
|
219
|
-
#
|
220
|
-
def self.mac?; darwin?; end
|
221
|
-
|
222
|
-
#-----------------------------------------------------------------------------
|
223
|
-
|
224
244
|
#
|
225
245
|
# Trap signals!
|
226
246
|
#
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 41
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 19
|
10
|
+
version: 0.4.19
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- epitron
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-30 00:00:00 -04:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,11 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ~>
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 0
|
24
34
|
version: 2.2.0
|
25
35
|
type: :development
|
26
36
|
version_requirements: *id001
|
@@ -32,6 +42,11 @@ dependencies:
|
|
32
42
|
requirements:
|
33
43
|
- - ~>
|
34
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
- 0
|
35
50
|
version: 1.0.0
|
36
51
|
type: :development
|
37
52
|
version_requirements: *id002
|
@@ -43,6 +58,9 @@ dependencies:
|
|
43
58
|
requirements:
|
44
59
|
- - ">="
|
45
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
46
64
|
version: "0"
|
47
65
|
type: :development
|
48
66
|
version_requirements: *id003
|
@@ -110,17 +128,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
128
|
requirements:
|
111
129
|
- - ">="
|
112
130
|
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
113
134
|
version: "0"
|
114
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
136
|
none: false
|
116
137
|
requirements:
|
117
138
|
- - ">="
|
118
139
|
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
119
143
|
version: "0"
|
120
144
|
requirements: []
|
121
145
|
|
122
146
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.
|
147
|
+
rubygems_version: 1.3.7
|
124
148
|
signing_key:
|
125
149
|
specification_version: 3
|
126
150
|
summary: NOT UTILS... METILS!
|