From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/lib/rake/contrib/.document | 1 + jni/ruby/lib/rake/contrib/compositepublisher.rb | 21 ++++ jni/ruby/lib/rake/contrib/ftptools.rb | 137 ++++++++++++++++++++++++ jni/ruby/lib/rake/contrib/publisher.rb | 81 ++++++++++++++ jni/ruby/lib/rake/contrib/rubyforgepublisher.rb | 18 ++++ jni/ruby/lib/rake/contrib/sshpublisher.rb | 61 +++++++++++ jni/ruby/lib/rake/contrib/sys.rb | 4 + 7 files changed, 323 insertions(+) create mode 100644 jni/ruby/lib/rake/contrib/.document create mode 100644 jni/ruby/lib/rake/contrib/compositepublisher.rb create mode 100644 jni/ruby/lib/rake/contrib/ftptools.rb create mode 100644 jni/ruby/lib/rake/contrib/publisher.rb create mode 100644 jni/ruby/lib/rake/contrib/rubyforgepublisher.rb create mode 100644 jni/ruby/lib/rake/contrib/sshpublisher.rb create mode 100644 jni/ruby/lib/rake/contrib/sys.rb (limited to 'jni/ruby/lib/rake/contrib') diff --git a/jni/ruby/lib/rake/contrib/.document b/jni/ruby/lib/rake/contrib/.document new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/jni/ruby/lib/rake/contrib/.document @@ -0,0 +1 @@ + diff --git a/jni/ruby/lib/rake/contrib/compositepublisher.rb b/jni/ruby/lib/rake/contrib/compositepublisher.rb new file mode 100644 index 0000000..69952a0 --- /dev/null +++ b/jni/ruby/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/jni/ruby/lib/rake/contrib/ftptools.rb b/jni/ruby/lib/rake/contrib/ftptools.rb new file mode 100644 index 0000000..b178523 --- /dev/null +++ b/jni/ruby/lib/rake/contrib/ftptools.rb @@ -0,0 +1,137 @@ +# = Tools for FTP uploading. +# +# This file is still under development and is not released for general +# use. + +require 'date' +require 'net/ftp' +require 'rake/file_list' + +module Rake # :nodoc: + + class FtpFile # :nodoc: all + 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} #{d3}") + else + result = Time.parse("#{d1} #{d2} #{now.year} #{d3}") + result = Time.parse("#{d1} #{d2} #{now.year - 1} #{d3}") if + result > now + end + result + end + end + + ## + # Manage the uploading of files to an FTP account. + class FtpUploader # :nodoc: + + # 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) + FileList.glob(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/jni/ruby/lib/rake/contrib/publisher.rb b/jni/ruby/lib/rake/contrib/publisher.rb new file mode 100644 index 0000000..f4ee1ab --- /dev/null +++ b/jni/ruby/lib/rake/contrib/publisher.rb @@ -0,0 +1,81 @@ +# 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: + +# TODO: Move to contrib/sshpublisher +#-- +# Manage several publishers as a single entity. +class CompositePublisher # :nodoc: + 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 + +# TODO: Remove in Rake 11, duplicated +#-- +# Publish an entire directory to an existing remote directory using +# SSH. +class SshDirPublisher # :nodoc: all + 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 + +# TODO: Remove in Rake 11, duplicated +#-- +# Publish an entire directory to a fresh remote directory using SSH. +class SshFreshDirPublisher < SshDirPublisher # :nodoc: all + def upload + run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil + run %{ssh #{@host} mkdir #{@remote_dir}} + super + end +end + +# TODO: Remove in Rake 11, duplicated +#-- +# Publish a list of files to an existing remote directory. +class SshFilePublisher # :nodoc: all + # 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/jni/ruby/lib/rake/contrib/rubyforgepublisher.rb b/jni/ruby/lib/rake/contrib/rubyforgepublisher.rb new file mode 100644 index 0000000..00889ad --- /dev/null +++ b/jni/ruby/lib/rake/contrib/rubyforgepublisher.rb @@ -0,0 +1,18 @@ +# TODO: Remove in Rake 11 + +require 'rake/contrib/sshpublisher' + +module Rake + + class RubyForgePublisher < SshDirPublisher # :nodoc: all + 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/jni/ruby/lib/rake/contrib/sshpublisher.rb b/jni/ruby/lib/rake/contrib/sshpublisher.rb new file mode 100644 index 0000000..64f5770 --- /dev/null +++ b/jni/ruby/lib/rake/contrib/sshpublisher.rb @@ -0,0 +1,61 @@ +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 + + # Creates an SSH publisher which will scp all files in +local_dir+ to + # +remote_dir+ on +host+ + + def initialize(host, remote_dir, local_dir) + @host = host + @remote_dir = remote_dir + @local_dir = local_dir + end + + # Uploads the files + + 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 + + # Uploads the files after removing the existing remote directory. + + 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 + + # Creates an SSH publisher which will scp all +files+ in +local_dir+ to + # +remote_dir+ on +host+. + + def initialize(host, remote_dir, local_dir, *files) + @host = host + @remote_dir = remote_dir + @local_dir = local_dir + @files = files + end + + # Uploads the files + + def upload + @files.each do |fn| + sh "scp", "-q", "#{@local_dir}/#{fn}", "#{@host}:#{@remote_dir}" + end + end + end +end diff --git a/jni/ruby/lib/rake/contrib/sys.rb b/jni/ruby/lib/rake/contrib/sys.rb new file mode 100644 index 0000000..8d4c735 --- /dev/null +++ b/jni/ruby/lib/rake/contrib/sys.rb @@ -0,0 +1,4 @@ +# TODO: Remove in Rake 11 + +fail "ERROR: 'rake/contrib/sys' is obsolete and no longer supported. " + + "Use 'FileUtils' instead." -- cgit v1.2.3