[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

finding which OS?

d c

11/16/2006 9:17:00 AM

hi -

is there a way to find which OS Ruby is running on?

also, searching for ruby clues, i usually resort to google, wondering
how other people find stuff?

/dc
--
-------------------------------------------
David "DC" Collier
mailto:dc@pikkle.com
+81 (0)80 6521 9559
skype: callto://d3ntaku
-------------------------------------------
Pikkle ????
http://www....
-------------------------------------------

12 Answers

Farrel Lifson

11/16/2006 9:21:00 AM

0

On 16/11/06, dc <lister@pikkle.com> wrote:
> hi -
>
> is there a way to find which OS Ruby is running on?
>
> also, searching for ruby clues, i usually resort to google, wondering
> how other people find stuff?
>
> /dc
> --
> -------------------------------------------
> David "DC" Collier
> mailto:dc@pikkle.com
> +81 (0)80 6521 9559
> skype: callto://d3ntaku
> -------------------------------------------
> Pikkle ????
> http://www....
> -------------------------------------------
>
>

C:\Documents and Settings\flifson>irb
irb(main):001:0> PLATFORM
=> "i386-mswin32"
irb(main):002:0>

Farrel

Axel

11/16/2006 12:29:00 PM

0


> C:\Documents and Settings\flifson>irb
> irb(main):001:0> PLATFORM
> => "i386-mswin32"
> irb(main):002:0>

.... or from inside a Ruby script:

puts RUBY_PLATFORM


Where to find resources:


http://wiki.rubygarde...
http://www.ruby-la... (down just now?)


Documentation:
http://www.rub...docs/Progra...
http://www.rub...

Some code snippets:
http://pleac.sourceforge.net/pleac_ruby/...

Search for help
http://groups.google.com/group/comp.lang.ruby?hl=en&lr=&ie=UTF-8&...

Libraries:
http://raa.ruby...
http://ruby... (down just now?)

....


Book with a lot of "How Tos":
"The Ruby Way" by Hal Fulton


Have a nice day!

Axel

Luke A. Kanies

11/16/2006 8:32:00 PM

0

On Nov 16, 2006, at 3:17 AM, dc wrote:

> hi -
>
> is there a way to find which OS Ruby is running on?

Facter[1] does this and much more:

luke@midden(0) $ irb
irb(main):001:0> require 'facter'
=> true
irb(main):002:0> Facter.value(:operatingsystem)
=> "Darwin"
irb(main):003:0> Facter.macaddress
=> "00:0a:95:96:5f:64"
irb(main):004:0> Facter.to_hash.each do |p, v| next if p =~ /key/;
puts "%s => %s" % [p, v] end
kernel => Darwin
rubysitedir => /usr/lib/ruby/site_ruby/1.8
operatingsystemrelease => 8.8.0
hardwaremodel => Power Macintosh
ipaddress => 192.168.0.4
kernelrelease => 8.8.0
fqdn => midden.madstop.com
ps => ps -auxwww
domain => madstop.com
rubyversion => 1.8.2
puppetversion => 0.20.1
hostname => midden
facterversion => 1.3.3
operatingsystem => Darwin
macaddress => 00:0a:95:96:5f:64
home => /Users/luke

Note that Facter distinguishes the kernel from the operatingsystem;
you'll correctly get 'Debian' or 'Fedora' as your operating system,
for instance, not 'Linux'.

Also, FWIW, Facter is pretty darn easy to extend:

Facter.add(:myfact) do setcode { ...find your data } end

1 - http://reducti.../proje...

--
Luke Kanies
http://m... | http://reducti... | 615-594-8199



Ara.T.Howard

11/16/2006 8:43:00 PM

0

David Ashmore

11/16/2006 9:07:00 PM

0

Luke Kanies wrote:
> On Nov 16, 2006, at 3:17 AM, dc wrote:
>
>> hi -
>>
>> is there a way to find which OS Ruby is running on?
>
> Facter[1] does this and much more:
>
> luke@midden(0) $ irb
> irb(main):001:0> require 'facter'
> => true
> irb(main):002:0> Facter.value(:operatingsystem)
> => "Darwin"
> irb(main):003:0> Facter.macaddress
> => "00:0a:95:96:5f:64"
> irb(main):004:0> Facter.to_hash.each do |p, v| next if p =~ /key/;
> puts "%s => %s" % [p, v] end
> kernel => Darwin
> rubysitedir => /usr/lib/ruby/site_ruby/1.8
> operatingsystemrelease => 8.8.0
> hardwaremodel => Power Macintosh
> ipaddress => 192.168.0.4
> kernelrelease => 8.8.0
> fqdn => midden.madstop.com
> ps => ps -auxwww
> domain => madstop.com
> rubyversion => 1.8.2
> puppetversion => 0.20.1
> hostname => midden
> facterversion => 1.3.3
> operatingsystem => Darwin
> macaddress => 00:0a:95:96:5f:64
> home => /Users/luke
>
> Note that Facter distinguishes the kernel from the operatingsystem;
> you'll correctly get 'Debian' or 'Fedora' as your operating system,
> for instance, not 'Linux'.
>
> Also, FWIW, Facter is pretty darn easy to extend:
>
> Facter.add(:myfact) do setcode { ...find your data } end
>
> 1 - http://reducti.../proje...
>
> --Luke Kanies
> http://m... | http://reducti... | 615-594-8199
>
>
I use this:
myhome = ENV['HOME']
path = 'load path: '+$:.to_s
script = 'Script location = '+Dir.pwd+$0+' pid id '+$$.to_s
rubyinfo = 'OS = '+RUBY_PLATFORM+' and Ruby version = '+VERSION
puts 'Below is script location'
puts script
puts 'Below is rubyinfo'
puts rubyinfo
puts 'Below is load path'
puts path
puts ' My Shell enviroment = ' + ENV['SHELL']
puts ' My Home dir = ' + ENV['HOME']
puts ' My username = ' + ENV['USER']

--
Regards
Dave Ashmore
SOHO IT Solutions llc
1934 S. Delaware Dr.
Easton, PA 18042
610-258-7128
http://call...
Sometimes I can be reached via Skype as djash34
Disclaimer: The below quote is randomly generated and I may or
may not agree with the quote.
################################################################
HELP! MY TYPEWRITER IS BROKEN!
-- E. E. CUMMINGS
################################################################

Luke A. Kanies

11/16/2006 9:14:00 PM

0

On Nov 16, 2006, at 2:43 PM, ara.t.howard@noaa.gov wrote:

> On Fri, 17 Nov 2006, Luke Kanies wrote:
>> Facter[1] does this and much more:
>>
>> luke@midden(0) $ irb
>> irb(main):001:0> require 'facter'
>> => true
>> irb(main):002:0> Facter.value(:operatingsystem)
>> => "Darwin"
>> irb(main):003:0> Facter.macaddress
>> => "00:0a:95:96:5f:64"
>> irb(main):004:0> Facter.to_hash.each do |p, v| next if p =~ /key/;
>> puts "%s
> ^^^^^^^^^^^^^
> ^^^^^^^^^^^^^
>
> can you explain that? custom .to_s?

Facter is meant to be a collection of mechanisms for retrieving a
named piece of data; e.g., 'uname -s' is the most common way of
retrieving the operating system name, but it's useless on any Linux
distro so instead I look for /etc/redhat-release or use lsbrelease.
Thus, it's pretty easy to think of Facter as a big hash, but instead
of simple values it has one or more ways of retrieving each value.

So, I just implemented to_hash as a way of returning all known facts
and their values.

I'm skipping any fact that matches /key/ here because Facter knows
how to retrieve SSH keys, which are huge and would have polluted the
output. I had to pick between confusing people by skipping those
values, or confusing people by including them. :)

