specs 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ # FreeBSD License
2
+
3
+ # Copyright 2012 Andrew Pennebaker. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation and/or
12
+ other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED
15
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
17
+ SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/bin/specs ADDED
@@ -0,0 +1,10 @@
1
+ #!/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "specs"
5
+
6
+ begin
7
+ main
8
+ rescue Interrupt => e
9
+ nil
10
+ end
data/lib/aspects/as.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Recipe
2
+ def self.as
3
+ # Windows
4
+ if Os.windows?
5
+ "as -version"
6
+ # Assume OS is a Unix variant.
7
+ # as hangs by default, waiting for stdin to end;
8
+ # Send EOF via /dev/null.
9
+ #
10
+ # Don't create spurious a.out file.
11
+ else
12
+ "as -o /dev/null -version < /dev/null"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Recipe
2
+ def self.bios
3
+ if Os.windows?
4
+ "systeminfo | findstr /B /C:\"BIOS Version\""
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Recipe
2
+ def self.chocolatey
3
+ if Os.windows?
4
+ "chocolatey version"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module Recipe
2
+ def self.chrome
3
+ # Assumes Chrome installed in default directory.
4
+ if Os.mac?
5
+ "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --version 2>&1 | grep -v Unsure" # Redirect stderr to stdout
6
+ elsif Os.windows?
7
+ if Os.x86_64?
8
+ "%UserProfile%\\AppData\\Local\\Google\\Chrome\\Application\\chrome --version"
9
+ else
10
+ "\"C:\\Program Files\\Google\\Chrome\\Application\\chrome\" --version"
11
+ end
12
+ # Assumes
13
+ # * binary is google-chrome.
14
+ # * binary is in PATH.
15
+ else
16
+ "google-chrome --version"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Recipe
2
+ def self.cpu
3
+ if Os.windows?
4
+ "wmic cpu get NumberOfCores, NumberOfLogicalProcessors"
5
+ elsif Os.mac?
6
+ [
7
+ "system_profiler | grep Cores: ",
8
+ "system_profiler | grep Processors:"
9
+ ]
10
+ else
11
+ "cat /proc/cpuinfo | grep processor | wc -l"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Recipe
2
+ def self.firefox
3
+ # Assumes Firefox is installed in the default directory.
4
+ if Os.windows?
5
+ "C:\\Program Files (x86)\\Mozilla Firefox\\firefox --version"
6
+ elsif Os.mac?
7
+ "/Applications/Firefox.app/Contents/MacOS/firefox --version"
8
+ # Assumes firefox in PATH.
9
+ else
10
+ "firefox --version"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # Module name must be filename, minus .rb, in CamelCase.
2
+ module Recipe
3
+ # ModuleName.command returns the appropriate command line instruction for returning the relevant specifications.
4
+ # OS-contextual instructions can be modulated by querying the Os module (see the root specs Ruby code).
5
+ def self.hardware
6
+ # Use environment variable.
7
+ if Os.windows?
8
+ "systeminfo | findstr /B /C:\"System Manufacturer\" /C:\"System Model\""
9
+ # Produces a noticeable delay.
10
+ elsif Os.mac?
11
+ "system_profiler | grep 'Model Identifier'"
12
+ # Assume:
13
+ # * OS is a Unix variant.
14
+ # * dmidecode is installed.
15
+ else
16
+ "sudo dmidecode -t system | grep Manufacturer|Product"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Recipe
2
+ def self.inkscape
3
+ # Assumes Inkscape is installed in default directory.
4
+ if Os.windows?
5
+ if Os.x86_64?
6
+ "C:\\Program Files (x86)\\Inkscape\\inkscape --version"
7
+ elsif Os.x86?
8
+ "\"C:\\Program Files\\Inkscape\\inkscape\" --version"
9
+ end
10
+ elsif Os.mac?
11
+ "/Applications/Inkscape.app/Contents/Resources/bin/inkscape --version"
12
+ # Assumes:
13
+ # * OS is a Unix variant.
14
+ # * inkscape is in PATH.
15
+ else
16
+ "inkscape --version"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Recipe
2
+ def self.latex
3
+ if Os.unix?
4
+ "pdflatex --version"
5
+ end
6
+ end
7
+ end
data/lib/aspects/ld.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Recipe
2
+ def self.ld
3
+ "ld -v"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Recipe
2
+ def self.lua
3
+ "lua -v"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Recipe
2
+ def self.net
3
+ "ruby -e \"require 'net/http'; puts Net::HTTP.new('icanhazip.com').request(Net::HTTP::Get.new('/', {'User-Agent'=>'curl'})).body\""
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module Recipe
2
+ def self.npm
3
+ "npm --version"
4
+ end
5
+
6
+ def self.js
7
+ "node --version"
8
+ end
9
+
10
+ def self.node
11
+ [npm, js]
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Recipe
2
+ def self.opera
3
+ # Assumes opera in PATH.
4
+ if Os.unix? and not Os.mac?
5
+ "opera -version"
6
+ # Opera for Mac/Windows does not support the -version command line option.
7
+ # # Assumes Opera is installed in the default directory.
8
+ # elsif Os.mac?
9
+ # "/Applications/Opera.app/Contents/MacOS/Opera -version"
10
+ # elsif Os.windows?
11
+ # "C:\\Program Files (x86)\\Opera\\opera -version"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Recipe
2
+ def self.ppm
3
+ "ppm --version"
4
+ end
5
+
6
+ def self.cpan
7
+ "cpan --version"
8
+ end
9
+
10
+ def self.pl
11
+ "perl --version"
12
+ end
13
+
14
+ def self.perl
15
+ [ppm, cpan, pl]
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Recipe
2
+ def self.powershell
3
+ if Os.windows?
4
+ "@powershell Get-Host"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Recipe
2
+ def self.ram
3
+ if Os.windows?
4
+ "systeminfo | findstr /C:\"Total Physical Memory\""
5
+ elsif Os.mac?
6
+ "system_profiler | grep 'Memory:'"
7
+ else
8
+ "grep MemTotal /proc/meminfo"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Recipe
2
+ def self.rubygems
3
+ "gem --version"
4
+ end
5
+
6
+ def self.rb
7
+ "ruby --version"
8
+ end
9
+
10
+ def self.ruby
11
+ [rubygems, rb]
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Recipe
2
+ def self.shell
3
+ if Os.windows?
4
+ "echo %cmdextversion%"
5
+ elsif Os.unix?
6
+ "sh --version"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Recipe
2
+ def self.virtualbox
3
+ # Assumes Firefox is installed in the default directory.
4
+ if Os.windows?
5
+ if Os.x86?
6
+ "\"C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage\" --version"
7
+ elsif Os.x86_64?
8
+ "C:\\Program Files (x86)\\Oracle\\VirtualBox\\VBoxManage --version"
9
+ end
10
+ elsif Os.mac?
11
+ "/Applications/Firefox.app/Contents/MacOS/firefox --version"
12
+ # Assumes firefox in PATH.
13
+ else
14
+ "firefox --version"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Recipe
2
+ def self.xcode
3
+ if Os.mac?
4
+ "xcodebuild -version"
5
+ end
6
+ end
7
+ end
data/lib/specs.rb ADDED
@@ -0,0 +1,266 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Author:: Andrew Pennebaker
4
+ #
5
+ # Copyright:: Copyright 2012 Andrew Pennebaker
6
+ #
7
+ # == Synopsis
8
+ #
9
+ # specs - Get system specs easily
10
+ #
11
+ # == Usage
12
+ #
13
+ # specs [aspects]
14
+ #
15
+ # Example:
16
+ #
17
+ # specs ruby os hardware
18
+ #
19
+ # By default, aspects are os and hardware.
20
+ #
21
+ # If an aspect is not installed, its output may be omitted.
22
+ #
23
+ # --help, -h:
24
+ # show usage info for specs
25
+ #
26
+ # --version, -v:
27
+ # print specs' own version
28
+
29
+ require "getoptlong"
30
+
31
+ require "pathname"
32
+
33
+ SPECS_VERSION = "0.2"
34
+ SPECS_VERSION_STRING = "specs #{SPECS_VERSION}"
35
+ SPECS_HOME_PAGE = "https://github.com/mcandre/specs#readme"
36
+
37
+ SPECS_DIR = Pathname.new(File.dirname(__FILE__))
38
+
39
+ # Get the basic operating system name reliably, even in JRuby
40
+ # Useful for OS-contextual command line instructions.
41
+ #
42
+ # E.g., "C:\Program Files (x86)\Mozilla Firefox\firefox --version" in Windows vs
43
+ # "/Applications/Firefox.app/Contents/MacOS/firefox --version" in Mac vs
44
+ # "firefox --version" in Unix
45
+ #
46
+ module Os
47
+ def self.raw
48
+ # Config deprecated in Ruby 1.9
49
+ RbConfig::CONFIG["host_os"]
50
+ end
51
+
52
+ # A series of OS descriptions.
53
+ # Not all of these are mutually exclusive.
54
+
55
+ def self.windows?
56
+ self.raw =~ /cygwin|mswin|mingw|bccwin|wince|emx/
57
+ end
58
+
59
+ def self.mingw?
60
+ self.raw =~ /cygwin|mingw/
61
+ end
62
+
63
+ def self.mac?
64
+ self.raw =~ /darwin/
65
+ end
66
+
67
+ def self.unix?
68
+ not self.windows?
69
+ end
70
+
71
+ def self.haiku?
72
+ self.raw =~ /haiku/
73
+ end
74
+
75
+ def self.linux?
76
+ self.unix? and not self.mac? and not self.haiku?
77
+ end
78
+
79
+ def self.x86_64?
80
+ RbConfig::CONFIG["arch"] =~ /64/
81
+ end
82
+
83
+ def self.x86?
84
+ !self.x86_64?
85
+ end
86
+ end
87
+
88
+ module Recipe
89
+ def self.command_not_found
90
+ # Windows but not MinGW
91
+ if Os.windows? and !Os.mingw?
92
+ "not recognized as an internal or external command"
93
+ # MinGW or other Unix variant.
94
+ else
95
+ "command not found"
96
+ end
97
+ end
98
+
99
+ def self.os
100
+ if Os.windows?
101
+ "systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\""
102
+ elsif Os.mac?
103
+ "system_profiler SPSoftwareDataType | grep 'System Version'"
104
+ elsif Os.linux?
105
+ "lsb_release -a"
106
+ # Unix
107
+ else
108
+ "uname -a"
109
+ end
110
+ end
111
+
112
+ def self.arch
113
+ "ruby -rrbconfig -e 'puts RbConfig::CONFIG[\"arch\"]'"
114
+ end
115
+
116
+ def self.specs
117
+ SPECS_VERSION_STRING
118
+ end
119
+
120
+ def self.ruby_v
121
+ RUBY_VERSION
122
+ end
123
+
124
+ def self.ruby1_8?
125
+ RUBY_VERSION =~ /^1\.8/
126
+ end
127
+
128
+ def self.ruby1_9?
129
+ RUBY_VERSION =~ /^1\.9/
130
+ end
131
+
132
+ def self.rubygems
133
+ "gem --version"
134
+ end
135
+
136
+ def self.rb
137
+ "ruby --version"
138
+ end
139
+
140
+ def self.ruby
141
+ [rubygems, rb]
142
+ end
143
+ end
144
+
145
+ BUILTINS = ["specs", "os", "arch", "ruby"]
146
+
147
+ SEP = File::SEPARATOR
148
+
149
+ # .../specs/aspects
150
+ RECIPE_DIR = [SPECS_DIR, "aspects"].join(SEP)
151
+
152
+ # For a given spec, return the command line instruction(s)
153
+ # that will get the spec's version information.
154
+ def command(aspect)
155
+ # Custom aspect?
156
+ if !BUILTINS.include?(aspect)
157
+ require_path = "#{RECIPE_DIR}#{SEP}#{aspect}.rb"
158
+
159
+ # Attempt to load custom aspect recipe.
160
+ if File.exist?(require_path)
161
+ require require_path
162
+ end
163
+ end
164
+
165
+ # Ruby methods can't use hypens (-),
166
+ # So translate to underscores (_)
167
+ # When looking up known aspects.
168
+ method = aspect.gsub("-", "_").to_sym
169
+
170
+ # Known aspect.
171
+ if Recipe.methods.include?(method)
172
+ Recipe.send(method)
173
+ # Unknown aspect.
174
+ # Default to --version flag.
175
+ else
176
+ "#{aspect} --version"
177
+ end
178
+ end
179
+
180
+ # Print a command line instruction and its output,
181
+ # Emulating a user manually entering the instruction.
182
+ def run(cmd, aspect)
183
+ # Newline to visually separate multiple aspect commands.
184
+ puts ""
185
+
186
+ if cmd.nil?
187
+ puts "#{aspect} aspect not implemented for this system"
188
+
189
+ elsif cmd == SPECS_VERSION_STRING
190
+ puts "specs --version"
191
+ puts SPECS_VERSION_STRING
192
+ else
193
+ puts cmd
194
+
195
+ output = `#{cmd} 2>&1`
196
+
197
+ if output.include?(Recipe.command_not_found)
198
+ puts "#{cmd.split.first} not found"
199
+ else
200
+ puts output
201
+ end
202
+ end
203
+ end
204
+
205
+ def usage
206
+ system "more specs.rb"
207
+ exit
208
+ end
209
+
210
+ def print_specs_own_version
211
+ puts SPECS_VERSION_STRING
212
+ puts SPECS_HOME_PAGE
213
+ end
214
+
215
+ def check_ruby_version
216
+ if RUBY_VERSION =~ /^1\.8/
217
+ puts "Requires Ruby 1.9+"
218
+ puts "http://www.ruby-lang.org/"
219
+ exit
220
+ end
221
+ end
222
+
223
+ def main
224
+ check_ruby_version
225
+
226
+ opts = GetoptLong.new(
227
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
228
+ ["--version", "-v", GetoptLong::NO_ARGUMENT]
229
+ )
230
+
231
+ begin
232
+ opts.each { |option, value|
233
+ case option
234
+ when "--help"
235
+ usage
236
+ when "--version"
237
+ print_specs_own_version
238
+ end
239
+ }
240
+ rescue GetoptLong::InvalidOption
241
+ usage
242
+ end
243
+
244
+ # Default aspects
245
+ aspects = ["specs", "os", "hardware"]
246
+ if !ARGV.empty?
247
+ aspects = ARGV
248
+ end
249
+
250
+ aspects = aspects - ["specs"]
251
+ puts "Specs:\n\n"
252
+ print_specs_own_version
253
+
254
+ aspects.each { |aspect|
255
+ # What does the aspect module say to run
256
+ # in order to retrieve the aspect information?
257
+ cmds = command(aspect)
258
+
259
+ if cmds.nil? or cmds.instance_of?(String)
260
+ run(cmds, aspect)
261
+ # Module returns an array of command strings.
262
+ elsif cmds.instance_of?(Array)
263
+ cmds.each { |cmd| run(cmd, aspect) }
264
+ end
265
+ }
266
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: specs
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Pennebaker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: See README.md for example usage
15
+ email: andrew.pennebaker@gmail.com
16
+ executables:
17
+ - specs
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/specs.rb
22
+ - lib/aspects/as.rb
23
+ - lib/aspects/bios.rb
24
+ - lib/aspects/chocolatey.rb
25
+ - lib/aspects/chrome.rb
26
+ - lib/aspects/cpu.rb
27
+ - lib/aspects/firefox.rb
28
+ - lib/aspects/hardware.rb
29
+ - lib/aspects/inkscape.rb
30
+ - lib/aspects/latex.rb
31
+ - lib/aspects/ld.rb
32
+ - lib/aspects/lua.rb
33
+ - lib/aspects/net.rb
34
+ - lib/aspects/node.rb
35
+ - lib/aspects/opera.rb
36
+ - lib/aspects/perl.rb
37
+ - lib/aspects/powershell.rb
38
+ - lib/aspects/ram.rb
39
+ - lib/aspects/ruby.rb
40
+ - lib/aspects/shell.rb
41
+ - lib/aspects/virtualbox.rb
42
+ - lib/aspects/xcode.rb
43
+ - LICENSE.md
44
+ - bin/specs
45
+ homepage: https://github.com/mcandre/specs
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Software version information at your fingertips
69
+ test_files: []