helper_classes 0.3.5 → 1.9.13.pre.10
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.
- checksums.yaml +4 -4
- data/Gemfile +0 -0
- data/Gemfile.lock +7 -0
- data/helper_classes.gemspec +4 -4
- data/lib/helper_classes.rb +1 -1
- data/lib/helper_classes/dputs.rb +4 -4
- data/lib/helper_classes/{service.rb → platform.rb} +44 -8
- data/lib/helper_classes/system.rb +17 -11
- data/test/hc_hashaccessor.rb +25 -0
- data/test/hc_service.rb +3 -3
- data/test/test.rb +3 -2
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a715987ec443ba019a87e2894095b3e1506ed9
|
4
|
+
data.tar.gz: db222b62513305e232cfd1bfceeb70096e490527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6cacdbb88c73871991dc541a06ed4201fe5d119c33cc7781d89450963d45939225c4f22fc338a9c151dade50e0bbe8d42b043d03414a137fd09e6c40ff60eb8
|
7
|
+
data.tar.gz: 39244111e0e56a3c769251f42070389d446ed5019a4b30a9a155a2c696d83985b2df3914eaec7e2f051d11c32c9ed810869f4c962982bd148e0344e94570db5c
|
data/Gemfile
ADDED
File without changes
|
data/Gemfile.lock
ADDED
data/helper_classes.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'helper_classes'
|
3
|
-
s.version = '
|
4
|
-
s.date = '
|
3
|
+
s.version = '1.9.13-10'
|
4
|
+
s.date = '2017-10-30'
|
5
5
|
s.summary = 'Hash._accessor Array.to_sym and DPuts'
|
6
6
|
s.description = 'Added accessors to Hash, to_sym to Array and a nice debugging-interface called DPuts'
|
7
7
|
s.authors = ['Linus Gasser']
|
8
|
-
s.email = 'ineiti
|
8
|
+
s.email = 'ineiti.blue'
|
9
9
|
|
10
10
|
s.files = `if [ -d '.git' ]; then git ls-files -z; fi`.split("\x0")
|
11
11
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -14,5 +14,5 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.homepage =
|
16
16
|
'https://github.com/ineiti/HelperClasses'
|
17
|
-
s.license = '
|
17
|
+
s.license = 'GPL-3.0'
|
18
18
|
end
|
data/lib/helper_classes.rb
CHANGED
data/lib/helper_classes/dputs.rb
CHANGED
@@ -50,11 +50,11 @@ module HelperClasses
|
|
50
50
|
end
|
51
51
|
DPuts.mutex.synchronize do
|
52
52
|
width = DPuts.terminal_width.to_i || 160
|
53
|
-
width = [width -
|
53
|
+
width = [width - 40.0, 10].max
|
54
54
|
file, func = call.split(' ')
|
55
|
-
file = file[/^.*\/(
|
56
|
-
who = (':' + n.to_s + ':' + file.to_s +
|
57
|
-
func.to_s).ljust(
|
55
|
+
file = file[/^.*\/(.*):in/, 1]
|
56
|
+
who = (':' + n.to_s + ':' + file.to_s + "--" +
|
57
|
+
func.to_s).ljust(40, ['X', 'x', '*', '-', '.', ' '][n])
|
58
58
|
lines = []
|
59
59
|
pos = 0
|
60
60
|
# Don't show enormous strings
|
@@ -2,7 +2,7 @@ require 'helper_classes/dputs'
|
|
2
2
|
require 'helper_classes/system'
|
3
3
|
|
4
4
|
module HelperClasses
|
5
|
-
module
|
5
|
+
module Platform
|
6
6
|
attr_accessor :system, :services
|
7
7
|
|
8
8
|
extend self
|
@@ -20,7 +20,9 @@ module HelperClasses
|
|
20
20
|
|
21
21
|
@services = {
|
22
22
|
samba: {ArchLinux: %w( smbd nmbd ), Ubuntu: %w(smbd nmbd)},
|
23
|
-
cups: {ArchLinux: 'org.cups.cupsd', Ubuntu: 'cupsd'}
|
23
|
+
cups: {ArchLinux: 'org.cups.cupsd', Ubuntu: 'cupsd'},
|
24
|
+
net_start: {ArchLinux: '/usr/bin/netctl start', Ubuntu: 'ifup'},
|
25
|
+
net_stop: {ArchLinux: '/usr/bin/netctl stop', Ubuntu: 'ifdown'},
|
24
26
|
}
|
25
27
|
|
26
28
|
def service_get(service)
|
@@ -58,35 +60,35 @@ module HelperClasses
|
|
58
60
|
|
59
61
|
def start(service)
|
60
62
|
service_run(service, {ArchLinux: 'systemctl start ##',
|
61
|
-
Ubuntu: '
|
63
|
+
Ubuntu: 'systemctl start ##',
|
62
64
|
MacOSX: nil}
|
63
65
|
)
|
64
66
|
end
|
65
67
|
|
66
68
|
def stop(service)
|
67
69
|
service_run(service, {ArchLinux: 'systemctl stop ##',
|
68
|
-
Ubuntu: '
|
70
|
+
Ubuntu: 'systemctl stop ##',
|
69
71
|
MacOSX: nil}
|
70
72
|
)
|
71
73
|
end
|
72
74
|
|
73
75
|
def restart(service)
|
74
76
|
service_run(service, {ArchLinux: 'systemctl restart ##',
|
75
|
-
Ubuntu: '
|
77
|
+
Ubuntu: 'systemctl restart ##',
|
76
78
|
MacOSX: nil}
|
77
79
|
)
|
78
80
|
end
|
79
81
|
|
80
82
|
def enable(service)
|
81
83
|
service_run(service, {ArchLinux: 'systemctl enable ##',
|
82
|
-
Ubuntu:
|
84
|
+
Ubuntu: 'systemctl enable ##',
|
83
85
|
MacOSX: nil}
|
84
86
|
)
|
85
87
|
end
|
86
88
|
|
87
89
|
def disable(service)
|
88
90
|
service_run(service, {ArchLinux: 'systemctl disable ##',
|
89
|
-
Ubuntu:
|
91
|
+
Ubuntu: 'systemctl disable ##',
|
90
92
|
MacOSX: nil}
|
91
93
|
)
|
92
94
|
end
|
@@ -109,5 +111,39 @@ module HelperClasses
|
|
109
111
|
disable(service)
|
110
112
|
stop(service)
|
111
113
|
end
|
114
|
+
|
115
|
+
def net_start(iface)
|
116
|
+
c = "#{@services[:net_start][@system]} #{iface}"
|
117
|
+
if !System.run_bool(c)
|
118
|
+
log_msg :Services, "Command #{c} failed"
|
119
|
+
return false
|
120
|
+
end
|
121
|
+
return true
|
122
|
+
end
|
123
|
+
|
124
|
+
def net_stop(iface)
|
125
|
+
c = "#{@services[:net_stop][@system]} #{iface}"
|
126
|
+
if !System.run_bool(c)
|
127
|
+
log_msg :Services, "Command #{c} failed"
|
128
|
+
return false
|
129
|
+
end
|
130
|
+
return true
|
131
|
+
end
|
132
|
+
|
133
|
+
def net_restart(iface)
|
134
|
+
net_stop(iface)
|
135
|
+
net_start(iface)
|
136
|
+
end
|
137
|
+
|
138
|
+
def net_status(iface, dev)
|
139
|
+
case @system
|
140
|
+
when :ArchLinux
|
141
|
+
return System.run_str("netctl status #{iface} | grep Active") =~ /: active/
|
142
|
+
when :Ubuntu
|
143
|
+
return System.run_str("ifconfig | grep #{dev}") != ''
|
144
|
+
else
|
145
|
+
return false
|
146
|
+
end
|
147
|
+
end
|
112
148
|
end
|
113
|
-
end
|
149
|
+
end
|
@@ -34,7 +34,7 @@ module HelperClasses
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def iptables(*args)
|
37
|
+
def iptables(*args, check: false)
|
38
38
|
if !@iptables_cmd
|
39
39
|
if System.exists?('iptables')
|
40
40
|
@iptables_cmd = 'iptables'
|
@@ -45,7 +45,11 @@ module HelperClasses
|
|
45
45
|
end
|
46
46
|
|
47
47
|
if @iptables_cmd != ''
|
48
|
-
|
48
|
+
if check
|
49
|
+
System.run_bool("#{@iptables_cmd} #{@iptables_wait} #{args.join(' ')} 2>/dev/null")
|
50
|
+
else
|
51
|
+
System.run_str("#{@iptables_cmd} #{@iptables_wait} #{args.join(' ')}")
|
52
|
+
end
|
49
53
|
else
|
50
54
|
return ''
|
51
55
|
end
|
@@ -58,17 +62,19 @@ module HelperClasses
|
|
58
62
|
ret = System.run_str('ntpq -c "rv 0 stratum"')
|
59
63
|
return 16 if ret =~ /connection refused/i
|
60
64
|
stratum = ret.gsub(/.*=/, '')
|
61
|
-
return stratum
|
65
|
+
return stratum.to_i
|
62
66
|
end
|
63
67
|
|
64
68
|
# Waits for NTP to be synchronized or for _n_ seconds
|
65
69
|
def ntpd_wait(n = 60)
|
66
70
|
Thread.new {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
System.rescue_all do
|
72
|
+
(1..n).each {
|
73
|
+
break if System.ntpdoffset
|
74
|
+
sleep 1
|
75
|
+
}
|
76
|
+
yield
|
77
|
+
end
|
72
78
|
}
|
73
79
|
end
|
74
80
|
|
@@ -79,8 +85,8 @@ module HelperClasses
|
|
79
85
|
ret = System.run_str('ntpq -c "rv 0 stratum,offset"')
|
80
86
|
return nil if ret =~ /connection refused/i
|
81
87
|
stratum, offset = ret.split(/, /).collect { |s| s.gsub(/.*=/, '') }
|
82
|
-
return nil if stratum == '16'
|
83
|
-
return offset
|
88
|
+
#return nil if stratum == '16'
|
89
|
+
return offset.to_f
|
84
90
|
end
|
85
91
|
end
|
86
|
-
end
|
92
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
class TC_Arraysym < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_simple
|
9
|
+
a = {}
|
10
|
+
a._hi = 'there'
|
11
|
+
assert_equal 'there', a[:hi]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_replace
|
15
|
+
a = {'one' => 1, two: 2}
|
16
|
+
assert_equal 1, a._one
|
17
|
+
assert_equal 2, a._two
|
18
|
+
|
19
|
+
a._one = 3
|
20
|
+
a._two = 4
|
21
|
+
assert_equal 3, a._one
|
22
|
+
assert_equal 4, a._two
|
23
|
+
assert_equal ['one', :two], a.keys
|
24
|
+
end
|
25
|
+
end
|
data/test/hc_service.rb
CHANGED
@@ -7,9 +7,9 @@ class TC_Service < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_service_get
|
10
|
-
|
10
|
+
Platform.system = :ArchLinux
|
11
11
|
|
12
|
-
assert_equal %w(smbd nmbd),
|
13
|
-
assert_equal 'dnsmasq',
|
12
|
+
assert_equal %w(smbd nmbd), Platform.service_get(:samba)
|
13
|
+
assert_equal 'dnsmasq', Platform.service_get(:dnsmasq)
|
14
14
|
end
|
15
15
|
end
|
data/test/test.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'bundler/setup'
|
3
|
+
$LOAD_PATH.push '.', '../lib'
|
3
4
|
|
4
5
|
require 'test/unit'
|
5
6
|
require 'helper_classes'
|
6
7
|
include HelperClasses
|
7
8
|
|
8
9
|
tests = Dir.glob( 'hc_*.rb' )
|
9
|
-
|
10
|
+
tests = %w( hashaccessor )
|
10
11
|
|
11
12
|
tests.each{|t|
|
12
13
|
begin
|
metadata
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helper_classes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.9.13.pre.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linus Gasser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Added accessors to Hash, to_sym to Array and a nice debugging-interface
|
14
14
|
called DPuts
|
15
|
-
email: ineiti
|
15
|
+
email: ineiti.blue
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
21
23
|
- LICENSE
|
22
24
|
- README.md
|
23
25
|
- helper_classes.gemspec
|
@@ -25,11 +27,12 @@ files:
|
|
25
27
|
- lib/helper_classes/arraysym.rb
|
26
28
|
- lib/helper_classes/dputs.rb
|
27
29
|
- lib/helper_classes/hashaccessor.rb
|
30
|
+
- lib/helper_classes/platform.rb
|
28
31
|
- lib/helper_classes/readconfig.rb
|
29
|
-
- lib/helper_classes/service.rb
|
30
32
|
- lib/helper_classes/system.rb
|
31
33
|
- lib/helper_classes/timing.rb
|
32
34
|
- lib/helper_classes/virtual.rb
|
35
|
+
- test/hc_hashaccessor.rb
|
33
36
|
- test/hc_service.rb
|
34
37
|
- test/test.rb
|
35
38
|
- test/test_arraysym.rb
|
@@ -39,7 +42,7 @@ files:
|
|
39
42
|
- test/test_system.rb
|
40
43
|
homepage: https://github.com/ineiti/HelperClasses
|
41
44
|
licenses:
|
42
|
-
-
|
45
|
+
- GPL-3.0
|
43
46
|
metadata: {}
|
44
47
|
post_install_message:
|
45
48
|
rdoc_options: []
|
@@ -52,16 +55,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
55
|
version: '0'
|
53
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
57
|
requirements:
|
55
|
-
- - "
|
58
|
+
- - ">"
|
56
59
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
60
|
+
version: 1.3.1
|
58
61
|
requirements: []
|
59
62
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.6.13
|
61
64
|
signing_key:
|
62
65
|
specification_version: 4
|
63
66
|
summary: Hash._accessor Array.to_sym and DPuts
|
64
67
|
test_files:
|
68
|
+
- test/hc_hashaccessor.rb
|
65
69
|
- test/hc_service.rb
|
66
70
|
- test/test.rb
|
67
71
|
- test/test_arraysym.rb
|