> seems like you should be able to do
>
> y Facter.table('key') # or :key
>
> for similar effect, or some such

What would be the intent of that? I think we're each missing
something here. Facter.to_hash just returns has hash of all of the
facts it knows about. Everything after that is normal, non-Facter
ruby. What would 'table' be used for?

> looks very cool btw - i didn't know about Facter.

I originally wrote it a few years ago as an inventorying mechanism --
there's a simple tool[1] that stores these facts into LDAP -- but now
Puppet uses it heavily. Every time a Puppet client connects to the
server, it collects all of its known facts and passes them to the
server as a hash. The server then sets these facts as variables in
the top-level scope. Thus, you can use $operatingsystem or
$ipaddress in your Puppet configurations and use this data to make
decisions in your configuratin.

1 - http://reducti.../proje...

--
Luke Kanies
http://m... | http://reducti... | 615-594-8199



Ara.T.Howard

11/16/2006 10:38:00 PM

0

Luke A. Kanies

11/16/2006 11:23:00 PM

0

On Nov 16, 2006, at 4:38 PM, ara.t.howard@noaa.gov wrote:

> On Fri, 17 Nov 2006, Luke Kanies wrote:
>>
>> I'm skipping any fact that matches /key/ here because Facter knows
>> how to retrieve SSH keys, which are huge and would have polluted
>> the output. I had to pick between confusing people by skipping
>> those values, or confusing people by including them. :)
>
> okay - it makes perfect sense then

