From: Randy Lawrence Date: 2004-07-11T00:08:49+09:00 Subject: Re: Ruby Snapshot Notifier 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. :) > > 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 > > > 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.