webget_gemini 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/lib/webget_gemini.rb +156 -0
- data/test/webget_gemini/webget_gemini_test.rb +23 -0
- metadata +97 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# = Gemini: Gem Initialization Helper
|
2
|
+
#
|
3
|
+
# Simple gem methods.
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
# require 'gemini'
|
7
|
+
#
|
8
|
+
# Gemini.installed?(:name=>'passenger',:version=>'2.0.0')
|
9
|
+
# => true
|
10
|
+
#
|
11
|
+
# Gemini.install(:name=>'passenger',:version=>'2.0.0')
|
12
|
+
# => install passenger 2.0.0 if necessary
|
13
|
+
#
|
14
|
+
# Gemini.find(:name=>'passenger')
|
15
|
+
# => all gemspecs with name 'passenger'
|
16
|
+
#
|
17
|
+
# Gemini.find(:name=>'passenger',:version=>version_requiremens)
|
18
|
+
# => all gemspecs with name 'passenger' that match the requirments
|
19
|
+
#
|
20
|
+
##
|
21
|
+
|
22
|
+
require 'rexml/document'
|
23
|
+
require 'rubygems'
|
24
|
+
require 'webget_commander'
|
25
|
+
|
26
|
+
class Gemini
|
27
|
+
|
28
|
+
TRUST_POLICY_NICKNAME={'no'=>'NoSecurity','low'=>'LowSecurity','medium'=>'MediumSecurity','high'=>'HighSecurity'}
|
29
|
+
|
30
|
+
# Return true iff a given name is installed
|
31
|
+
#
|
32
|
+
# Options
|
33
|
+
# - name e.g. "foo" [required]
|
34
|
+
# - version string e.g. ">=1.2.3"
|
35
|
+
|
36
|
+
def self.installed?(ops)
|
37
|
+
name,version = [:name,:version].map{|k| ops[k]||ops[k.to_s]}
|
38
|
+
dep = Gem::Dependency.new name, (version||Gem::Requirement.default)
|
39
|
+
!Gem.source_index.search(dep).empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Return an array of all gemspecs that match the name and version requirements
|
44
|
+
#
|
45
|
+
# Options:
|
46
|
+
# - name e.g. "foo" [required]
|
47
|
+
# - version: version requirements as defined in Gem.source_index.find_name
|
48
|
+
|
49
|
+
def self.find(ops)
|
50
|
+
name,version = [:name,:version].map{|k| ops[k]||ops[k.to_s]}
|
51
|
+
return Gem.source_index.find_name(name,version||[])
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Install a gem, if needed, by running a system command.
|
56
|
+
#
|
57
|
+
# This dispatches on the first parameter:
|
58
|
+
# - nil: install_from_rails_root_cofig_gems_xml
|
59
|
+
# - File: install_from_xml_file
|
60
|
+
# - String: install_from_xml_text
|
61
|
+
# - REXML::Document: install_from_xml_doc
|
62
|
+
# - Array: install_from_array
|
63
|
+
# - Hash: install_from_options
|
64
|
+
#
|
65
|
+
# Return status, stdout, stderr
|
66
|
+
|
67
|
+
def self.install(x=nil)
|
68
|
+
if x.class==NilClass then return self.install_from_rails_root_config_gems_xml end
|
69
|
+
if x.class==File then return self.install_from_file(x) end
|
70
|
+
if x.class==String then return self.install_from_xml_text(x) end
|
71
|
+
if x.class==REXML::Document then return self.install_from_xml_doc(x) end
|
72
|
+
if x.class==Array then return self.install_from_array(x) end
|
73
|
+
return self.install_from_options(x)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.install_from_rails_root_config_gems_xml
|
77
|
+
return self.install_from_xml_file(File.new(RAILS_ROOT+'/config/gems.xml'))
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.install_from_xml_file(file)
|
81
|
+
return self.install_from_xml_text(File.read(x))
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.install_from_xml_text
|
85
|
+
return self.install_from_xml_doc(REXML::Document.new(x))
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.install_from_xml_doc
|
89
|
+
return self.install_from_array(x.elements.each('gems/gem'){}.map{|e| e.attributes})
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.install_from_array(array)
|
93
|
+
return x.map{|options| self.install(options)}
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
public
|
98
|
+
|
99
|
+
# Install a gem, if needed, by running a system command.
|
100
|
+
#
|
101
|
+
# Options
|
102
|
+
# - name e.g. "foo" [required]
|
103
|
+
# - version e.g. ">=1.2.3"
|
104
|
+
# - trust: no|low|medium|high (same as NoSecurity|LowSecurity|MediumSecurity|HighSecurity)
|
105
|
+
# - append: anything to append to the gem command e.g. " --no-ri --no-rdoc --no-user-install"
|
106
|
+
#
|
107
|
+
|
108
|
+
def self.install_from_options(options)
|
109
|
+
return installed?(options) \
|
110
|
+
? [nil,nil,nil] \
|
111
|
+
: commander(self.install_command(options))
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
# Create the system command to do a gem install
|
116
|
+
#
|
117
|
+
# Options
|
118
|
+
# - name e.g. "foo" [required]
|
119
|
+
# - version e.g. ">=1.2.3"
|
120
|
+
# - trust: no|low|medium|high (aka NoSecurity|LowSecurity|MediumSecurity|HighSecurity)
|
121
|
+
# - append (aka installing): anything to append to the gem install command e.g. " --no-ri --no-rdoc --no-user-install"
|
122
|
+
#
|
123
|
+
# Return the command as a string
|
124
|
+
|
125
|
+
def self.install_command(ops)
|
126
|
+
name,version,trust,source,append,installing = [:name,:version,:trust,:source,:append,:installing].map{|k| ops[k]||ops[k.to_s]}
|
127
|
+
append||=installing
|
128
|
+
return "sudo gem install #{name}" +
|
129
|
+
(version ? " --version \"#{version}\"" : '' ) +
|
130
|
+
(trust ? " --trust-policy #{TRUST_POLICY_NICKNAME[trust]||trust}" : '') +
|
131
|
+
(source ? [*source].map{|x| " --source \"#{x}\""}.join : '') +
|
132
|
+
(append ? (' '+append) : '')
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
# Return a lookup hash of all the gems installed on the system,
|
138
|
+
# by running the system command 'sudo gem list'.
|
139
|
+
#
|
140
|
+
# - hash key is a gem name.
|
141
|
+
# - hash value is an array of the gem's installed version numbers.
|
142
|
+
|
143
|
+
def self.sudo_gem_list
|
144
|
+
@sudo_gem_list=`sudo gem list`.split(/\n/).map{|line| line.split(/[ \,\(\)]+/)}.inject({}){|h,v| h[v[0]]=v[1,v.length]; h}
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
# Return true iff the sudo_gem_list hash shows a given gem is installed.
|
149
|
+
|
150
|
+
def self.sudo_gem_list_installed?(ops)
|
151
|
+
name,version = [:name,:version].map{|k| ops[k]||ops[k.to_s]}
|
152
|
+
self.sudo_gem_list[name] and (!version or self.sudo_gem_list[name].include?(version))
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'webget_gemini'
|
3
|
+
|
4
|
+
class GeminiTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_gemini_installed_false
|
7
|
+
assert(!Gemini.installed?(:name=>'gem-should-not-exist',:version=>'9.9.9'))
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_gemini_install_command
|
11
|
+
assert_equal('sudo gem install foo',Gemini.install_command(:name=>'foo'))
|
12
|
+
assert_equal('sudo gem install foo --version "9.9.9"',Gemini.install_command(:name=>'foo',:version=>'9.9.9'))
|
13
|
+
assert_equal('sudo gem install foo --trust-policy HighSecurity',Gemini.install_command(:name=>'foo',:trust=>'high'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_gemini_install
|
17
|
+
status,stdout,stderr=Gemini.install(:name=>'gem-should-not-exist',:version=>'9.9.9')
|
18
|
+
assert_equal(2,status)
|
19
|
+
assert_equal('',stdout)
|
20
|
+
assert_equal('ERROR: could not find gem gem-should-not-exist locally or in a repository',stderr)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webget_gemini
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- WebG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MIGbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQG
|
27
|
+
A1UEBxMNU2FuIEZyYW5jaXNjbzETMBEGA1UEChMKV2ViR2V0LmNvbTETMBEGA1UE
|
28
|
+
CxMKV2ViR2V0LmNvbTETMBEGA1UEAxMKV2ViR2V0LmNvbTEgMB4GCSqGSIb3DQEJ
|
29
|
+
ARYRd2ViZ2V0QHdlYmdldC5jb22CCQCJUqhJA0GmSDAMBgNVHRMEBTADAQH/MA0G
|
30
|
+
CSqGSIb3DQEBBQUAA4GBADzVXlwuff0/w3yK4LflGKKhtC3oChIrwmSyP6tk628N
|
31
|
+
BHokpc4Kz63xSXqzYTnBS7rFBwlYThtNalQeWmoUjGh3Z0ZR0JlhU0ln8899LuJ3
|
32
|
+
DXnLFY0cVuBnNDMOOFl8vk1qIcZjcTovhzgcixpG6Uk5qmUsKHRLQf4oQJx7TfLK
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
|
35
|
+
date: 2009-10-27 00:00:00 -07:00
|
36
|
+
default_executable:
|
37
|
+
dependencies:
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: open4
|
40
|
+
type: :runtime
|
41
|
+
version_requirement:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.6
|
47
|
+
version:
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: webget_commander
|
50
|
+
type: :runtime
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.0.1
|
57
|
+
version:
|
58
|
+
description:
|
59
|
+
email: webget@webget.com
|
60
|
+
executables: []
|
61
|
+
|
62
|
+
extensions: []
|
63
|
+
|
64
|
+
extra_rdoc_files: []
|
65
|
+
|
66
|
+
files:
|
67
|
+
- lib/webget_gemini.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://webget.com/
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: "WebGet Gemini: provides gem initial setup method to see if a gem is installed"
|
96
|
+
test_files:
|
97
|
+
- test/webget_gemini/webget_gemini_test.rb
|
metadata.gz.sig
ADDED
Binary file
|