Okay. *whew*

> well, i happen to be working on resource requests for ruby queue, eg
>
> rq queue submit --requirements="cpu > 3.0mhz and mem > 64gb" --
> job.rb

Yeah. There are currently very limited facts for cpu and memory
information, but they could be expanded pretty easily.

By the way, I've been using the term 'confine' to describe matching
these requirements; as in, 'confine this code to hosts that match
these requirements'. Facter uses this internally to confine a
resolution mechanism to specific platforms or organizations. E.g.,
here's how you set up one of the ways to retrieve the hostname on OS
X (darwin):

Facter.add("Hostname") do
confine :kernel => :darwin, :kernelrelease => "R7"
setcode do
%x{/usr/sbin/scutil --get LocalHostName}
end
end

You can confine resolutions based on any other fact values.

Puppet providers (the low-level code that handles things like
different package types or different user management tools) use a
similar mechanism. Mostly I confine providers based on available
binaries:

Puppet::Type.type(:package).provide(:dpkg) do
confine :exists => "/usr/bin/dpkg"
...
end

But you can also confine just like in Facter:

Puppet::Type.type(:package).provide(:darwinports) do
confine :operatingsystem => :darwin
...
end

So, not saying you have to adopt my terminology or something, but
I've been pretty happy with it.

--
Luke Kanies
http://m... | http://reducti... | 615-594-8199



Ara.T.Howard

11/16/2006 11:37:00 PM

0

Joel

3/13/2009 7:15:00 PM

0

I created two versions of the macro. the 1st the same as you had. Then 2nd
I removed some optional parmaeters that the macro recorder added. Not sure
if the 2nd method is going to worl because I may of taken out too many
options. Try both.


Sub ImportDataFromAccess()
'
' ImportDataFromAccess Macro
' Macro recorded 03/13/2009 by Memphis
'
DefaultFolder = "C:\temp"
ChDrive ("C:")
ChDir (DefaultFolder)

fileToOpen = Application.GetOpenFilename( _
FileFilter:="Access Files (*.mdb), *.mdb", _
Title:="OPen Database")
If fileToOpen = False Then
MsgBox ("Cannot Open file - Exiting Macro")
Exit Sub
End If

'

With Sheets("PropData").QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password="""";" & _
"UserID=Admin;" & _
"Data Source=" & fileToOpen & ";" & _
"Mode=Share DenyWrite;" & _
"Extended Properties="""";" & _
"Jet OLEDB:System database="""";" & _
"Jet OLEDB:Registry Path="""";" & _
"Jet OLEDB:Database Password="""";" & _
"Jet OLEDB:EngineType=5;" & _
"Jet OLEDB:Database Locking Mode=0;" & _
"Jet OLEDB:Global Partial BulkOps=2;" & _
"Jet OLEDB:Global Bulk Transactions=1;" & _
"Jet OLEDB:New Database Password="""";" & _
"Jet OLEDB:Create System Database=False;" & _
"Jet OLEDB:Encrypt Database=False;" & _
"Jet OLEDB:Don't Copy Locale on Compact=False;" & _
"Jet OLEDB:Compact Without Replica Repair=False;" & _
"Jet OLEDB:SFP=False"), _
Destination:=Range("A1"))

