~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/rake/contrib/ftptools.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# = Tools for FTP uploading.
 
2
#
 
3
# This file is still under development and is not released for general
 
4
# use.
 
5
 
 
6
require 'date'
 
7
require 'net/ftp'
 
8
 
 
9
module Rake # :nodoc:
 
10
 
 
11
  ####################################################################
 
12
  # <b>Note:</b> <em> Not released for general use.</em>
 
13
  class FtpFile
 
14
    attr_reader :name, :size, :owner, :group, :time
 
15
 
 
16
    def self.date
 
17
      @date_class ||= Date
 
18
    end
 
19
 
 
20
    def self.time
 
21
      @time_class ||= Time
 
22
    end
 
23
 
 
24
    def initialize(path, entry)
 
25
      @path = path
 
26
      @mode, line, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
 
27
      @size = size.to_i
 
28
      @time = determine_time(d1, d2, d3)
 
29
    end
 
30
 
 
31
    def path
 
32
      File.join(@path, @name)
 
33
    end
 
34
 
 
35
    def directory?
 
36
      @mode[0] == ?d
 
37
    end
 
38
 
 
39
    def mode
 
40
      parse_mode(@mode)
 
41
    end
 
42
 
 
43
    def symlink?
 
44
      @mode[0] == ?l
 
45
    end
 
46
 
 
47
    private # --------------------------------------------------------
 
48
 
 
49
    def parse_mode(m)
 
50
      result = 0
 
51
      (1..9).each do |i|
 
52
        result = 2*result + ((m[i]==?-) ? 0 : 1)
 
53
      end
 
54
      result
 
55
    end
 
56
 
 
57
    def determine_time(d1, d2, d3)
 
58
      now = self.class.time.now
 
59
      if /:/ =~ d3
 
60
        h, m = d3.split(':')
 
61
        result = Time.parse("#{d1} #{d2} #{now.year} #{d3}")
 
62
        if result > now
 
63
          result = Time.parse("#{d1} #{d2} #{now.year-1} #{d3}")
 
64
        end
 
65
      else
 
66
        result = Time.parse("#{d1} #{d2} #{d3}")
 
67
      end
 
68
      result
 
69
#       elements = ParseDate.parsedate("#{d1} #{d2} #{d3}")
 
70
#       if elements[0].nil?
 
71
#         today = self.class.date.today
 
72
#         if elements[1] > today.month
 
73
#           elements[0] = today.year - 1
 
74
#         else
 
75
#           elements[0] = today.year
 
76
#         end
 
77
#       end
 
78
#       elements = elements.collect { |el| el.nil? ? 0 : el }
 
79
#       Time.mktime(*elements[0,7])
 
80
    end
 
81
  end
 
82
 
 
83
  ####################################################################
 
84
  # Manage the uploading of files to an FTP account.
 
85
  class FtpUploader
 
86
 
 
87
    # Log uploads to standard output when true.
 
88
    attr_accessor :verbose
 
89
 
 
90
    class << FtpUploader
 
91
      # Create an uploader and pass it to the given block as +up+.
 
92
      # When the block is complete, close the uploader.
 
93
      def connect(path, host, account, password)
 
94
        up = self.new(path, host, account, password)
 
95
        begin
 
96
          yield(up)
 
97
        ensure
 
98
          up.close
 
99
        end
 
100
      end
 
101
    end
 
102
 
 
103
    # Create an FTP uploader targetting the directory +path+ on +host+
 
104
    # using the given account and password.  +path+ will be the root
 
105
    # path of the uploader.
 
106
    def initialize(path, host, account, password)
 
107
      @created = Hash.new
 
108
      @path = path
 
109
      @ftp = Net::FTP.new(host, account, password)
 
110
      makedirs(@path)
 
111
      @ftp.chdir(@path)
 
112
    end
 
113
 
 
114
    # Create the directory +path+ in the uploader root path.
 
115
    def makedirs(path)
 
116
      route = []
 
117
      File.split(path).each do |dir|
 
118
        route << dir
 
119
        current_dir = File.join(route)
 
120
        if @created[current_dir].nil?
 
121
          @created[current_dir] = true
 
122
          puts "Creating Directory  #{current_dir}" if @verbose
 
123
          @ftp.mkdir(current_dir) rescue nil
 
124
        end
 
125
      end
 
126
    end
 
127
 
 
128
    # Upload all files matching +wildcard+ to the uploader's root
 
129
    # path.
 
130
    def upload_files(wildcard)
 
131
      Dir[wildcard].each do |fn|
 
132
        upload(fn)
 
133
      end
 
134
    end
 
135
 
 
136
    # Close the uploader.
 
137
    def close
 
138
      @ftp.close
 
139
    end
 
140
 
 
141
    private # --------------------------------------------------------
 
142
 
 
143
    # Upload a single file to the uploader's root path.
 
144
    def upload(file)
 
145
      puts "Uploading #{file}" if @verbose
 
146
      dir = File.dirname(file)
 
147
      makedirs(dir)
 
148
      @ftp.putbinaryfile(file, file) unless File.directory?(file)
 
149
    end
 
150
  end
 
151
end