From: daz Date: 2004-07-10T22:02:29+09:00 Subject: Re: Ruby Snapshot Notifier Ryan Phillips wrote: > > On Sat, 10 Jul 2004 04:58:49 +0900, Randy Lawrence 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. :) File.utime isn't universally available (according to PickAxe I). That often means "Windows has no chance", but it works for me. daz #--------------------------------------------------------------- # -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