.CommandType = xlCmdTable
.CommandText = Array("8508Prepqry")
.Name = "0109CASES_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = fileToOpen
.Refresh BackgroundQuery:=False
End With
Sheets("Control").Select
End Sub

Sub ImportDataFromAccess2()
'
' ImportDataFromAccess Macro
' Macro recorded 03/13/2009 by Memphis
'
DefaultFolder = "C:\temp"
ChDrive ("C:")
ChDir (DefaultFolder)

fileToOpen = Application.GetOpenFilename( _
FileFilter:="Access Files (*.mdb), *.mdb", _
Title:="OPen Database")
If fileToOpen = False Then
MsgBox ("Cannot Open file - Exiting Macro")
Exit Sub
End If

'

With Sheets("PropData").QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password="""";" & _
"UserID=Admin;" & _
"Data Source=" & fileToOpen & ";"), _
Destination:=Range("A1"))

.CommandType = xlCmdTable
.CommandText = Array("8508Prepqry")
.Name = "0109CASES_1"
.FieldNames = True
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = fileToOpen
.Refresh BackgroundQuery:=False
End With
Sheets("Control").Select
End Sub





"Memphis" wrote:

> Thanks Joel, here it is:
> Sub ImportDataFromAccess()
> '
> ' ImportDataFromAccess Macro
> ' Macro recorded 03/13/2009 by Memphis
> '
>
> '
> Sheets("PropData").Select
> Range("A1").Select
> With ActiveSheet.QueryTables.Add(Connection:=Array( _
> "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User
> ID=Admin;Data Source=P:\Toolbar\Redet\0109CASES.mdb;Mode=Share Deny
> Write;Exte" _
> , _
> "nded Properties="""";Jet OLEDB:System database="""";Jet
> OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine
> Type=" _
> , _
> "5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk
> Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Datab" _
> , _
> "ase Password="""";Jet OLEDB:Create System Database=False;Jet
> OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=F" _
> , "alse;Jet OLEDB:Compact Without Replica Repair=False;Jet
> OLEDB:SFP=False"), _
> Destination:=Range("A1"))
> .CommandType = xlCmdTable
> .CommandText = Array("8508Prepqry")
> .Name = "0109CASES_1"
> .FieldNames = True
> .RowNumbers = False
> .FillAdjacentFormulas = False
> .PreserveFormatting = True
> .RefreshOnFileOpen = False
> .BackgroundQuery = True
> .RefreshStyle = xlInsertDeleteCells
> .SavePassword = False
> .SaveData = True
> .AdjustColumnWidth = True
> .RefreshPeriod = 0
> .PreserveColumnInfo = True
> .SourceDataFile = "P:\Toolbar\Redet\0109CASES.mdb"
> .Refresh BackgroundQuery:=False
> End With
> ActiveWindow.ScrollWorkbookTabs Sheets:=-1
> Sheets("Control").Select
> End Sub
>
> ___________________________________________________________________
> "Joel" wrote:
>
> > Turn on Macro recorder while performing the operation. Then post the code
> > and I will make the changes to select a file name.
> >
> > "Memphis" wrote:
> >
> > > Hello Everyone,
> > > I am currently importing data into an excel sheet from an Access query.
> > > I go to Data/ Import External Data/ Import data, and on the Select Data
> > > Source I find the Shared Drive (S:\) and then find the folder where the .mdb
> > > is found.
> > > Now every month the path is the same, only the name of the .mdb file changes
> > > its, basically I get a new batch of information for the new month.
> > > What I want to look into is the possibility of creating a Macros that promps
> > > the user for the file name they need to import the data from and have the
> > > system do the importing for them and drop the imported data beginning with
> > > Cell A1.
> > > The Command button for this operation is not in the actual sheet were the
> > > imported data is going, it is in a sheet I call ???Case Control???, the data
> > > needs to be propagated to the ???ImpData??? sheet.
> > >
> > > Thank you.
> > >