rtask 009 → 010

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ == 010: 2008-07-10
2
+ * yhara:
3
+ * patch for new rubyforge(1.0.0) interface
4
+ * check to exist zip file
5
+ * Keita Yamaguchi:
6
+ * added gem editor(curses version)
7
+ * removed gemify dependency
8
+
1
9
  == 009: 2008-04-22
2
10
  * Keita Yamaguchi:
3
11
  * Fixed publish task
data/README.txt CHANGED
@@ -4,15 +4,23 @@ Author:: Keita Yamaguchi(山口 慶太) <keita.yamaguchi@gmail.com>
4
4
  Copyright:: © Keita Yamaguchi, 2008. All rights reserved.
5
5
  License:: Ruby License
6
6
 
7
- RTask provides easy way to release Ruby’s gem packages. This also provides useful Rake tasks for releasing packages and uploading documents.
7
+ RTask provides easy way to release RubyGems packages. This also provides useful Rake tasks for releasing packages and uploading documents.
8
8
 
9
9
  == Usage
10
10
 
11
11
  See {the document}[http://github.com/keita/rtask/wikis] for details.
12
12
 
13
+ === Edit gemspec
14
+
15
+ RTask creates a gem by gemspec file.
16
+
17
+ % rtask
18
+
19
+ The gem generated by RTask contains files included in Manifest.txt.
20
+
13
21
  === How to release packages
14
22
 
15
- First, you should setup rubyforge and gemify. Next, let's run rtask command.
23
+ First, you should setup rubyforge. Next, let's run rtask command.
16
24
 
17
25
  % rtask -r
18
26
 
@@ -28,11 +36,14 @@ It's all.
28
36
 
29
37
  % rtask -c
30
38
 
39
+ == Contributers
40
+
41
+ * yhara(http://github.com/yhara)
42
+
31
43
  == Links
32
44
 
33
45
  * RTask
34
46
  * {RubyForge}[http://rubyforge.org/projects/rtask/]
35
47
  * {GitHub}[http://github.com/keita/rtask/tree/master]
36
- * {Gemify}[http://dojo.rubyforge.org/gemify/] : RTask is developed for using with Gemify.
37
- * author's blog(written in Japanese)
48
+ * Author's blog(written in Japanese)
38
49
  * {¬¬日常日記}[http://d.hatena.ne.jp/keita_yamaguchi/]
data/bin/rtask CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rubygems"
4
4
  require "rtask"
5
+ require "rtask/ui"
5
6
  require "optparse"
6
7
 
7
8
  $task = RTask.new(:use => :all)
@@ -62,5 +63,7 @@ OptionParser.new(nil, 24) do |opt|
62
63
  puts RTask::VERSION; exit
63
64
  end
64
65
 
65
- opt.parse!(ARGV)
66
+ opt.parse(ARGV)
66
67
  end
68
+
69
+ RTask::UI.start($task, :curses) unless ARGV.size > 0
@@ -1,12 +1,8 @@
1
1
  require 'rake'
2
2
  require 'rubyforge'
3
- require 'gemify'
4
3
 
5
- # == Usage
6
- # First, you setup gemify.
7
- # % gemify
8
- #
9
- # Second, add RTask in your Rakefile:
4
+ # == Usage for Rake users
5
+ # RTask in your Rakefile:
10
6
  # require 'rubygems'
11
7
  # require 'rtask'
12
8
  # RTask.new
@@ -24,18 +20,20 @@ require 'gemify'
24
20
  # rake tgz # Create the tgz package
25
21
  #
26
22
  class RTask
27
- VERSION = "009"
23
+ VERSION = "010"
28
24
  MESSAGE = Hash.new
29
25
 
30
- attr_reader :project, :package, :version
26
+ attr_reader :spec, :project, :package, :version
31
27
 
32
28
  def initialize(config={:use => :all})
29
+ @spec = init_spec
30
+ @spec.files = manifest
33
31
  @rubyforge = ::RubyForge.new
32
+ @rubyforge.configure
34
33
  @user = @rubyforge.userconfig
35
- @gemify = Gemify.new.instance_eval{@settings}
36
- @project = @gemify[:rubyforge_project]
37
- @package = @gemify[:name]
38
- @version = @gemify[:version]
34
+ @project = @spec.rubyforge_project
35
+ @package = @spec.name
36
+ @version = @spec.version
39
37
  @lib_version = config[:version]
40
38
  if config.has_key?(:use)
41
39
  list = config[:use]
@@ -45,6 +43,40 @@ class RTask
45
43
  yield self if block_given?
46
44
  end
47
45
 
46
+ # Initialize gem specification.
47
+ def init_spec
48
+ # if .rtask exists
49
+ if File.exist?(".rtask")
50
+ return YAML.load(File.read(".rtask"))
51
+ end
52
+
53
+ # if gemspec exists
54
+ Dir.glob("*.gemspec") do |spec|
55
+ return RTask::Spec.new(::Gem::Specification.load(spec))
56
+ end
57
+
58
+ # if .gemified exists
59
+ if File.exist?(".gemified")
60
+ data = YAML.load(File.read(".gemified"))
61
+ spec = ::Gem::Specification.new
62
+ spec.summary = data[:summary]
63
+ spec.email = data[:email]
64
+ spec.name = data[:name]
65
+ spec.homepage = data[:homepage]
66
+ spec.version = data[:version]
67
+ spec.rubyforge_project = data[:rubyforge_project]
68
+ # assume gemify's "dependencies" are runtime dependencies
69
+ data[:dependencies].each do |dep|
70
+ spec.add_runtime_dependency dep
71
+ end
72
+ spec.authors << data[:author]
73
+ return RTask::Spec.new(spec)
74
+ end
75
+
76
+ # no specification
77
+ return RTask::Spec.new
78
+ end
79
+
48
80
  # define task
49
81
  def self.define_task(description, rule)
50
82
  name = rule
@@ -120,9 +152,9 @@ class RTask
120
152
  gem = filename + ".gem"
121
153
  tgz = filename + ".tgz"
122
154
  zip = filename + ".zip"
123
- if File.exist?(gem) and File.exist?(tgz)
155
+ if File.exist?(gem) and File.exist?(tgz) and File.exist?(zip)
124
156
  @rubyforge.add_release @project, @package, @version, gem, tgz, zip
125
- puts "Released #{gem} and #{tgz}"
157
+ puts "Released #{gem}, #{tgz}, and #{zip}"
126
158
  else
127
159
  puts "Please make gem and tgz files first: rake gem tgz"
128
160
  exit
@@ -136,7 +168,7 @@ class RTask
136
168
 
137
169
  # Task for creating gem
138
170
  def gem
139
- sh "gemify -I"
171
+ Gem.build(@spec)
140
172
  end
141
173
 
142
174
  define_task "Create the gem package", :gem
@@ -168,7 +200,7 @@ class RTask
168
200
  private
169
201
 
170
202
  def manifest
171
- manifest = Dir.glob("*Manifest*", File::FNM_CASEFOLD).first
203
+ manifest = Dir.glob("*manifest*", File::FNM_CASEFOLD).first
172
204
  unless manifest
173
205
  puts "Please make manifest"
174
206
  exit
@@ -176,3 +208,6 @@ class RTask
176
208
  File.read(manifest).split("\n")
177
209
  end
178
210
  end
211
+
212
+ require "rtask/spec"
213
+ require "rtask/gem"
@@ -0,0 +1,22 @@
1
+ require "rubygems/specification"
2
+
3
+ class RTask
4
+ module Gem
5
+ def self.build(spec)
6
+ ::Gem::Builder.new(spec).build
7
+ end
8
+
9
+ def self.gemspec(spec)
10
+ spec.gemspec
11
+ end
12
+ end
13
+ end
14
+
15
+ # for showing gem specs
16
+ module Gem
17
+ class Dependency
18
+ def to_s
19
+ @name.to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ require "delegate"
2
+
3
+ class RTask
4
+ class Spec < DelegateClass(::Gem::Specification)
5
+ def initialize(gem_spec = ::Gem::Specification.new)
6
+ super(gem_spec)
7
+ end
8
+
9
+ def attributes
10
+ __getobj__.class.attribute_names
11
+ end
12
+
13
+ def bool_attributes
14
+ [:has_rdoc]
15
+ end
16
+
17
+ def standard
18
+ __getobj__.class.required_attributes +
19
+ [:authors, :email, :homepage, :rubyforge_project, :description,
20
+ :has_rdoc, :dependencies ] -
21
+ [:rubygems_version, :specification_version, :date, :require_paths]
22
+ end
23
+
24
+ def required
25
+ ::Gem::Specification.attribute_names.each do |name|
26
+ ::Gem::Specification.required_attribute?()
27
+ end
28
+ end
29
+
30
+ def array
31
+ ::Gem::Specification.array_attributes
32
+ end
33
+
34
+ def type_of(name)
35
+ if array.include?(name)
36
+ return :array
37
+ elsif bool.include?(name)
38
+ return :bool
39
+ else
40
+ return :string
41
+ end
42
+ end
43
+
44
+ alias :bool :bool_attributes
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ module RTask::UI
2
+ # Start the user interface.
3
+ def self.start(rtask, name)
4
+ case name
5
+ when :curses
6
+ require "rtask/ui/curses"
7
+ RTask::UI::CursesInterface.new(rtask).start
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,327 @@
1
+ require "delegate"
2
+ require "cursesx"
3
+ require "readline"
4
+ require "termios"
5
+
6
+ module RTask::UI
7
+ class CursesInterface
8
+ include ::Curses
9
+
10
+ def initialize(rtask)
11
+ @rtask = rtask
12
+ end
13
+
14
+ def start
15
+ # init curses
16
+ init_screen; start_color; cbreak; noecho; nl
17
+
18
+ # init color
19
+ define_color :banner, :white, :blue
20
+ define_color :attribute, :blue, :black
21
+ define_color :current_position, :red, :black
22
+ define_color :required, :red, :black
23
+ define_color :usage, :white, :blue
24
+
25
+ # start the main window
26
+ @main = stdscr
27
+ @main.instance_variable_set(:@spec, @rtask.spec)
28
+ @main.extend Main
29
+ @main.start
30
+ end
31
+
32
+ module Main
33
+ attr_reader :spec
34
+
35
+ def self.extended(obj)
36
+ obj.instance_eval do
37
+ @awin = subwin maxy-7, maxx, 4, 0, Attribute
38
+ @bwin = subwin 4, maxx, 0, 0, Banner
39
+ @dwin = subwin 1, maxx, maxy-1, 0, Display
40
+ @uwin = subwin 1, maxx, maxy-2, 0, Usage
41
+ end
42
+ end
43
+
44
+ # Start to render main window.
45
+ def start
46
+ draw; @awin.start
47
+ end
48
+
49
+ # Draw windows.
50
+ def draw
51
+ clear; children.each {|win| win.draw }
52
+ end
53
+
54
+ # Show the message.
55
+ def message(msg); @dwin << msg; end
56
+
57
+ # Input.
58
+ def input(msg, val=""); @dwin.input(msg, val); end
59
+
60
+ # Wait to input a character.
61
+ def input_char(msg); @dwin.input_char(msg); end
62
+ end
63
+
64
+ # Hedding banner.
65
+ module Banner
66
+ def draw
67
+ clear
68
+ attron(color(:banner)) do
69
+ self << "RTask: gemspec editor".center(maxx)
70
+ end
71
+ setpos(2, 0)
72
+ addstr "Edit .gemspec"
73
+ refresh
74
+ end
75
+ end
76
+
77
+ # Display window for showing messages.
78
+ module Display
79
+ def draw; clear; end
80
+
81
+ # Show the message.
82
+ def <<(msg)
83
+ clear
84
+ setpos(0, 0)
85
+ addstr(msg.to_s.ljust(maxx))
86
+ refresh
87
+ end
88
+
89
+ # Wait to input a line.
90
+ def input(msg, val = "")
91
+ clear
92
+ setpos(0, 0)
93
+ refresh
94
+
95
+ # setup io config
96
+ tio = Termios.getattr(STDIN)
97
+ tio.lflag |= Termios::ECHO
98
+ Termios.setattr(STDIN, Termios::TCSANOW, tio)
99
+
100
+ # read
101
+ Readline::HISTORY << val.to_s
102
+ res = Readline.readline("> #{msg}: ")
103
+
104
+ # restore io config
105
+ tio.lflag &= ~Termios::ECHO
106
+ Termios.setattr(STDIN, Termios::TCSANOW, tio)
107
+
108
+ return res
109
+ end
110
+
111
+ # Wait to input a character.
112
+ def input_char(msg)
113
+ clear
114
+ setpos(0, 0)
115
+ addstr("> #{msg}: ")
116
+ refresh
117
+ return echo { getch }
118
+ end
119
+ end
120
+
121
+ # Attribute list window.
122
+ module Attribute
123
+
124
+ def self.extended(obj)
125
+ obj.instance_eval do
126
+ # doesn't show all
127
+ @show_all = false
128
+ # gem spec
129
+ @spec = parent.spec
130
+ # displayed top item
131
+ @top = 0
132
+ # selected position
133
+ @position = 0
134
+ # width
135
+ @key_width = @spec.attributes.inject(0) do |m, n|
136
+ m > n.to_s.size ? m : n.to_s.size
137
+ end
138
+ # keypad is ok
139
+ keypad(true)
140
+ end
141
+ end
142
+
143
+ def attributes
144
+ @show_all ? @spec.attributes : @spec.standard
145
+ end
146
+
147
+ def draw
148
+ clear
149
+ @top.upto(@top+maxy-1) do |idx|
150
+ break unless attributes[idx]
151
+ setpos(idx - @top, 0)
152
+ show_attribute(attributes[idx], @position == idx)
153
+ end
154
+ refresh
155
+ end
156
+
157
+ def start
158
+ loop do
159
+ # handles input
160
+ case c = getch
161
+ when ?a; toogle_show_all
162
+ when ?u, ::Curses::KEY_UP ; up
163
+ when ?d, ::Curses::KEY_DOWN ; down
164
+ when ?c, ::Curses::KEY_CTRL_J ; change
165
+ when ?b; build_gem
166
+ when ?s; save
167
+ when ?i; IncludedFiles.new(parent.files)
168
+ when ?q; quit
169
+ else
170
+ parent.message "[" + ::Curses.keyname(c).to_s + "]" if $DEBUG
171
+ end
172
+
173
+ # redraw
174
+ draw
175
+ end
176
+ end
177
+
178
+ # Move up.
179
+ def up
180
+ if @position != 0
181
+ @position -= 1
182
+ @top -= 1 if @top == @position + 1
183
+ end
184
+ end
185
+
186
+ # Move down.
187
+ def down
188
+ if @position < attributes.size - 1
189
+ @position += 1
190
+ @top += 1 if @position == @top + maxy
191
+ end
192
+ end
193
+
194
+ # Show all items.
195
+ def toogle_show_all
196
+ @show_all = !@show_all
197
+ @top, @position = 0, 0
198
+ end
199
+
200
+ # Build the gem.
201
+ def build_gem
202
+ unless RTask::Gem.build(@spec)
203
+ parent.message "You need to fill out all the required fields"
204
+ else
205
+ gemname = "#{@spec.name}-#{@spec.version}.gem"
206
+ parent.message("Created " + gemname)
207
+ end
208
+ end
209
+
210
+ def save
211
+ specname = "#{@spec.name}.gemspec"
212
+
213
+ # check required attrs
214
+ if Gem::Specification.required_attributes.any? do |sym|
215
+ @spec.send(sym).nil?
216
+ end
217
+ parent.message "You need to fill out all the required fields"
218
+ else
219
+ File.open(specname, "w") do |file|
220
+ file.write @spec.to_ruby
221
+ end
222
+ parent.message "Saved #{specname}"
223
+ @changed = false
224
+ end
225
+ end
226
+
227
+ def quit
228
+ if @changed
229
+ res = ::Curses.keyname(parent.input_char(<<-__Q__.chomp))
230
+ Changes are not saved. Quit? (y or n)
231
+ __Q__
232
+ return unless res.upcase == "Y"
233
+ end
234
+ exit
235
+ end
236
+
237
+ def change
238
+ name = attributes[@position]
239
+ val = parent.spec.send(name)
240
+ res = case @spec.type_of(name)
241
+ when :array
242
+ msg = "#{name.to_s.capitalize}(Split by ',')"
243
+ (parent.input msg, val.join(",")).strip.split(",")
244
+ when :bool
245
+ !val
246
+ when :string
247
+ parent.input name.to_s.capitalize, val
248
+ end
249
+ if name == :dependencies
250
+ parent.spec.dependencies.clear
251
+ res.each {|dep| parent.spec.add_runtime_dependency dep}
252
+ else
253
+ parent.spec.send("#{name}=", res)
254
+ end
255
+ parent.message "Updated '#{name}'"
256
+ @changed = true
257
+ end
258
+
259
+ def show_attribute(name, highlight)
260
+ val = @spec.send(name)
261
+
262
+ # star
263
+ attron(highlight ? ::Curses::A_UNDERLINE : 0)
264
+ addstr " * "
265
+ addstr name.to_s
266
+ key_width = name.to_s.size
267
+
268
+ # required
269
+ if Gem::Specification.required_attribute?(name) and val.nil?
270
+ attron(color(:required)){ addstr " (required)" }
271
+ key_width += 11
272
+ end
273
+
274
+ # padding + separator
275
+ addstr " ".rjust(@key_width - key_width + 1)
276
+
277
+ # value
278
+ case val
279
+ when Array
280
+ addstr val.join(", ")
281
+ else
282
+ addstr val.to_s
283
+ end unless val.nil?
284
+
285
+ attroff(highlight ? ::Curses::A_UNDERLINE : 0)
286
+ end
287
+ end
288
+
289
+ module Usage
290
+ def draw
291
+ clear
292
+ setpos(0, 0)
293
+ attron(color(:usage)) do
294
+ addstr " q) Quit, s) Save, b) Build the gem, h) Help".ljust(maxx)
295
+ end
296
+ refresh
297
+ end
298
+ end
299
+
300
+ class IncludedFiles < DelegateClass(::Curses::Window)
301
+ def initialize(files)
302
+ @files = files
303
+ window = ::Curses.stdscr
304
+ window.clear
305
+ super(window.subwin(window.maxy, window.maxx, 0, 0))
306
+ draw
307
+ getch
308
+ close
309
+ MAIN_WINDOW.draw
310
+ end
311
+
312
+ def draw
313
+ setpos(0, 0)
314
+ standout
315
+ addstr "Manifest(included files)".center(maxx)
316
+ standend
317
+ @files.each_with_index do |file, idx|
318
+ setpos(idx+1, 0)
319
+ addstr file
320
+ end
321
+ refresh
322
+ end
323
+ end
324
+
325
+ end
326
+ end
327
+
@@ -0,0 +1,38 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{rtask}
3
+ s.version = "010"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Keita Yamaguchi"]
7
+ s.date = %q{2008-07-11}
8
+ s.email = %q{keita.yamaguchi@gmail.com}
9
+ s.files = ["History.txt", "README.txt", "License.txt", "Rakefile", "bin/rtask", "lib/rtask.rb", "lib/rtask/gem.rb", "lib/rtask/spec.rb", "lib/rtask/ui.rb", "lib/rtask/ui/curses.rb", "rtask.gemspec", "setup.rb"]
10
+ s.has_rdoc = true
11
+ s.homepage = %q{http://github.com/keita/rtask/tree/master}
12
+ s.require_paths = ["lib"]
13
+ s.rubyforge_project = %q{rtask}
14
+ s.rubygems_version = %q{1.2.0}
15
+ s.summary = %q{RTask handles tasks for releasing gem packages.}
16
+
17
+ if s.respond_to? :specification_version then
18
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
19
+ s.specification_version = 2
20
+
21
+ if current_version >= 3 then
22
+ s.add_runtime_dependency(%q<cursesx>, [">= 0"])
23
+ s.add_runtime_dependency(%q<rubyforge>, [">= 0"])
24
+ s.add_runtime_dependency(%q<rubyzip>, [">= 0"])
25
+ s.add_runtime_dependency(%q<termios>, [">= 0"])
26
+ else
27
+ s.add_dependency(%q<cursesx>, [">= 0"])
28
+ s.add_dependency(%q<rubyforge>, [">= 0"])
29
+ s.add_dependency(%q<rubyzip>, [">= 0"])
30
+ s.add_dependency(%q<termios>, [">= 0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<cursesx>, [">= 0"])
34
+ s.add_dependency(%q<rubyforge>, [">= 0"])
35
+ s.add_dependency(%q<rubyzip>, [">= 0"])
36
+ s.add_dependency(%q<termios>, [">= 0"])
37
+ end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtask
3
3
  version: !ruby/object:Gem::Version
4
- version: 009
4
+ version: "010"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Yamaguchi
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-22 00:00:00 +09:00
12
+ date: 2008-07-11 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: gemify
16
+ name: cursesx
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: rubyforge
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -32,6 +34,17 @@ dependencies:
32
34
  version:
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: rubyzip
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: termios
47
+ type: :runtime
35
48
  version_requirement:
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
@@ -41,8 +54,8 @@ dependencies:
41
54
  version:
42
55
  description:
43
56
  email: keita.yamaguchi@gmail.com
44
- executables:
45
- - rtask
57
+ executables: []
58
+
46
59
  extensions: []
47
60
 
48
61
  extra_rdoc_files: []
@@ -54,6 +67,11 @@ files:
54
67
  - Rakefile
55
68
  - bin/rtask
56
69
  - lib/rtask.rb
70
+ - lib/rtask/gem.rb
71
+ - lib/rtask/spec.rb
72
+ - lib/rtask/ui.rb
73
+ - lib/rtask/ui/curses.rb
74
+ - rtask.gemspec
57
75
  - setup.rb
58
76
  has_rdoc: true
59
77
  homepage: http://github.com/keita/rtask/tree/master
@@ -77,9 +95,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
95
  requirements: []
78
96
 
79
97
  rubyforge_project: rtask
80
- rubygems_version: 1.1.1
98
+ rubygems_version: 1.2.0
81
99
  signing_key:
82
100
  specification_version: 2
83
- summary: RTask provides useful Rake tasks for releasing gem packages.
101
+ summary: RTask handles tasks for releasing gem packages.
84
102
  test_files: []
85
103