Ruby Snapshot Notifier

Has anyone already implemented a ruby script to check if a new ruby snapshot is available? Would be neat if it could do this without downloading the snapshot.

It seems the Ruby 1.8.1 snapshot is updated fairly frequently and the download page doesn't indicate the date/time stamp (so we periodically download, untar, ungzip and examine the timestamps manually).

You could write a script that FTP's to the server and uses the list
command to get the filestamp of the file and compare it to a filestamp
locally.

-ryan

···

On Sat, 10 Jul 2004 04:58:49 +0900, Randy Lawrence <jm@zzzzzzzzzzzz.com> wrote:

Has anyone already implemented a ruby script to check if a new ruby
snapshot is available? Would be neat if it could do this without
downloading the snapshot.

It seems the Ruby 1.8.1 snapshot is updated fairly frequently and the
download page doesn't indicate the date/time stamp (so we periodically
download, untar, ungzip and examine the timestamps manually).

Ryan Phillips wrote:

You could write a script that FTP's to the server and uses the list
command to get the filestamp of the file and compare it to a filestamp
locally.

-ryan

Has anyone already implemented a ruby script to check if a new ruby
snapshot is available? Would be neat if it could do this without
downloading the snapshot.

It seems the Ruby 1.8.1 snapshot is updated fairly frequently and the
download page doesn't indicate the date/time stamp (so we periodically
download, untar, ungzip and examine the timestamps manually).

Yea, we just poked a hole in our firewall to allow ftp now. We were downloading to our public server, and then downloading to our lan. Now we can just connect directly. :slight_smile:

···

On Sat, 10 Jul 2004 04:58:49 +0900, Randy Lawrence <jm@zzzzzzzzzzzz.com> wrote:

Ryan Phillips wrote:

> Has anyone already implemented a ruby script to check if a new ruby
> snapshot is available? Would be neat if it could do this without
> downloading the snapshot.
>
> It seems the Ruby 1.8.1 snapshot is updated fairly frequently and the
> download page doesn't indicate the date/time stamp (so we periodically
> download, untar, ungzip and examine the timestamps manually).

You could write a script that FTP's to the server and uses the list
command to get the filestamp of the file and compare it to a filestamp
locally.

If it would save some of Matz' valuable bandwith, it's worth doing.
All you need to do is run this, then find out why it didn't do
what I expected on your machine. :slight_smile:

File.utime isn't universally available (according to PickAxe I).
That often means "Windows has no chance", but it works for me.

daz

···

On Sat, 10 Jul 2004 04:58:49 +0900, Randy Lawrence wrote:

#---------------------------------------------------------------
# <ftp_snap.rb> -DfB- 2004/07/10
# Download stable-snapshot only if updated

ftp_site = 'ftp.iij.ad.jp' # ftp.ruby-lang.org mirror
fn_snap = 'stable-snapshot.tar.gz' # 1.8.x

################################################
# Download to site-ruby/stable-snapshot.tar.gz #
################################################
require 'rbconfig'
fn_snap_save = File.join(Config::CONFIG['sitedir'], fn_snap)
# fn_snap_save = 'some.other'

#---------------------------------------------------------------
$stdout.sync = true

# [Y,M,D,h,m] to Time
def pdt_to_time(pdt, now = Time.now)
  unless pdt[1,4].compact.size==4
    raise "#{pdt[1,4].inspect} ... expected [M, D, h, m]"
  end
  pdt[0] ||= now.year # assume year
  pdt[0] -= 1 if pdt[1] > now.month # last year ?
  Time.utc(*pdt[0,5])
end

require 'ParseDate'
require 'net/ftp'

ftp = Net::FTP.open(ftp_site)
END { ftp.close unless ftp.closed? }
ftp.login
##
ftp.chdir('/pub/lang/ruby')
fline = ftp.list(fn_snap)
if fline.empty?
  ftp.chdir('/pub/ruby')
  fline = ftp.list(fn_snap)
end
unless fline.size==1
  puts '+++', fline, '+++'
  raise "Multiple, or no files match \"#{fn_snap}\""
end
# <---- Jan..Dec ---->
fline[0] =~ /(\s[AFJMNOS][aceopu][b-y]\s.*)#{Regexp.quote(fn_snap)}\Z/
ft = pdt_to_time(ParseDate::parsedate($1))
ft_prev = File.exist?(fn_snap_save) ? File.mtime(fn_snap_save).utc : 0
if ft > ft_prev
  if ft_prev > 0
    puts "Replacing: #{ft_prev}"
  else
    puts "No previous snapshot found (first run)"
  end
  puts "Getting latest (#{ft}) ..."
  ftp.getbinaryfile(fn_snap, fn_snap_save, 1024)
  File.utime(ft, ft, fn_snap_save)
else
  puts "Existing snapshot is current"
end

daz wrote:

[snip]

If it would save some of Matz' valuable bandwith, it's worth doing.
All you need to do is run this, then find out why it didn't do
what I expected on your machine. :slight_smile:

File.utime isn't universally available (according to PickAxe I).
That often means "Windows has no chance", but it works for me.

daz

#---------------------------------------------------------------
# <ftp_snap.rb> -DfB- 2004/07/10
# Download stable-snapshot only if updated

ftp_site = 'ftp.iij.ad.jp' # ftp.ruby-lang.org mirror
fn_snap = 'stable-snapshot.tar.gz' # 1.8.x

