reap 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ # Rakefile for xoxo-rb. -*-ruby-*-
2
+ require 'rake/rdoctask'
3
+ require 'rake/testtask'
4
+
5
+
6
+ desc "Run all the tests"
7
+ task :default => [:test]
8
+
9
+ desc "Do predistribution stuff"
10
+ task :predist => [:chmod, :changelog, :doc]
11
+
12
+
13
+ desc "Run all the tests"
14
+ Rake::TestTask.new do |t|
15
+ t.libs << "test"
16
+ t.test_files = FileList['test_*.rb']
17
+ t.verbose = true
18
+ end
19
+
20
+ desc "Make an archive as .tar.gz"
21
+ task :dist => :test do
22
+ system "export DARCS_REPO=#{File.expand_path "."}; " +
23
+ "darcs dist -d xoxo-rb#{get_darcs_tree_version}"
24
+ end
25
+
26
+ desc "Make binaries executable"
27
+ task :chmod do
28
+ Dir["bin/*"].each { |binary| File.chmod(0775, binary) }
29
+ end
30
+
31
+ desc "Generate a ChangeLog"
32
+ task :changelog do
33
+ system "darcs changes --repo=#{ENV["DARCS_REPO"] || "."} >ChangeLog"
34
+ end
35
+
36
+ desc "Generate RDoc documentation"
37
+ Rake::RDocTask.new(:doc) do |rdoc|
38
+ rdoc.options << '--line-numbers --inline-source'
39
+ rdoc.rdoc_dir = "rdoc"
40
+ rdoc.rdoc_files.include 'README'
41
+ rdoc.rdoc_files.include 'xoxo.rb'
42
+ end
43
+
44
+
45
+ # Helper to retrieve the "revision number" of the darcs tree.
46
+ def get_darcs_tree_version
47
+ return "" unless File.directory? "_darcs"
48
+
49
+ changes = `darcs changes`
50
+ count = 0
51
+ tag = "0.0"
52
+
53
+ changes.each("\n\n") { |change|
54
+ head, title, desc = change.split("\n", 3)
55
+
56
+ if title =~ /^ \*/
57
+ # Normal change.
58
+ count += 1
59
+ elsif title =~ /tagged (.*)/
60
+ # Tag. We look for these.
61
+ tag = $1
62
+ break
63
+ else
64
+ warn "Unparsable change: #{change}"
65
+ end
66
+ }
67
+
68
+ "-" + tag + "." + count.to_s
69
+ end
@@ -0,0 +1,60 @@
1
+ # Rakefile for rubypants -*-ruby-*-
2
+ require 'rake/rdoctask'
3
+
4
+
5
+ desc "Run all the tests"
6
+ task :default => [:test]
7
+
8
+ desc "Do predistribution stuff"
9
+ task :predist => [:changelog, :doc]
10
+
11
+
12
+ desc "Run all the tests"
13
+ task :test do
14
+ ruby 'rand.rb'
15
+ end
16
+
17
+ desc "Make an archive as .tar.gz"
18
+ task :dist => :test do
19
+ system "export DARCS_REPO=#{File.expand_path "."}; " +
20
+ "darcs dist -d rand#{get_darcs_tree_version}"
21
+ end
22
+
23
+ desc "Generate a ChangeLog"
24
+ task :changelog do
25
+ system "darcs changes --repo=#{ENV["DARCS_REPO"] || "."} >ChangeLog"
26
+ end
27
+
28
+ desc "Generate RDoc documentation"
29
+ Rake::RDocTask.new(:doc) do |rdoc|
30
+ rdoc.options << '--line-numbers --inline-source --all'
31
+ rdoc.rdoc_files.include 'README'
32
+ rdoc.rdoc_files.include 'rand.rb'
33
+ end
34
+
35
+
36
+ # Helper to retrieve the "revision number" of the darcs tree.
37
+ def get_darcs_tree_version
38
+ return "" unless File.directory? "_darcs"
39
+
40
+ changes = `darcs changes`
41
+ count = 0
42
+ tag = "0.0"
43
+
44
+ changes.each("\n\n") { |change|
45
+ head, title, desc = change.split("\n", 3)
46
+
47
+ if title =~ /^ \*/
48
+ # Normal change.
49
+ count += 1
50
+ elsif title =~ /tagged (.*)/
51
+ # Tag. We look for these.
52
+ tag = $1
53
+ break
54
+ else
55
+ warn "Unparsable change: #{change}"
56
+ end
57
+ }
58
+
59
+ "-" + tag + "." + count.to_s
60
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Rake
4
+
5
+ # Manage several publishers as a single entity.
6
+ class CompositePublisher
7
+ def initialize
8
+ @publishers = []
9
+ end
10
+
11
+ # Add a publisher to the composite.
12
+ def add(pub)
13
+ @publishers << pub
14
+ end
15
+
16
+ # Upload all the individual publishers.
17
+ def upload
18
+ @publishers.each { |p| p.upload }
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # = Tools for FTP uploading.
4
+ #
5
+ # This file is still under development and is not released for general
6
+ # use.
7
+
8
+ require 'date'
9
+ require 'parsedate'
10
+ require 'net/ftp'
11
+
12
+ module Rake # :nodoc:
13
+
14
+ ####################################################################
15
+ # <b>Note:</b> <em> Not released for general use.</em>
16
+ class FtpFile
17
+ attr_reader :name, :size, :owner, :group, :time
18
+
19
+ def self.date
20
+ @date_class ||= Date
21
+ end
22
+
23
+ def initialize(path, entry)
24
+ @path = path
25
+ @mode, line, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
26
+ @size = size.to_i
27
+ @time = determine_time(d1, d2, d3)
28
+ end
29
+
30
+ def path
31
+ File.join(@path, @name)
32
+ end
33
+
34
+ def directory?
35
+ @mode[0] == ?d
36
+ end
37
+
38
+ def mode
39
+ parse_mode(@mode)
40
+ end
41
+
42
+ def symlink?
43
+ @mode[0] == ?l
44
+ end
45
+
46
+ private # --------------------------------------------------------
47
+
48
+ def parse_mode(m)
49
+ result = 0
50
+ (1..9).each do |i|
51
+ result = 2*result + ((m[i]==?-) ? 0 : 1)
52
+ end
53
+ result
54
+ end
55
+
56
+ def determine_time(d1, d2, d3)
57
+ elements = ParseDate.parsedate("#{d1} #{d2} #{d3}")
58
+ if elements[0].nil?
59
+ today = self.class.date.today
60
+ if elements[1] > today.month
61
+ elements[0] = today.year - 1
62
+ else
63
+ elements[0] = today.year
64
+ end
65
+ end
66
+ elements = elements.collect { |el| el.nil? ? 0 : el }
67
+ Time.mktime(*elements[0,7])
68
+ end
69
+ end
70
+
71
+ ####################################################################
72
+ # Manage the uploading of files to an FTP account.
73
+ class FtpUploader
74
+
75
+ # Log uploads to standard output when true.
76
+ attr_accessor :verbose
77
+
78
+ class << FtpUploader
79
+ # Create an uploader and pass it to the given block as +up+.
80
+ # When the block is complete, close the uploader.
81
+ def connect(path, host, account, password)
82
+ up = self.new(path, host, account, password)
83
+ begin
84
+ yield(up)
85
+ ensure
86
+ up.close
87
+ end
88
+ end
89
+ end
90
+
91
+ # Create an FTP uploader targetting the directory +path+ on +host+
92
+ # using the given account and password. +path+ will be the root
93
+ # path of the uploader.
94
+ def initialize(path, host, account, password)
95
+ @created = Hash.new
96
+ @path = path
97
+ @ftp = Net::FTP.new(host, account, password)
98
+ makedirs(@path)
99
+ @ftp.chdir(@path)
100
+ end
101
+
102
+ # Create the directory +path+ in the uploader root path.
103
+ def makedirs(path)
104
+ route = []
105
+ File.split(path).each do |dir|
106
+ route << dir
107
+ current_dir = File.join(route)
108
+ if @created[current_dir].nil?
109
+ @created[current_dir] = true
110
+ puts "Creating Directory #{current_dir}" if @verbose
111
+ @ftp.mkdir(current_dir) rescue nil
112
+ end
113
+ end
114
+ end
115
+
116
+ # Upload all files matching +wildcard+ to the uploader's root
117
+ # path.
118
+ def upload_files(wildcard)
119
+ Dir[wildcard].each do |fn|
120
+ upload(fn)
121
+ end
122
+ end
123
+
124
+ # Close the uploader.
125
+ def close
126
+ @ftp.close
127
+ end
128
+
129
+ private # --------------------------------------------------------
130
+
131
+ # Upload a single file to the uploader's root path.
132
+ def upload(file)
133
+ puts "Uploading #{file}" if @verbose
134
+ dir = File.dirname(file)
135
+ makedirs(dir)
136
+ @ftp.putbinaryfile(file, file) unless File.directory?(file)
137
+ end
138
+ end
139
+ end