[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

autoinstall gems

S2

3/13/2008 8:18:00 AM

Is there a way to autoinstall a gem when it is "required" in an .rb file?

say I have:


-----
#!/usr/bin/ruby

require 'rubygems'
require 'HOTP'

puts HOTP.new.calculate_hotp('12345', 1, 6)
-----


Is there a way to make rubygems autoinstall the HOTP gem if it is not
already installed?
7 Answers

Joachim Glauche

3/13/2008 12:07:00 PM

0

S2 wrote:

> Is there a way to make rubygems autoinstall the HOTP gem if it is not
> already installed?

I think there is a right problem there. Installing gems *normally*
require super user rights (on modern OS).
--
Posted via http://www.ruby-....

S2

3/13/2008 1:05:00 PM

0

Joachim Glauche wrote:
> S2 wrote:
>
>> Is there a way to make rubygems autoinstall the HOTP gem if it is not
>> already installed?
>
> I think there is a right problem there. Installing gems *normally*
> require super user rights (on modern OS).

Yes, that is true. It would eventually yield a Permission denied error.
But that is an OS configuration problem, not a rubygems one :)

Tom Cloyd

3/13/2008 4:40:00 PM

0

S2 wrote:
> Joachim Glauche wrote:
>> S2 wrote:
>>
>>> Is there a way to make rubygems autoinstall the HOTP gem if it is not
>>> already installed?
>>
>> I think there is a right problem there. Installing gems *normally*
>> require super user rights (on modern OS).
>
> Yes, that is true. It would eventually yield a Permission denied
> error. But that is an OS configuration problem, not a rubygems one :)
>
>
Well, if I may add my very amateur voice here, it seems to me that one
could certainly trap an error and conditionally issue a system call to
engage the installation process at the super user level. The process
would then have to worked through manually, since there often are one or
more interactions which need to occur to complete the installation of
some gems. This would work fine if the person running the programmer has
access to superuser passwords.

Don't know this is the sort of thing you have in mind or not.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


S2

3/13/2008 4:50:00 PM

0

Tom Cloyd wrote:
> S2 wrote:
>> Joachim Glauche wrote:
>>> S2 wrote:
>>>
>>>> Is there a way to make rubygems autoinstall the HOTP gem if it is not
>>>> already installed?
>>> I think there is a right problem there. Installing gems *normally*
>>> require super user rights (on modern OS).
>> Yes, that is true. It would eventually yield a Permission denied
>> error. But that is an OS configuration problem, not a rubygems one :)
>>
>>
> Well, if I may add my very amateur voice here, it seems to me that one
> could certainly trap an error and conditionally issue a system call to
> engage the installation process at the super user level. The process
> would then have to worked through manually, since there often are one or
> more interactions which need to occur to complete the installation of
> some gems. This would work fine if the person running the programmer has
> access to superuser passwords.

Yes, this is a good alternative.

> Don't know this is the sort of thing you have in mind or not.

I thought that rubygems had his way of doing this automagically, but
after reading your response it looks like this is not the case and it's
also not really feasible to do easily.

Tom Cloyd

3/13/2008 5:17:00 PM

0

S2 wrote:
> Tom Cloyd wrote:
>> S2 wrote:
>>> Joachim Glauche wrote:
>>>> S2 wrote:
>>>>
>>>>> Is there a way to make rubygems autoinstall the HOTP gem if it is not
>>>>> already installed?
>>>> I think there is a right problem there. Installing gems *normally*
>>>> require super user rights (on modern OS).
>>> Yes, that is true. It would eventually yield a Permission denied
>>> error. But that is an OS configuration problem, not a rubygems one :)
>>>
>>>
>> Well, if I may add my very amateur voice here, it seems to me that
>> one could certainly trap an error and conditionally issue a system
>> call to engage the installation process at the super user level. The
>> process would then have to worked through manually, since there often
>> are one or more interactions which need to occur to complete the
>> installation of some gems. This would work fine if the person running
>> the programmer has access to superuser passwords.
>
> Yes, this is a good alternative.
>
>> Don't know this is the sort of thing you have in mind or not.
>
> I thought that rubygems had his way of doing this automagically, but
> after reading your response it looks like this is not the case and
> it's also not really feasible to do easily.
>
>
Well, its apparent that when one manually installs a gem ("sudo install
slideshow", for example), those already installed are checked to see if
they need to be updated, but normally calling programmatically upon an
uninstalled gem, in any way, produces an error.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


James Tucker

3/16/2008 4:24:00 PM

0


On 13 Mar 2008, at 08:20, S2 wrote:

> Is there a way to autoinstall a gem when it is "required" in an .rb
> file?

Kind of, but not really. The already discussed stuff is important, but
also is the fact that for some gems (actually quite a number of gems),
the gem name does not match the require. Anyway, enough reasoning,
here's solutioning:

> -----

#!/usr/bin/env ruby
require 'rubygems'

%w[HOTP].each |gemname|
begin
require gemname
rescue LoadError
win = Gem.win_platform? rescue RUBY_PLATFORM =~ /(ms|cyg)win|mingw/
command = "#{'sudo' unless win} gem#{'.bat' if win} install
#{gemname}"
system command
require gemname
end
end

> puts HOTP.new.calculate_hotp('12345', 1, 6)
> -----

Untested, and written in the mail client, anyway, you should get the
idea. N.B. Gem.win_platform? is rubygems 0.9.5 (iirc) and above. The
platform match is *ok*, but far from ideal.

Another odd problem that can come up from this is to ensure that
you're working on the same drive as rubygems. Sadly, some stuff still
doesn't work correctly in different places. That is not really a
problem on *nix, which has a single root (maybe).

>
>
>
> Is there a way to make rubygems autoinstall the HOTP gem if it is
> not already installed?
>


Eric Hodel

3/21/2008 9:55:00 PM

0

On Mar 13, 2008, at 01:20 AM, S2 wrote:
> Is there a way to autoinstall a gem when it is "required" in an .rb
> file?
>
> say I have:
>
>
> -----
> #!/usr/bin/ruby
>
> require 'rubygems'
> require 'HOTP'
>
> puts HOTP.new.calculate_hotp('12345', 1, 6)
> -----
>
>
> Is there a way to make rubygems autoinstall the HOTP gem if it is
> not already installed?

No, as the list of files in a gem is only available after installation.