sys-uptime 0.4.4 → 0.4.5
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/CHANGES +4 -0
- data/MANIFEST +6 -4
- data/README +11 -11
- data/ext/extconf.rb +29 -0
- data/{lib/os/unix.c → ext/uptime.c} +4 -4
- data/test/tc_uptime.rb +27 -29
- metadata +9 -6
- data/extconf.rb +0 -36
data/CHANGES
CHANGED
data/MANIFEST
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
CHANGES
|
2
2
|
MANIFEST
|
3
3
|
README
|
4
|
-
extconf.rb
|
5
4
|
install.rb
|
6
5
|
sys-uptime.gemspec
|
7
6
|
|
@@ -9,7 +8,10 @@ doc/uptime.txt
|
|
9
8
|
|
10
9
|
examples/test.rb
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
ext/extconf.rb
|
12
|
+
ext/uptime.c
|
14
13
|
|
15
|
-
|
14
|
+
lib/sys/linux.rb
|
15
|
+
lib/sys/windows.rb
|
16
|
+
|
17
|
+
test/tc_uptime.rb
|
data/README
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
|
1
|
+
= Description
|
2
2
|
A Ruby interface for getting system uptime information.
|
3
3
|
|
4
|
-
|
4
|
+
= Prerequisites
|
5
5
|
Ruby 1.8.0 or later.
|
6
|
-
|
6
|
+
Ruby 1.8.2 or later is recommended on MS Windows.
|
7
7
|
|
8
|
-
|
8
|
+
= Installation
|
9
9
|
=== Unix:
|
10
|
-
ruby extconf.rb
|
11
|
-
make
|
12
|
-
ruby test/tc_uptime.rb (optional)
|
13
|
-
make
|
10
|
+
ruby extconf.rb
|
11
|
+
make
|
12
|
+
ruby test/tc_uptime.rb (optional)
|
13
|
+
make install
|
14
14
|
|
15
15
|
=== Windows and Linux:
|
16
|
-
ruby test\tc_uptime.rb (optional)
|
17
|
-
ruby install.rb
|
16
|
+
ruby test\tc_uptime.rb (optional)
|
17
|
+
ruby install.rb
|
18
18
|
|
19
19
|
== Notes
|
20
|
-
For additional documentation see doc/uptime.txt.
|
20
|
+
For additional documentation see doc/uptime.txt.
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
################################################
|
2
|
+
# extconf.rb
|
3
|
+
#
|
4
|
+
# Configuration & build script for sys-uptime.
|
5
|
+
################################################
|
6
|
+
require 'mkmf'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
if RUBY_PLATFORM =~ /windows|win32|cygwin|mingw|dos|linux/i
|
10
|
+
STDERR.puts 'Run the "install.rb" script instead on this platform'
|
11
|
+
exit
|
12
|
+
else
|
13
|
+
# Don't install the pure Ruby libraries during 'make install'.
|
14
|
+
if File.basename(Dir.pwd) =~ /ext|sys-uptime/i
|
15
|
+
Dir.chdir('..'){
|
16
|
+
if File.exists?('lib/sys/windows.rb')
|
17
|
+
FileUtils.mv('lib/sys/windows.rb', 'lib/sys/windows.orig')
|
18
|
+
end
|
19
|
+
|
20
|
+
if File.exists?('lib/sys/linux.rb')
|
21
|
+
FileUtils.mv('lib/sys/linux.rb', 'lib/sys/linux.orig')
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
have_header('sys/loadavg.h')
|
28
|
+
have_header('utmpx.h')
|
29
|
+
create_makefile('sys/uptime')
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/******************************************************************************
|
2
|
-
*
|
2
|
+
* uptime.c
|
3
3
|
*
|
4
4
|
* Authors:
|
5
5
|
* Daniel Berger
|
@@ -7,7 +7,7 @@
|
|
7
7
|
*
|
8
8
|
* sys-uptime source code for most *nix platforms
|
9
9
|
*****************************************************************************/
|
10
|
-
#include
|
10
|
+
#include <ruby.h>
|
11
11
|
|
12
12
|
#if defined (__FreeBSD__) || defined (__NetBSD__)
|
13
13
|
#include <sys/time.h>
|
@@ -45,7 +45,7 @@
|
|
45
45
|
|
46
46
|
#define MAXSTRINGSIZE 32 /* reasonable limit */
|
47
47
|
|
48
|
-
#define SYS_UPTIME_VERSION "0.4.
|
48
|
+
#define SYS_UPTIME_VERSION "0.4.5"
|
49
49
|
|
50
50
|
VALUE cUptimeError;
|
51
51
|
|
@@ -59,7 +59,7 @@ unsigned long get_uptime_secs()
|
|
59
59
|
mib[0] = CTL_KERN;
|
60
60
|
mib[1] = KERN_BOOTTIME;
|
61
61
|
if(sysctl(mib, 2, &tv, &tvlen, NULL, 0)){
|
62
|
-
rb_raise(cUptimeError,"sysctl() call failed");
|
62
|
+
rb_raise(cUptimeError, "sysctl() call failed");
|
63
63
|
}
|
64
64
|
return time(NULL) - tv.tv_sec;
|
65
65
|
#else
|
data/test/tc_uptime.rb
CHANGED
@@ -1,76 +1,74 @@
|
|
1
1
|
#################################
|
2
2
|
# tc_uptime.rb
|
3
3
|
#
|
4
|
-
# Test suite for sys-uptime
|
4
|
+
# Test suite for sys-uptime.
|
5
5
|
#################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
|
-
if base ==
|
8
|
-
require
|
9
|
-
Dir.chdir(
|
7
|
+
if base == 'test' || base =~ /sys-uptime.*/
|
8
|
+
require 'fileutils'
|
9
|
+
Dir.chdir('..') if base == 'test'
|
10
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
Dir.mkdir("sys") unless File.exists?("sys")
|
16
|
-
|
17
|
-
if PLATFORM.match("mswin")
|
18
|
-
File.copy("lib/os/windows.rb", "sys/uptime.rb")
|
19
|
-
elsif PLATFORM.match("linux")
|
20
|
-
File.copy("lib/os/linux.rb", "sys/uptime.rb")
|
12
|
+
if RUBY_PLATFORM.match('mswin')
|
13
|
+
FileUtils.cp('lib/sys/windows.rb', 'sys/uptime.rb') rescue nil
|
14
|
+
elsif RUBY_PLATFORM.match('linux')
|
15
|
+
FileUtils.cp('lib/sys/linux.rb', 'sys/uptime.rb') rescue nil
|
21
16
|
else
|
22
|
-
|
23
|
-
|
17
|
+
require 'rbconfig'
|
18
|
+
file = 'ext/uptime.' + Config::CONFIG['DLEXT']
|
19
|
+
FileUtils.cp(file, 'sys')
|
24
20
|
end
|
25
|
-
|
21
|
+
|
22
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
23
|
+
$LOAD_PATH.unshift(Dir.pwd + '/lib')
|
26
24
|
end
|
27
25
|
|
28
|
-
require
|
29
|
-
require
|
26
|
+
require 'sys/uptime'
|
27
|
+
require 'test/unit'
|
30
28
|
include Sys
|
31
29
|
|
32
30
|
class TC_Uptime < Test::Unit::TestCase
|
33
31
|
def test_version
|
34
|
-
assert_equal('0.4.
|
32
|
+
assert_equal('0.4.5', Uptime::VERSION)
|
35
33
|
end
|
36
34
|
|
37
35
|
def test_seconds
|
38
36
|
assert_respond_to(Uptime, :seconds)
|
39
37
|
assert_nothing_raised{ Uptime.seconds }
|
40
|
-
assert_kind_of(Fixnum, Uptime.seconds
|
41
|
-
assert_equal(true, Uptime.seconds > 0
|
38
|
+
assert_kind_of(Fixnum, Uptime.seconds)
|
39
|
+
assert_equal(true, Uptime.seconds > 0)
|
42
40
|
end
|
43
41
|
|
44
42
|
def test_minutes
|
45
43
|
assert_respond_to(Uptime, :minutes)
|
46
44
|
assert_nothing_raised{ Uptime.minutes }
|
47
|
-
assert_kind_of(Fixnum, Uptime.minutes
|
45
|
+
assert_kind_of(Fixnum, Uptime.minutes)
|
48
46
|
end
|
49
47
|
|
50
48
|
def test_hours
|
51
49
|
assert_respond_to(Uptime, :hours)
|
52
50
|
assert_nothing_raised{ Uptime.hours }
|
53
|
-
assert_kind_of(Fixnum, Uptime.hours
|
51
|
+
assert_kind_of(Fixnum, Uptime.hours)
|
54
52
|
end
|
55
53
|
|
56
54
|
def test_days
|
57
55
|
assert_respond_to(Uptime,:days)
|
58
56
|
assert_nothing_raised{ Uptime.days }
|
59
|
-
assert_kind_of(Fixnum, Uptime.days
|
57
|
+
assert_kind_of(Fixnum, Uptime.days)
|
60
58
|
end
|
61
59
|
|
62
60
|
def test_uptime
|
63
61
|
assert_respond_to(Uptime,:uptime)
|
64
62
|
assert_nothing_raised{ Uptime.uptime }
|
65
|
-
assert_kind_of(String, Uptime.uptime
|
66
|
-
assert_equal(false, Uptime.uptime.empty
|
63
|
+
assert_kind_of(String, Uptime.uptime)
|
64
|
+
assert_equal(false, Uptime.uptime.empty?)
|
67
65
|
end
|
68
66
|
|
69
67
|
def test_dhms
|
70
68
|
assert_respond_to(Uptime,:dhms)
|
71
69
|
assert_nothing_raised{ Uptime.dhms }
|
72
|
-
assert_kind_of(Array, Uptime.dhms
|
73
|
-
assert_equal(false, Uptime.dhms.empty
|
70
|
+
assert_kind_of(Array, Uptime.dhms)
|
71
|
+
assert_equal(false, Uptime.dhms.empty?)
|
74
72
|
assert_equal(4, Uptime.dhms.length)
|
75
73
|
end
|
76
74
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sys-uptime
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.4.5
|
7
|
+
date: 2006-11-20 00:00:00 -07:00
|
8
8
|
summary: A Ruby interface for getting system uptime information.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -32,10 +32,10 @@ files:
|
|
32
32
|
- doc/uptime.txt
|
33
33
|
- test/tc_uptime.rb
|
34
34
|
- CHANGES
|
35
|
-
- MANIFEST
|
36
35
|
- README
|
37
|
-
-
|
38
|
-
-
|
36
|
+
- MANIFEST
|
37
|
+
- ext/uptime.c
|
38
|
+
- ext/extconf.rb
|
39
39
|
test_files:
|
40
40
|
- test/tc_uptime.rb
|
41
41
|
rdoc_options: []
|
@@ -43,10 +43,13 @@ rdoc_options: []
|
|
43
43
|
extra_rdoc_files:
|
44
44
|
- CHANGES
|
45
45
|
- README
|
46
|
+
- MANIFEST
|
47
|
+
- doc/uptime.txt
|
48
|
+
- ext/uptime.c
|
46
49
|
executables: []
|
47
50
|
|
48
51
|
extensions:
|
49
|
-
- extconf.rb
|
52
|
+
- ext/extconf.rb
|
50
53
|
requirements: []
|
51
54
|
|
52
55
|
dependencies: []
|
data/extconf.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
##############################################
|
2
|
-
# extconf.rb
|
3
|
-
#
|
4
|
-
# Configuration & build script for sys-uptime
|
5
|
-
##############################################
|
6
|
-
require 'mkmf'
|
7
|
-
require 'ftools'
|
8
|
-
|
9
|
-
#######################################################################
|
10
|
-
# In case this is run more than one time, delete the link/copy if it
|
11
|
-
# already exists.
|
12
|
-
#######################################################################
|
13
|
-
uptime_file = "uptime.c"
|
14
|
-
File.delete(uptime_file) if File.exists?(uptime_file)
|
15
|
-
|
16
|
-
case RUBY_PLATFORM
|
17
|
-
when /windows|win32|cygwin|mingw|dos|linux/i
|
18
|
-
STDERR.puts "Run the 'install.rb' script instead on this platform"
|
19
|
-
exit
|
20
|
-
else
|
21
|
-
have_header("sys/loadavg.h")
|
22
|
-
c_file = "lib/os/unix.c"
|
23
|
-
|
24
|
-
File.symlink(c_file, uptime_file)
|
25
|
-
|
26
|
-
if File.exists?("lib/os/windows.rb")
|
27
|
-
File.move("lib/os/windows.rb", "lib/os/windows.orig") # Don't install
|
28
|
-
end
|
29
|
-
|
30
|
-
if File.exists?("lib/os/linux.rb")
|
31
|
-
File.move("lib/os/linux.rb", "lib/os/linux.orig") # Don't install
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
have_header("utmpx.h")
|
36
|
-
create_makefile('sys/uptime')
|