################################################
# Download to site-ruby/stable-snapshot.tar.gz #
################################################
require 'rbconfig'
fn_snap_save = File.join(Config::CONFIG['sitedir'], fn_snap)
# fn_snap_save = 'some.other'

#---------------------------------------------------------------
$stdout.sync = true

# [Y,M,D,h,m] to Time
def pdt_to_time(pdt, now = Time.now)
  unless pdt[1,4].compact.size==4
    raise "#{pdt[1,4].inspect} ... expected [M, D, h, m]"
  end
  pdt[0] ||= now.year # assume year
  pdt[0] -= 1 if pdt[1] > now.month # last year ?
  Time.utc(*pdt[0,5])
end

require 'ParseDate'
require 'net/ftp'

ftp = Net::FTP.open(ftp_site)
END { ftp.close unless ftp.closed? }
ftp.login
##
ftp.chdir('/pub/lang/ruby')
fline = ftp.list(fn_snap)
if fline.empty?
  ftp.chdir('/pub/ruby')
  fline = ftp.list(fn_snap)
end
unless fline.size==1
  puts '+++', fline, '+++'
  raise "Multiple, or no files match \"#{fn_snap}\""
end
# <---- Jan..Dec ---->
fline[0] =~ /(\s[AFJMNOS][aceopu][b-y]\s.*)#{Regexp.quote(fn_snap)}\Z/
ft = pdt_to_time(ParseDate::parsedate($1))
ft_prev = File.exist?(fn_snap_save) ? File.mtime(fn_snap_save).utc : 0
if ft > ft_prev
  if ft_prev > 0
    puts "Replacing: #{ft_prev}"
  else
    puts "No previous snapshot found (first run)"
  end
  puts "Getting latest (#{ft}) ..."
  ftp.getbinaryfile(fn_snap, fn_snap_save, 1024)
  File.utime(ft, ft, fn_snap_save)
else
  puts "Existing snapshot is current"
end

You are much to kind. Thank you very much!

Aside from the functionality, it is good for ruby beginners like me to see other people's ruby coding style.

Daz,

"daz" <dooby@d10.karoo.co.uk> wrote in message

<snip>

if ft > ft_prev

      ^^^^^^^^^
This condition gives me an error (ruby 1.8.2-rc14) but it can
easily be fixed like so:

    if ft.to_i > ft_prev.to_i

  if ft_prev > 0
    puts "Replacing: #{ft_prev}"
  else
    puts "No previous snapshot found (first run)"
  end
  puts "Getting latest (#{ft}) ..."
  ftp.getbinaryfile(fn_snap, fn_snap_save, 1024)
  File.utime(ft, ft, fn_snap_save)
else
  puts "Existing snapshot is current"
end

Thanks,
-- shanko

Hi,

At Sat, 10 Jul 2004 22:02:29 +0900,
daz wrote in [ruby-talk:105895]:

require 'ParseDate'

  $ ruby -rParseDate -ep
  ruby: No such file to load -- ParseDate (LoadError)

No such library is bundled.

···

--
Nobu Nakada

Randy Lawrence wrote:

[...] Thank you very much!

Quite a pleasure. Valuable question.
I couldn't concentrate on what I was supposed to be doing :slight_smile:

Aside from the functionality, it is good for ruby beginners like me to
see other people's ruby coding style.

Normally, yes; but not from my example.
I looked at it and saw I'd written it in Perl.

I'll do coding style another day, perhaps :wink:

cheers,

daz

Shashank Date wrote:

"daz" wrote

<snip>

> if ft > ft_prev
      ^^^^^^^^^
This condition gives me an error (ruby 1.8.2-rc14) ...

Hi Shanko,

Oh, true. The line immediately below that should be modified
in the same way, I guess.

I must have run with:
       ruby 1.8.0 (2003-05-15) [i386-mswin32]

Most later versions of Ruby require to_i before comparison of
Time and Fixnum objects.

... but it can easily be fixed like so:

> if ft > ft_prev ## original
      ^^^^^^^^^
  if ft.to_i > ft_prev.to_i <----------* new

> if ft_prev > 0 ## original
     ^^^^^^^^^

      if ft_prev.to_i > 0 <----------* new

> puts "Replacing: #{ft_prev}"
> else
> puts "No previous snapshot found (first run)"
> end

Thanks for the 'patch'.

I said that it looked like Perl ...
.... I think it looks more like a Makefile :-#

ruby ftp_snap.rb # doesn't look as bad, tho'.

-- shanko

daz

<nobu.nokada@softhome.net> wrote in message news:200407120125.i6C1PXGg010327@sharui.nakada.niregi.kanuma.tochigi.jp...

Hi,

At Sat, 10 Jul 2004 22:02:29 +0900,
daz wrote in [ruby-talk:105895]:
> require 'ParseDate'

  $ ruby -rParseDate -ep
  ruby: No such file to load -- ParseDate (LoadError)

No such library is bundled.

--
Nobu Nakada

Thanks Nobu, is this OK ? (of course :wink:

$ ruby -rparsedate -ep

(Windows doesn't care too much about case, but I should.)

daz

# parsedate.rb: Written by Tadayoshi Funaba 2001, 2002
# $Id: parsedate.rb,v 2.6 2002-05-14 07:43:18+09 tadf Exp $

require 'date/format'

module ParseDate

  def parsedate(str, comp=false)
    Date._parse(str, comp).
      values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)
  end

  module_function :parsedate

end