startor 0.6.0
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 +7 -0
- data/bin/startor +173 -0
- data/lib/Array/all_but_last.rb +24 -0
- data/lib/Array/extract_optionsX.rb +21 -0
- data/lib/Array/lastX.rb +10 -0
- data/lib/File/basename_without_extname.rb +17 -0
- data/lib/File/extname.rb +18 -0
- data/lib/File/self.gsubX.rb +54 -0
- data/lib/FileUtils/where.rb +37 -0
- data/lib/FileUtils/which.rb +20 -0
- data/lib/Files.rb +249 -0
- data/lib/Kernel/run.rb +43 -0
- data/lib/Module/alias_methods.rb +16 -0
- data/lib/OSX/HardwarePort.rb +69 -0
- data/lib/OSX/IfConfig.rb +57 -0
- data/lib/Ordinal/Array.rb +8 -0
- data/lib/Ordinal.rb +155 -0
- data/lib/Platform/OS/OSX/SystemProfiler.rb +36 -0
- data/lib/Platform/OS/OSX.rb +100 -0
- data/lib/Platform/OS/linuxQ.rb +15 -0
- data/lib/Platform/OS/nt_basedQ.rb +16 -0
- data/lib/Platform/OS/osxQ.rb +15 -0
- data/lib/Platform/OS/windowsQ.rb +26 -0
- data/lib/Platform/OS.rb +13 -0
- data/lib/String/capture.rb +20 -0
- data/lib/Thoran/String/Capture/capture.rb +26 -0
- data/lib/Thoran/String/Captures/captures.rb +26 -0
- data/lib/Version.rb +403 -0
- metadata +73 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
# OSX/Hardware.rb
|
2
|
+
# OSX::Hardware
|
3
|
+
|
4
|
+
# 20180209
|
5
|
+
# 0.1.1
|
6
|
+
|
7
|
+
require 'Thoran/String/Captures/captures'
|
8
|
+
|
9
|
+
module OSX
|
10
|
+
class HardwarePort
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def parse(output)
|
15
|
+
hardware_ports = []
|
16
|
+
hardware_port = nil
|
17
|
+
output.each_line do |line|
|
18
|
+
if line == "\n" || line == ""
|
19
|
+
hardware_port = new
|
20
|
+
else
|
21
|
+
label, value = line.captures(/^(.+): (.+)/)
|
22
|
+
case label
|
23
|
+
when 'Hardware Port'; hardware_port.hardware_port = value
|
24
|
+
when 'Device'; hardware_port.device = value
|
25
|
+
when 'Ethernet Address'; hardware_port.ethernet_address = value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
hardware_ports << hardware_port
|
29
|
+
end
|
30
|
+
hardware_ports
|
31
|
+
end
|
32
|
+
|
33
|
+
def all
|
34
|
+
parse(output)
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_by_device(device)
|
38
|
+
all.detect{|hardware_port| hardware_port.device == device}
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def output
|
44
|
+
`networksetup -listallhardwareports`
|
45
|
+
end
|
46
|
+
|
47
|
+
end # class << self
|
48
|
+
|
49
|
+
attr_accessor :hardware_port
|
50
|
+
attr_accessor :device
|
51
|
+
attr_accessor :ethernet_address
|
52
|
+
|
53
|
+
def new(hardware_port:, device:, ethernet_address:)
|
54
|
+
@hardware_port = hardware_port
|
55
|
+
@device = device
|
56
|
+
@ethernet_address = ethernet_address
|
57
|
+
end
|
58
|
+
|
59
|
+
def name
|
60
|
+
@hardware_port
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
if __FILE__ == $0
|
67
|
+
p hardware_ports = OSX::HardwarePort.all
|
68
|
+
p en4 = OSX::HardwarePort.find_by_device('en4')
|
69
|
+
end
|
data/lib/OSX/IfConfig.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# OSX/IfConfig.rb
|
2
|
+
# OSX::IfConfig
|
3
|
+
|
4
|
+
# 20180209
|
5
|
+
# 0.2.0
|
6
|
+
|
7
|
+
# Changes since 0.1:
|
8
|
+
# 1. + OSX namespace, under the assumption that the output of ifconfig on OSX is different from other operating systems.
|
9
|
+
require 'Thoran/String/Captures/captures'
|
10
|
+
|
11
|
+
module OSX
|
12
|
+
class IfConfig
|
13
|
+
|
14
|
+
def new(output = nil)
|
15
|
+
@output = output
|
16
|
+
end
|
17
|
+
|
18
|
+
def interfaces
|
19
|
+
parse.keys
|
20
|
+
end
|
21
|
+
|
22
|
+
def active_interfaces
|
23
|
+
parse.select do |interface, details|
|
24
|
+
details.any?{|detail| detail =~ /status: active/}
|
25
|
+
end.keys
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def output
|
31
|
+
@output || `ifconfig -a`
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse
|
35
|
+
interfaces = {}
|
36
|
+
interface = nil
|
37
|
+
output.each_line do |line|
|
38
|
+
if line =~ /^\t/
|
39
|
+
interfaces[interface] << line.sub(/^\t/, '')
|
40
|
+
else
|
41
|
+
interface, rest_of_line = line.captures(/^(.+?): (.+)$/)
|
42
|
+
interfaces[interface] = [rest_of_line]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
interfaces
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if __FILE__ == $0
|
52
|
+
require 'pp'
|
53
|
+
ic = OSX::IfConfig.new
|
54
|
+
pp ic.send(:parse)
|
55
|
+
ic.interfaces
|
56
|
+
ic.active_interfaces
|
57
|
+
end
|
data/lib/Ordinal.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Ordinal.rb
|
2
|
+
# Ordinal
|
3
|
+
|
4
|
+
# 20140316
|
5
|
+
# 0.2.0
|
6
|
+
|
7
|
+
# Description: This is a collection of methods which relies upon an object having an entries method.
|
8
|
+
|
9
|
+
# Notes:
|
10
|
+
# 1. This was originally meant to be extensions on Enumerable, as can be seen in version 0.0.0, but I decided that any object which provides for an ordered list of entries by way of having an entries method should be able to make use of this.
|
11
|
+
|
12
|
+
# Changes since 0.1:
|
13
|
+
# 1. - require 'File/self.relative_path' from Ordinal/Array and replaced with require_relative.
|
14
|
+
# 2. - require 'File/self.relative_path' from Ordinal/Array and replaced with require_relative.
|
15
|
+
|
16
|
+
module Ordinal
|
17
|
+
|
18
|
+
def first
|
19
|
+
entries[0]
|
20
|
+
end
|
21
|
+
|
22
|
+
def second
|
23
|
+
entries[1]
|
24
|
+
end
|
25
|
+
|
26
|
+
def third
|
27
|
+
entries[2]
|
28
|
+
end
|
29
|
+
|
30
|
+
def fourth
|
31
|
+
entries[3]
|
32
|
+
end
|
33
|
+
|
34
|
+
def fifth
|
35
|
+
entries[4]
|
36
|
+
end
|
37
|
+
|
38
|
+
def sixth
|
39
|
+
entries[5]
|
40
|
+
end
|
41
|
+
|
42
|
+
def seventh
|
43
|
+
entries[6]
|
44
|
+
end
|
45
|
+
|
46
|
+
def eighth
|
47
|
+
entries[7]
|
48
|
+
end
|
49
|
+
|
50
|
+
def ninth
|
51
|
+
entries[8]
|
52
|
+
end
|
53
|
+
|
54
|
+
def tenth
|
55
|
+
entries[9]
|
56
|
+
end
|
57
|
+
|
58
|
+
def eleventh
|
59
|
+
entries[10]
|
60
|
+
end
|
61
|
+
|
62
|
+
def twelfth
|
63
|
+
entries[11]
|
64
|
+
end
|
65
|
+
|
66
|
+
def thirteenth
|
67
|
+
entries[12]
|
68
|
+
end
|
69
|
+
|
70
|
+
def fourteenth
|
71
|
+
entries[13]
|
72
|
+
end
|
73
|
+
|
74
|
+
def fifteenth
|
75
|
+
entries[14]
|
76
|
+
end
|
77
|
+
|
78
|
+
def sixteenth
|
79
|
+
entries[15]
|
80
|
+
end
|
81
|
+
|
82
|
+
def seventeenth
|
83
|
+
entries[16]
|
84
|
+
end
|
85
|
+
|
86
|
+
def eighteenth
|
87
|
+
entries[17]
|
88
|
+
end
|
89
|
+
|
90
|
+
def ninteenth
|
91
|
+
entries[18]
|
92
|
+
end
|
93
|
+
|
94
|
+
def twentieth
|
95
|
+
entries[19]
|
96
|
+
end
|
97
|
+
|
98
|
+
def tenth_last
|
99
|
+
entries[count - 10]
|
100
|
+
end
|
101
|
+
|
102
|
+
def ninth_last
|
103
|
+
entries[count - 9]
|
104
|
+
end
|
105
|
+
|
106
|
+
def eighth_last
|
107
|
+
entries[count - 8]
|
108
|
+
end
|
109
|
+
|
110
|
+
def seventh_last
|
111
|
+
entries[count - 7]
|
112
|
+
end
|
113
|
+
|
114
|
+
def sixth_last
|
115
|
+
entries[count - 6]
|
116
|
+
end
|
117
|
+
|
118
|
+
def fifth_last
|
119
|
+
entries[count - 5]
|
120
|
+
end
|
121
|
+
|
122
|
+
def fourth_last
|
123
|
+
entries[count - 4]
|
124
|
+
end
|
125
|
+
|
126
|
+
def third_last
|
127
|
+
entries[count - 3]
|
128
|
+
end
|
129
|
+
|
130
|
+
def second_last
|
131
|
+
entries[count - 2]
|
132
|
+
end
|
133
|
+
|
134
|
+
def last
|
135
|
+
entries[count - 1]
|
136
|
+
end
|
137
|
+
alias_method :first_last, :last
|
138
|
+
|
139
|
+
def all_but_first
|
140
|
+
entries.drop(1)
|
141
|
+
end
|
142
|
+
|
143
|
+
def all_but_last
|
144
|
+
entries.take(count - 1)
|
145
|
+
end
|
146
|
+
|
147
|
+
def all_but_first_and_last
|
148
|
+
entries.all_but_first.all_but_last
|
149
|
+
end
|
150
|
+
|
151
|
+
def first_and_last
|
152
|
+
[entries.first] + [entries.last]
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Platform/OS/OSX/SystemProfiler.rb
|
2
|
+
# Platform::OS::OSX::SystemProfiler
|
3
|
+
|
4
|
+
# Description: This uses the built-in system_profiler command on OSX to get access to the version numbers on OSX between 10.4 and 10.9,
|
5
|
+
# or more generally any version of OSX which has a system_profiler command and which returns results in the same format.
|
6
|
+
|
7
|
+
require 'Ordinal/Array'
|
8
|
+
require 'String/grep'
|
9
|
+
|
10
|
+
module Platform
|
11
|
+
module OS
|
12
|
+
module OSX
|
13
|
+
module SystemProfiler
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def system_version
|
18
|
+
`system_profiler SPSoftwareDataType`.force_encoding('UTF-8').grep(/System Version/).split(': ').second.split.fourth
|
19
|
+
end
|
20
|
+
|
21
|
+
def major_system_version
|
22
|
+
system_version.split('.').first.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def minor_system_version
|
26
|
+
system_version.split('.').second.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def tiny_system_version
|
30
|
+
system_version.split('.').third.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Platform/OS/OSX.rb
|
2
|
+
# Platform::OS::OSX
|
3
|
+
|
4
|
+
require 'Files'
|
5
|
+
require 'Platform/OS/OSX/SystemProfiler'
|
6
|
+
require 'Thoran/String/Capture/capture'
|
7
|
+
require 'Version'
|
8
|
+
|
9
|
+
module Platform
|
10
|
+
module OS
|
11
|
+
module OSX
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def version
|
16
|
+
Version.new(version_string)
|
17
|
+
end
|
18
|
+
|
19
|
+
def version_string
|
20
|
+
detect(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def name
|
24
|
+
detect.split('_').collect{|e| e.capitalize}.join(' ')
|
25
|
+
end
|
26
|
+
|
27
|
+
def detect(return_version_string = false)
|
28
|
+
if return_version_string
|
29
|
+
SystemProfiler.system_version
|
30
|
+
else
|
31
|
+
self.methods(false).select{|e| e =~ /\?$/}.detect{|e| send(e)}.to_s.capture(/^(\w+)\?/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def tiger?
|
36
|
+
SystemProfiler.major_system_version == 10 && SystemProfiler.minor_system_version == 4
|
37
|
+
end
|
38
|
+
|
39
|
+
def leopard?
|
40
|
+
SystemProfiler.major_system_version == 10 && SystemProfiler.minor_system_version == 5
|
41
|
+
end
|
42
|
+
|
43
|
+
def snow_leopard?
|
44
|
+
SystemProfiler.major_system_version == 10 && SystemProfiler.minor_system_version == 6
|
45
|
+
end
|
46
|
+
|
47
|
+
def lion?
|
48
|
+
SystemProfiler.major_system_version == 10 && SystemProfiler.minor_system_version == 7
|
49
|
+
end
|
50
|
+
|
51
|
+
def mountain_lion?
|
52
|
+
SystemProfiler.major_system_version == 10 && SystemProfiler.minor_system_version == 8
|
53
|
+
end
|
54
|
+
|
55
|
+
def mavericks?
|
56
|
+
SystemProfiler.major_system_version == 10 && SystemProfiler.minor_system_version == 9
|
57
|
+
end
|
58
|
+
|
59
|
+
def application_paths(username = nil)
|
60
|
+
system_application_paths + user_application_paths(username)
|
61
|
+
end
|
62
|
+
|
63
|
+
def system_application_paths
|
64
|
+
applications_in_directory('/Applications')
|
65
|
+
end
|
66
|
+
|
67
|
+
def user_application_paths(username = nil)
|
68
|
+
if username
|
69
|
+
applications_in_directory("/Users/#{username}/Applications")
|
70
|
+
else
|
71
|
+
usernames.collect do |username|
|
72
|
+
applications_in_directory("/Users/#{username}/Applications")
|
73
|
+
end.flatten
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def usernames
|
78
|
+
`dscl . list /users`.split("\n")
|
79
|
+
.reject{|username| username =~ /^_/}
|
80
|
+
.reject{|username| %w{daemon nobody root}.include?(username)}
|
81
|
+
end
|
82
|
+
|
83
|
+
def application_path_for_application(application_name)
|
84
|
+
application_paths.detect do |application_path|
|
85
|
+
File.basename(application_path) == application_name ||
|
86
|
+
File.basename(application_path, '.app') == application_name
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def start(application_name)
|
91
|
+
system("open #{application_path_for_application(application_name)}")
|
92
|
+
end
|
93
|
+
|
94
|
+
def applications_in_directory(directory)
|
95
|
+
Files.new(path: directory, pattern: '*.app').collect{|file| file.path}
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Platform/OS/nt_basedQ.rb
|
2
|
+
# Platform::OS#nt_based?
|
3
|
+
|
4
|
+
module Platform
|
5
|
+
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def nt_based?
|
9
|
+
if ENV.has_key?('OS') && ENV['OS'] =~ /nt/i # it's one of the NT-based operating systems (NT, 2000, or XP) (What about Vista, 7, and 8?)
|
10
|
+
true
|
11
|
+
else # it's one of DOS, Windows 95, 98, or ME
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Platform/OS/windowsQ.rb
|
2
|
+
# Platform::OS#windows?
|
3
|
+
|
4
|
+
module Platform
|
5
|
+
module OS
|
6
|
+
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def windows?
|
10
|
+
mswin32? || mingw32? || cygwin?
|
11
|
+
end
|
12
|
+
|
13
|
+
def mswin32?
|
14
|
+
RUBY_PLATFORM =~ /mswin32/ ? true : false
|
15
|
+
end
|
16
|
+
|
17
|
+
def mingw32?
|
18
|
+
RUBY_PLATFORM =~ /mingw32/ ? true : false
|
19
|
+
end
|
20
|
+
|
21
|
+
def cygwin?
|
22
|
+
RUBY_PLATFORM =~ /cygwin/ ? true : false
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/Platform/OS.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Thoran/String/Capture/capture.rb
|
2
|
+
# Thoran::String::Capture#capture
|
3
|
+
|
4
|
+
# 20161109
|
5
|
+
# 0.3.0
|
6
|
+
|
7
|
+
# Changes since 0.2:
|
8
|
+
# 1. + Thoran namespace.
|
9
|
+
|
10
|
+
module Thoran
|
11
|
+
module String
|
12
|
+
module Capture
|
13
|
+
|
14
|
+
def capture(regex)
|
15
|
+
if md = self.match(regex)
|
16
|
+
md[1]
|
17
|
+
else
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
String.send(:include, Thoran::String::Capture)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Thoran/String/Captures/captures.rb
|
2
|
+
# Thoran::String::Captures#captures
|
3
|
+
|
4
|
+
# 20171118
|
5
|
+
# 0.3.0
|
6
|
+
|
7
|
+
# Changes:
|
8
|
+
# 1. Returning an empty array when there's no match, since that's more consistent.
|
9
|
+
|
10
|
+
module Thoran
|
11
|
+
module String
|
12
|
+
module Captures
|
13
|
+
|
14
|
+
def captures(regex)
|
15
|
+
if md = self.match(regex)
|
16
|
+
md.captures
|
17
|
+
else
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
String.send(:include, Thoran::String::Captures)
|