summaryrefslogtreecommitdiff
path: root/ruby_1_9_3/lib/rake/contrib
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-14 11:27:23 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-14 11:27:23 +0000
commitaa6e98139c8e1ea442fb2182341aaa08ff55b529 (patch)
treea509eb830418991995bfe3b840d4bf270ff7f0e2 /ruby_1_9_3/lib/rake/contrib
parent9e9d191cf367caa17776231a2d0fad0da47b160a (diff)
add tag v1_9_3_426
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_3_426@40733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_9_3/lib/rake/contrib')
-rw-r--r--ruby_1_9_3/lib/rake/contrib/compositepublisher.rb21
-rw-r--r--ruby_1_9_3/lib/rake/contrib/ftptools.rb150
-rw-r--r--ruby_1_9_3/lib/rake/contrib/publisher.rb73
-rw-r--r--ruby_1_9_3/lib/rake/contrib/rubyforgepublisher.rb16
-rw-r--r--ruby_1_9_3/lib/rake/contrib/sshpublisher.rb50
-rw-r--r--ruby_1_9_3/lib/rake/contrib/sys.rb191
6 files changed, 501 insertions, 0 deletions
diff --git a/ruby_1_9_3/lib/rake/contrib/compositepublisher.rb b/ruby_1_9_3/lib/rake/contrib/compositepublisher.rb
new file mode 100644
index 0000000000..69952a0808
--- /dev/null
+++ b/ruby_1_9_3/lib/rake/contrib/compositepublisher.rb
@@ -0,0 +1,21 @@
+module Rake
+
+ # Manage several publishers as a single entity.
+ class CompositePublisher
+ def initialize
+ @publishers = []
+ end
+
+ # Add a publisher to the composite.
+ def add(pub)
+ @publishers << pub
+ end
+
+ # Upload all the individual publishers.
+ def upload
+ @publishers.each { |p| p.upload }
+ end
+ end
+
+end
+
diff --git a/ruby_1_9_3/lib/rake/contrib/ftptools.rb b/ruby_1_9_3/lib/rake/contrib/ftptools.rb
new file mode 100644
index 0000000000..78420c7412
--- /dev/null
+++ b/ruby_1_9_3/lib/rake/contrib/ftptools.rb
@@ -0,0 +1,150 @@
+# = Tools for FTP uploading.
+#
+# This file is still under development and is not released for general
+# use.
+
+require 'date'
+require 'net/ftp'
+
+module Rake # :nodoc:
+
+ ####################################################################
+ # <b>Note:</b> <em> Not released for general use.</em>
+ class FtpFile
+ attr_reader :name, :size, :owner, :group, :time
+
+ def self.date
+ @date_class ||= Date
+ end
+
+ def self.time
+ @time_class ||= Time
+ end
+
+ def initialize(path, entry)
+ @path = path
+ @mode, _, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
+ @size = size.to_i
+ @time = determine_time(d1, d2, d3)
+ end
+
+ def path
+ File.join(@path, @name)
+ end
+
+ def directory?
+ @mode[0] == ?d
+ end
+
+ def mode
+ parse_mode(@mode)
+ end
+
+ def symlink?
+ @mode[0] == ?l
+ end
+
+ private # --------------------------------------------------------
+
+ def parse_mode(m)
+ result = 0
+ (1..9).each do |i|
+ result = 2*result + ((m[i]==?-) ? 0 : 1)
+ end
+ result
+ end
+
+ def determine_time(d1, d2, d3)
+ now = self.class.time.now
+ if /:/ =~ d3
+ result = Time.parse("#{d1} #{d2} #{now.year} #{d3}")
+ if result > now
+ result = Time.parse("#{d1} #{d2} #{now.year-1} #{d3}")
+ end
+ else
+ result = Time.parse("#{d1} #{d2} #{d3}")
+ end
+ result
+# elements = ParseDate.parsedate("#{d1} #{d2} #{d3}")
+# if elements[0].nil?
+# today = self.class.date.today
+# if elements[1] > today.month
+# elements[0] = today.year - 1
+# else
+# elements[0] = today.year
+# end
+# end
+# elements = elements.collect { |el| el.nil? ? 0 : el }
+# Time.mktime(*elements[0,7])
+ end
+ end
+
+ ####################################################################
+ # Manage the uploading of files to an FTP account.
+ class FtpUploader
+
+ # Log uploads to standard output when true.
+ attr_accessor :verbose
+
+ class << FtpUploader
+ # Create an uploader and pass it to the given block as +up+.
+ # When the block is complete, close the uploader.
+ def connect(path, host, account, password)
+ up = self.new(path, host, account, password)
+ begin
+ yield(up)
+ ensure
+ up.close
+ end
+ end
+ end
+
+ # Create an FTP uploader targeting the directory +path+ on +host+
+ # using the given account and password. +path+ will be the root
+ # path of the uploader.
+ def initialize(path, host, account, password)
+ @created = Hash.new
+ @path = path
+ @ftp = Net::FTP.new(host, account, password)
+ makedirs(@path)
+ @ftp.chdir(@path)
+ end
+
+ # Create the directory +path+ in the uploader root path.
+ def makedirs(path)
+ route = []
+ File.split(path).each do |dir|
+ route << dir
+ current_dir = File.join(route)
+ if @created[current_dir].nil?
+ @created[current_dir] = true
+ $stderr.puts "Creating Directory #{current_dir}" if @verbose
+ @ftp.mkdir(current_dir) rescue nil
+ end
+ end
+ end
+
+ # Upload all files matching +wildcard+ to the uploader's root
+ # path.
+ def upload_files(wildcard)
+ Dir[wildcard].each do |fn|
+ upload(fn)
+ end
+ end
+
+ # Close the uploader.
+ def close
+ @ftp.close
+ end
+
+ private # --------------------------------------------------------
+
+ # Upload a single file to the uploader's root path.
+ def upload(file)
+ $stderr.puts "Uploading #{file}" if @verbose
+ dir = File.dirname(file)
+ makedirs(dir)
+ @ftp.putbinaryfile(file, file) unless File.directory?(file)
+ end
+ end
+end
diff --git a/ruby_1_9_3/lib/rake/contrib/publisher.rb b/ruby_1_9_3/lib/rake/contrib/publisher.rb
new file mode 100644
index 0000000000..8b11edb59c
--- /dev/null
+++ b/ruby_1_9_3/lib/rake/contrib/publisher.rb
@@ -0,0 +1,73 @@
+# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
+# All rights reserved.
+
+# :stopdoc:
+
+# Configuration information about an upload host system.
+# name :: Name of host system.
+# webdir :: Base directory for the web information for the
+# application. The application name (APP) is appended to
+# this directory before using.
+# pkgdir :: Directory on the host system where packages can be
+# placed.
+HostInfo = Struct.new(:name, :webdir, :pkgdir)
+
+# :startdoc:
+
+# Manage several publishers as a single entity.
+class CompositePublisher
+ def initialize
+ @publishers = []
+ end
+
+ # Add a publisher to the composite.
+ def add(pub)
+ @publishers << pub
+ end
+
+ # Upload all the individual publishers.
+ def upload
+ @publishers.each { |p| p.upload }
+ end
+end
+
+# Publish an entire directory to an existing remote directory using
+# SSH.
+class SshDirPublisher
+ def initialize(host, remote_dir, local_dir)
+ @host = host
+ @remote_dir = remote_dir
+ @local_dir = local_dir
+ end
+
+ def upload
+ run %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
+ end
+end
+
+# Publish an entire directory to a fresh remote directory using SSH.
+class SshFreshDirPublisher < SshDirPublisher
+ def upload
+ run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
+ run %{ssh #{@host} mkdir #{@remote_dir}}
+ super
+ end
+end
+
+# Publish a list of files to an existing remote directory.
+class SshFilePublisher
+ # Create a publisher using the give host information.
+ def initialize(host, remote_dir, local_dir, *files)
+ @host = host
+ @remote_dir = remote_dir
+ @local_dir = local_dir
+ @files = files
+ end
+
+ # Upload the local directory to the remote directory.
+ def upload
+ @files.each do |fn|
+ run %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
+ end
+ end
+end
diff --git a/ruby_1_9_3/lib/rake/contrib/rubyforgepublisher.rb b/ruby_1_9_3/lib/rake/contrib/rubyforgepublisher.rb
new file mode 100644
index 0000000000..a4b96936c8
--- /dev/null
+++ b/ruby_1_9_3/lib/rake/contrib/rubyforgepublisher.rb
@@ -0,0 +1,16 @@
+require 'rake/contrib/sshpublisher'
+
+module Rake
+
+ class RubyForgePublisher < SshDirPublisher
+ attr_reader :project, :proj_id, :user
+
+ def initialize(projname, user)
+ super(
+ "#{user}@rubyforge.org",
+ "/var/www/gforge-projects/#{projname}",
+ "html")
+ end
+ end
+
+end
diff --git a/ruby_1_9_3/lib/rake/contrib/sshpublisher.rb b/ruby_1_9_3/lib/rake/contrib/sshpublisher.rb
new file mode 100644
index 0000000000..bd6adc127e
--- /dev/null
+++ b/ruby_1_9_3/lib/rake/contrib/sshpublisher.rb
@@ -0,0 +1,50 @@
+require 'rake/dsl_definition'
+require 'rake/contrib/compositepublisher'
+
+module Rake
+
+ # Publish an entire directory to an existing remote directory using
+ # SSH.
+ class SshDirPublisher
+ include Rake::DSL
+
+ def initialize(host, remote_dir, local_dir)
+ @host = host
+ @remote_dir = remote_dir
+ @local_dir = local_dir
+ end
+
+ def upload
+ sh %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
+ end
+ end
+
+ # Publish an entire directory to a fresh remote directory using SSH.
+ class SshFreshDirPublisher < SshDirPublisher
+ def upload
+ sh %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
+ sh %{ssh #{@host} mkdir #{@remote_dir}}
+ super
+ end
+ end
+
+ # Publish a list of files to an existing remote directory.
+ class SshFilePublisher
+ include Rake::DSL
+
+ # Create a publisher using the give host information.
+ def initialize(host, remote_dir, local_dir, *files)
+ @host = host
+ @remote_dir = remote_dir
+ @local_dir = local_dir
+ @files = files
+ end
+
+ # Upload the local directory to the remote directory.
+ def upload
+ @files.each do |fn|
+ sh %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
+ end
+ end
+ end
+end
diff --git a/ruby_1_9_3/lib/rake/contrib/sys.rb b/ruby_1_9_3/lib/rake/contrib/sys.rb
new file mode 100644
index 0000000000..41963f1fef
--- /dev/null
+++ b/ruby_1_9_3/lib/rake/contrib/sys.rb
@@ -0,0 +1,191 @@
+warn 'Sys has been deprecated in favor of FileUtils'
+
+#--
+# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
+# All rights reserved.
+#++
+#
+begin
+ require 'ftools'
+rescue LoadError
+end
+require 'rbconfig'
+
+######################################################################
+# Sys provides a number of file manipulation tools for the convenience
+# of writing Rakefiles. All commands in this module will announce
+# their activity on standard output if the $verbose flag is set
+# ($verbose = true is the default). You can control this by globally
+# setting $verbose or by using the +verbose+ and +quiet+ methods.
+#
+# Sys has been deprecated in favor of the FileUtils module available
+# in Ruby 1.8.
+#
+module Sys
+ RUBY = RbConfig::CONFIG['ruby_install_name']
+
+ # Install all the files matching +wildcard+ into the +dest_dir+
+ # directory. The permission mode is set to +mode+.
+ def install(wildcard, dest_dir, mode)
+ Dir[wildcard].each do |fn|
+ File.install(fn, dest_dir, mode, $verbose)
+ end
+ end
+
+ # Run the system command +cmd+.
+ def run(cmd)
+ log cmd
+ system(cmd) or fail "Command Failed: [#{cmd}]"
+ end
+
+ # Run a Ruby interpreter with the given arguments.
+ def ruby(*args)
+ run "#{RUBY} #{args.join(' ')}"
+ end
+
+ # Copy a single file from +file_name+ to +dest_file+.
+ def copy(file_name, dest_file)
+ log "Copying file #{file_name} to #{dest_file}"
+ File.copy(file_name, dest_file)
+ end
+
+ # Copy all files matching +wildcard+ into the directory +dest_dir+.
+ def copy_files(wildcard, dest_dir)
+ for_matching_files(wildcard, dest_dir) { |from, to| copy(from, to) }
+ end
+
+ # Link +file_name+ to +dest_file+.
+ def link(file_name, dest_file)
+ log "Linking file #{file_name} to #{dest_file}"
+ File.link(file_name, dest_file)
+ end
+
+ # Link all files matching +wildcard+ into the directory +dest_dir+.
+ def link_files(wildcard, dest_dir)
+ for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
+ end
+
+ # Symlink +file_name+ to +dest_file+.
+ def symlink(file_name, dest_file)
+ log "Symlinking file #{file_name} to #{dest_file}"
+ File.symlink(file_name, dest_file)
+ end
+
+ # Symlink all files matching +wildcard+ into the directory +dest_dir+.
+ def symlink_files(wildcard, dest_dir)
+ for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
+ end
+
+ # Remove all files matching +wildcard+. If a matching file is a
+ # directory, it must be empty to be removed. used +delete_all+ to
+ # recursively delete directories.
+ def delete(*wildcards)
+ wildcards.each do |wildcard|
+ Dir[wildcard].each do |fn|
+ if File.directory?(fn)
+ log "Deleting directory #{fn}"
+ Dir.delete(fn)
+ else
+ log "Deleting file #{fn}"
+ File.delete(fn)
+ end
+ end
+ end
+ end
+
+ # Recursively delete all files and directories matching +wildcard+.
+ def delete_all(*wildcards)
+ wildcards.each do |wildcard|
+ Dir[wildcard].each do |fn|
+ next if ! File.exist?(fn)
+ if File.directory?(fn)
+ Dir["#{fn}/*"].each do |subfn|
+ next if subfn=='.' || subfn=='..'
+ delete_all(subfn)
+ end
+ log "Deleting directory #{fn}"
+ Dir.delete(fn)
+ else
+ log "Deleting file #{fn}"
+ File.delete(fn)
+ end
+ end
+ end
+ end
+
+ # Make the directories given in +dirs+.
+ def makedirs(*dirs)
+ dirs.each do |fn|
+ log "Making directory #{fn}"
+ File.makedirs(fn)
+ end
+ end
+
+ # Make +dir+ the current working directory for the duration of
+ # executing the given block.
+ def indir(dir)
+ olddir = Dir.pwd
+ Dir.chdir(dir)
+ yield
+ ensure
+ Dir.chdir(olddir)
+ end
+
+ # Split a file path into individual directory names.
+ #
+ # For example:
+ # split_all("a/b/c") => ['a', 'b', 'c']
+ def split_all(path)
+ head, tail = File.split(path)
+ return [tail] if head == '.' || tail == '/'
+ return [head, tail] if head == '/'
+ return split_all(head) + [tail]
+ end
+
+ # Write a message to standard error if $verbose is enabled.
+ def log(msg)
+ print " " if $trace && $verbose
+ $stderr.puts msg if $verbose
+ end
+
+ # Perform a block with $verbose disabled.
+ def quiet(&block)
+ with_verbose(false, &block)
+ end
+
+ # Perform a block with $verbose enabled.
+ def verbose(&block)
+ with_verbose(true, &block)
+ end
+
+ # Perform a block with each file matching a set of wildcards.
+ def for_files(*wildcards)
+ wildcards.each do |wildcard|
+ Dir[wildcard].each do |fn|
+ yield(fn)
+ end
+ end
+ end
+
+ extend(self)
+
+ private # ----------------------------------------------------------
+
+ def for_matching_files(wildcard, dest_dir)
+ Dir[wildcard].each do |fn|
+ dest_file = File.join(dest_dir, fn)
+ parent = File.dirname(dest_file)
+ makedirs(parent) if ! File.directory?(parent)
+ yield(fn, dest_file)
+ end
+ end
+
+ def with_verbose(v)
+ oldverbose = $verbose
+ $verbose = v
+ yield
+ ensure
+ $verbose = oldverbose
+ end
+
+end