tumblr 0.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/README +80 -0
  2. data/Rakefile +235 -0
  3. data/bin/tumblr +0 -0
  4. data/lib/tumblr.rb +25 -25
  5. data/tumblr.gemspec +28 -0
  6. metadata +61 -51
  7. data/a.rb +0 -12
  8. data/gemspec.rb +0 -36
  9. data/install.rb +0 -212
data/README ADDED
@@ -0,0 +1,80 @@
1
+ NAME
2
+ tumblr
3
+
4
+ SYNOPSIS
5
+ tumblr (setup|write|read|authenticate|check-vimeo|check-audio) [options]+
6
+
7
+ DESCRIPTION
8
+ tumblr.rb is a command line utility and library which interfaces to the
9
+ excellent tumblr blogging platform @ http://www.tumblr.com
10
+
11
+ tumblr.rb implements the complete restful api in both library and
12
+ command line utility, doccumented in full @ http://www.tumblr.com/api
13
+
14
+ === install ===
15
+
16
+ gem install tumblr
17
+
18
+ === cli ===
19
+
20
+ the cli exactly mirrors the library api. arguments are passed to each
21
+ method as 'key=val' pairs, values may be read from files using the
22
+ syntax 'key=file=val' or 'key==val'
23
+
24
+ you should first cache your login info to avoid having to pass it everytime
25
+
26
+ cfp: ~> tumblr setup --email=my_email --password=my_password --name=drawohara
27
+ /Users/ahoward/.tumblr.yml
28
+
29
+ you can post
30
+
31
+ cfp: ~> tumblr write regular title=testing body=rock_on
32
+
33
+ you can post from files
34
+
35
+ cfp: ~> tumblr write regular title=slurp body==./post.html
36
+
37
+ you can read
38
+
39
+ cfp: ~> tumblr read start=42 num=42
40
+
41
+ you can test the auth
42
+
43
+ cfp: ~> tumblr authenticate
44
+
45
+ etc.
46
+
47
+ === api ===
48
+
49
+ it's pretty simple. here's a start, use the web docs to figure out the
50
+ rest
51
+
52
+ config = {
53
+ :email => my_email,
54
+ :password => my_password,
55
+ :name => 'drawohara'
56
+ }
57
+
58
+ tumblr = Tumblr.for config
59
+
60
+ abort unless tumblr.uri == 'http://drawohara.tumblr.com'
61
+
62
+ response = tumblr.write :regular, :title = title, :body => body
63
+
64
+ video = open 'video.mpg'
65
+ response = tumblr.write :video, :data => video, :title => video.path
66
+
67
+ response = tumblr.read :start => 42, :num => 42
68
+ xml = response.content
69
+
70
+ response = tumblr.read :start => 42, :num => 42, :json => true
71
+ json = response.content
72
+
73
+ PARAMETERS
74
+ --name=name, -n (0 ~> name)
75
+ --email=email, -e (0 ~> email)
76
+ --password=password, -p (0 ~> password)
77
+ --debug, -d
78
+ --json, -j
79
+ --help, -h
80
+
@@ -0,0 +1,235 @@
1
+
2
+ This.rubyforge_project = 'codeforpeople'
3
+ This.author = "Ara T. Howard"
4
+ This.email = "ara.t.howard@gmail.com"
5
+ This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
6
+
7
+
8
+ task :default do
9
+ puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
10
+ end
11
+
12
+
13
+ task :gemspec do
14
+ ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
15
+ ignore_directories = 'pkg'
16
+ ignore_files = 'test/log'
17
+
18
+ shiteless =
19
+ lambda do |list|
20
+ list.delete_if do |entry|
21
+ next unless test(?e, entry)
22
+ extension = File.basename(entry).split(%r/[.]/).last
23
+ ignore_extensions.any?{|ext| ext === extension}
24
+ end
25
+ list.delete_if do |entry|
26
+ next unless test(?d, entry)
27
+ dirname = File.expand_path(entry)
28
+ ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
29
+ end
30
+ list.delete_if do |entry|
31
+ next unless test(?f, entry)
32
+ filename = File.expand_path(entry)
33
+ ignore_files.any?{|file| File.expand_path(file) == filename}
34
+ end
35
+ end
36
+
37
+ lib = This.lib
38
+ object = This.object
39
+ version = This.version
40
+ files = shiteless[Dir::glob("**/**")]
41
+ executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
42
+ has_rdoc = true #File.exist?('doc')
43
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
44
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
45
+ description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
46
+
47
+ extensions = This.extensions
48
+ if extensions.nil?
49
+ %w( Makefile configure extconf.rb ).each do |ext|
50
+ extensions << ext if File.exists?(ext)
51
+ end
52
+ end
53
+ extensions = [extensions].flatten.compact
54
+
55
+ template =
56
+ if test(?e, 'gemspec.erb')
57
+ Template{ IO.read('gemspec.erb') }
58
+ else
59
+ Template {
60
+ <<-__
61
+ ## #{ lib }.gemspec
62
+ #
63
+
64
+ Gem::Specification::new do |spec|
65
+ spec.name = #{ lib.inspect }
66
+ spec.version = #{ version.inspect }
67
+ spec.platform = Gem::Platform::RUBY
68
+ spec.summary = #{ lib.inspect }
69
+ spec.description = #{ description.inspect }
70
+
71
+ spec.files = #{ files.inspect }
72
+ spec.executables = #{ executables.inspect }
73
+
74
+ spec.require_path = "lib"
75
+
76
+ spec.has_rdoc = #{ has_rdoc.inspect }
77
+ spec.test_files = #{ test_files.inspect }
78
+ #spec.add_dependency 'lib', '>= version'
79
+ #spec.add_dependency 'fattr'
80
+
81
+ spec.extensions.push(*#{ extensions.inspect })
82
+
83
+ spec.rubyforge_project = #{ This.rubyforge_project.inspect }
84
+ spec.author = #{ This.author.inspect }
85
+ spec.email = #{ This.email.inspect }
86
+ spec.homepage = #{ This.homepage.inspect }
87
+ end
88
+ __
89
+ }
90
+ end
91
+
92
+ unless test(?e, "#{ lib }.gemspec")
93
+ open("#{ lib }.gemspec", "w"){|fd| fd.puts template}
94
+ end
95
+ This.gemspec = "#{ lib }.gemspec"
96
+ end
97
+
98
+ task :gem => [:clean, :gemspec] do
99
+ Fu.mkdir_p This.pkgdir
100
+ before = Dir['*.gem']
101
+ cmd = "gem build #{ This.gemspec }"
102
+ `#{ cmd }`
103
+ after = Dir['*.gem']
104
+ gem = ((after - before).first || after.first) or abort('no gem!')
105
+ Fu.mv gem, This.pkgdir
106
+ This.gem = File.basename(gem)
107
+ end
108
+
109
+ task :readme do
110
+ samples = ''
111
+ prompt = '~ > '
112
+ lib = This.lib
113
+ version = This.version
114
+
115
+ Dir['sample*/*'].sort.each do |sample|
116
+ samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
117
+
118
+ cmd = "cat #{ sample }"
119
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
120
+ samples << Util.indent(`#{ cmd }`, 4) << "\n"
121
+
122
+ cmd = "ruby #{ sample }"
123
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
124
+
125
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
126
+ samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
127
+ end
128
+
129
+ template =
130
+ if test(?e, 'readme.erb')
131
+ Template{ IO.read('readme.erb') }
132
+ else
133
+ Template {
134
+ <<-__
135
+ NAME
136
+ #{ lib }
137
+
138
+ DESCRIPTION
139
+
140
+ INSTALL
141
+ gem install #{ lib }
142
+
143
+ SAMPLES
144
+ #{ samples }
145
+ __
146
+ }
147
+ end
148
+
149
+ open("README", "w"){|fd| fd.puts template}
150
+ end
151
+
152
+
153
+ task :clean do
154
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
155
+ end
156
+
157
+
158
+ task :release => [:clean, :gemspec, :gem] do
159
+ gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
160
+ raise "which one? : #{ gems.inspect }" if gems.size > 1
161
+ raise "no gems?" if gems.size < 1
162
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
163
+ puts cmd
164
+ system cmd
165
+ end
166
+
167
+
168
+
169
+
170
+
171
+ BEGIN {
172
+ $VERBOSE = nil
173
+
174
+ require 'ostruct'
175
+ require 'erb'
176
+ require 'fileutils'
177
+
178
+ Fu = FileUtils
179
+
180
+ This = OpenStruct.new
181
+
182
+ This.file = File.expand_path(__FILE__)
183
+ This.dir = File.dirname(This.file)
184
+ This.pkgdir = File.join(This.dir, 'pkg')
185
+
186
+ lib = ENV['LIB']
187
+ unless lib
188
+ lib = File.basename(Dir.pwd)
189
+ end
190
+ This.lib = lib
191
+
192
+ version = ENV['VERSION']
193
+ unless version
194
+ require "./lib/#{ This.lib }"
195
+ This.name = lib.capitalize
196
+ This.object = eval(This.name)
197
+ version = This.object.send(:version)
198
+ end
199
+ This.version = version
200
+
201
+ abort('no lib') unless This.lib
202
+ abort('no version') unless This.version
203
+
204
+ module Util
205
+ def indent(s, n = 2)
206
+ s = unindent(s)
207
+ ws = ' ' * n
208
+ s.gsub(%r/^/, ws)
209
+ end
210
+
211
+ def unindent(s)
212
+ indent = nil
213
+ s.each do |line|
214
+ next if line =~ %r/^\s*$/
215
+ indent = line[%r/^\s*/] and break
216
+ end
217
+ indent ? s.gsub(%r/^#{ indent }/, "") : s
218
+ end
219
+ extend self
220
+ end
221
+
222
+ class Template
223
+ def initialize(&block)
224
+ @block = block
225
+ @template = block.call.to_s
226
+ end
227
+ def expand(b=nil)
228
+ ERB.new(Util.unindent(@template)).result(b||@block)
229
+ end
230
+ alias_method 'to_s', 'expand'
231
+ end
232
+ def Template(*args, &block) Template.new(*args, &block) end
233
+
234
+ Dir.chdir(This.dir)
235
+ }
data/bin/tumblr CHANGED
File without changes
@@ -1,15 +1,8 @@
1
1
  #
2
2
  # gems
3
3
  #
4
- begin
5
- gem "main", ">= 2.5.0"
6
- gem "attributes", ">= 4.1.0"
7
- gem "httpclient", ">= 2.1.2"
8
- rescue Exception
9
- 42
10
- end
11
4
  require "main"
12
- require "attributes"
5
+ require "fattr"
13
6
  require "httpclient"
14
7
  #
15
8
  # built-in
@@ -20,21 +13,28 @@
20
13
  # tumblr.rb
21
14
  #
22
15
  module Tumblr
23
- def self.for *a, &b
24
- Account.new *a, &b
16
+ Version = '2.0.0'
17
+
18
+ class << Tumblr
19
+ def version() Tumblr::Version end
20
+
21
+ def for *a, &b
22
+ Account.new *a, &b
23
+ end
25
24
  end
26
25
 
26
+
27
27
  class Account
28
- attribute "name"
29
- attribute "email"
30
- attribute "password"
31
- attribute "debug"
32
- attribute("uri"){ "http://#{ name }.tumblr.com" }
33
- attribute("generator"){ "tumblr.rb" }
34
- attribute("proxy"){ ENV["HTTP_PROXY"] }
35
- attribute("httpclient"){ HTTPClient.new proxy }
36
- attribute("api"){ API.new "account" => account }
37
- attribute("account"){ self }
28
+ fattr "name"
29
+ fattr "email"
30
+ fattr "password"
31
+ fattr "debug"
32
+ fattr("uri"){ "http://#{ name }.tumblr.com" }
33
+ fattr("generator"){ "tumblr.rb" }
34
+ fattr("proxy"){ ENV["HTTP_PROXY"] }
35
+ fattr("httpclient"){ HTTPClient.new proxy }
36
+ fattr("api"){ API.new "account" => account }
37
+ fattr("account"){ self }
38
38
 
39
39
  def initialize options = {}
40
40
  options.each{|k,v| send k, v}
@@ -56,11 +56,11 @@
56
56
  end
57
57
 
58
58
  class API
59
- attribute "account"
60
- attribute("uri"){ "#{ account.uri }/api" }
61
- attribute("uri_write"){ "#{ uri }/write" }
62
- attribute("uri_read"){ "#{ uri }/read" }
63
- attribute("uri_read_json"){ "#{ uri }/read/json" }
59
+ fattr "account"
60
+ fattr("uri"){ "#{ account.uri }/api" }
61
+ fattr("uri_write"){ "#{ uri }/write" }
62
+ fattr("uri_read"){ "#{ uri }/read" }
63
+ fattr("uri_read_json"){ "#{ uri }/read/json" }
64
64
 
65
65
  def initialize options = {}
66
66
  options.each{|k,v| send k, v}
@@ -0,0 +1,28 @@
1
+ ## tumblr.gemspec
2
+ #
3
+
4
+ Gem::Specification::new do |spec|
5
+ spec.name = "tumblr"
6
+ spec.version = "2.0.0"
7
+ spec.platform = Gem::Platform::RUBY
8
+ spec.summary = "tumblr"
9
+ spec.description = "a command line utility and library for the excellent tumblr blogging platform"
10
+
11
+ spec.files = ["bin", "bin/tumblr", "lib", "lib/tumblr.rb", "Rakefile", "README", "tumblr.gemspec"]
12
+ spec.executables = ["tumblr"]
13
+
14
+ spec.require_path = "lib"
15
+
16
+ spec.has_rdoc = true
17
+ spec.test_files = nil
18
+ spec.add_dependency 'fattr'
19
+ spec.add_dependency 'main'
20
+ spec.add_dependency 'httpclient'
21
+
22
+ spec.extensions.push(*[])
23
+
24
+ spec.rubyforge_project = "codeforpeople"
25
+ spec.author = "Ara T. Howard"
26
+ spec.email = "ara.t.howard@gmail.com"
27
+ spec.homepage = "http://github.com/ahoward/tumblr/tree/master"
28
+ end
metadata CHANGED
@@ -1,78 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: tumblr
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-11-02 00:00:00 -06:00
8
- summary: tumblr
9
- require_paths:
10
- - lib
11
- email: ara.t.howard@gmail.com
12
- homepage: http://codeforpeople.com/lib/ruby/tumblr/
13
- rubyforge_project:
14
- description:
15
- autorequire: tumblr
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 2.0.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Ara T. Howard
31
- files:
32
- - a.rb
33
- - bin
34
- - bin/tumblr
35
- - gemspec.rb
36
- - install.rb
37
- - lib
38
- - lib/tumblr.rb
39
- test_files: []
40
-
41
- rdoc_options: []
42
-
43
- extra_rdoc_files: []
44
-
45
- executables:
46
- - tumblr
47
- extensions: []
48
-
49
- requirements: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
50
11
 
12
+ date: 2009-10-14 00:00:00 -06:00
13
+ default_executable:
51
14
  dependencies:
52
15
  - !ruby/object:Gem::Dependency
53
- name: main
16
+ name: fattr
17
+ type: :runtime
54
18
  version_requirement:
55
- version_requirements: !ruby/object:Gem::Version::Requirement
19
+ version_requirements: !ruby/object:Gem::Requirement
56
20
  requirements:
57
21
  - - ">="
58
22
  - !ruby/object:Gem::Version
59
- version: 2.5.0
23
+ version: "0"
60
24
  version:
61
25
  - !ruby/object:Gem::Dependency
62
- name: attributes
26
+ name: main
27
+ type: :runtime
63
28
  version_requirement:
64
- version_requirements: !ruby/object:Gem::Version::Requirement
29
+ version_requirements: !ruby/object:Gem::Requirement
65
30
  requirements:
66
31
  - - ">="
67
32
  - !ruby/object:Gem::Version
68
- version: 4.1.0
33
+ version: "0"
69
34
  version:
70
35
  - !ruby/object:Gem::Dependency
71
36
  name: httpclient
37
+ type: :runtime
72
38
  version_requirement:
73
- version_requirements: !ruby/object:Gem::Version::Requirement
39
+ version_requirements: !ruby/object:Gem::Requirement
74
40
  requirements:
75
41
  - - ">="
76
42
  - !ruby/object:Gem::Version
77
- version: 2.1.2
43
+ version: "0"
78
44
  version:
45
+ description: a command line utility and library for the excellent tumblr blogging platform
46
+ email: ara.t.howard@gmail.com
47
+ executables:
48
+ - tumblr
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - bin/tumblr
55
+ - lib/tumblr.rb
56
+ - Rakefile
57
+ - README
58
+ - tumblr.gemspec
59
+ has_rdoc: true
60
+ homepage: http://github.com/ahoward/tumblr/tree/master
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project: codeforpeople
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: tumblr
87
+ test_files: []
88
+
data/a.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'tumblr'
2
-
3
- name, email, password, *ignored = ARGV
4
-
5
- tumblr = Tumblr.for :name => name,
6
- :email => email,
7
- :password => password
8
-
9
- [:authenticate, :check_vimeo, :check_audio].each do |m|
10
- response = tumblr.send m
11
- p response
12
- end
data/gemspec.rb DELETED
@@ -1,36 +0,0 @@
1
- lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
2
-
3
- require 'rubygems'
4
-
5
- Gem::Specification::new do |spec|
6
- $VERBOSE = nil
7
-
8
- shiteless = lambda do |list|
9
- list.delete_if do |file|
10
- file =~ %r/\.svn/ or file =~ %r/\.tmp/
11
- end
12
- end
13
-
14
- spec.name = lib
15
- spec.version = version
16
- spec.platform = Gem::Platform::RUBY
17
- spec.summary = lib
18
-
19
- spec.files = shiteless[Dir::glob("**/**")]
20
- spec.executables = shiteless[Dir::glob("bin/*")].map{|exe| File::basename exe}
21
-
22
- spec.require_path = "lib"
23
- spec.autorequire = lib
24
-
25
- spec.has_rdoc = File::exist? "doc"
26
- spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
27
- spec.add_dependency 'main', '>= 2.5.0'
28
- spec.add_dependency 'attributes', '>= 4.1.0'
29
- spec.add_dependency 'httpclient', '>= 2.1.2' # rock on NaHi
30
-
31
- spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
32
-
33
- spec.author = "Ara T. Howard"
34
- spec.email = "ara.t.howard@gmail.com"
35
- spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
36
- end
data/install.rb DELETED
@@ -1,212 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rbconfig'
3
- require 'find'
4
- require 'ftools'
5
- require 'tempfile'
6
- include Config
7
-
8
- LIBDIR = "lib"
9
- LIBDIR_MODE = 0644
10
-
11
- BINDIR = "bin"
12
- BINDIR_MODE = 0755
13
-
14
-
15
- $srcdir = CONFIG["srcdir"]
16
- $version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
17
- $libdir = File.join(CONFIG["libdir"], "ruby", $version)
18
- $archdir = File.join($libdir, CONFIG["arch"])
19
- $site_libdir = $:.find {|x| x =~ /site_ruby$/}
20
- $bindir = CONFIG["bindir"] || CONFIG['BINDIR']
21
- $ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME'] || 'ruby'
22
- $ruby_ext = CONFIG['EXEEXT'] || ''
23
- $ruby = File.join($bindir, ($ruby_install_name + $ruby_ext))
24
-
25
- if !$site_libdir
26
- $site_libdir = File.join($libdir, "site_ruby")
27
- elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
28
- $site_libdir = File.join($site_libdir, $version)
29
- end
30
-
31
- def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
32
- #{{{
33
- path = []
34
- dir = []
35
- Find.find(srcdir) do |f|
36
- next unless FileTest.file?(f)
37
- next if (f = f[srcdir.length+1..-1]) == nil
38
- next if (/CVS$/ =~ File.dirname(f))
39
- next if f =~ %r/\.lnk/
40
- next if f =~ %r/\.svn/
41
- next if f =~ %r/\.swp/
42
- path.push f
43
- dir |= [File.dirname(f)]
44
- end
45
- for f in dir
46
- next if f == "."
47
- next if f == "CVS"
48
- File::makedirs(File.join(destdir, f))
49
- end
50
- for f in path
51
- next if (/\~$/ =~ f)
52
- next if (/^\./ =~ File.basename(f))
53
- unless bin
54
- File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
55
- else
56
- from = File.join(srcdir, f)
57
- to = File.join(destdir, f)
58
- shebangify(from) do |sf|
59
- $deferr.print from, " -> ", File::catname(from, to), "\n"
60
- $deferr.printf "chmod %04o %s\n", mode, to
61
- File::install(sf, to, mode, false)
62
- end
63
- end
64
- end
65
- #}}}
66
- end
67
- def shebangify f
68
- #{{{
69
- open(f) do |fd|
70
- buf = fd.read 42
71
- if buf =~ %r/^\s*#\s*!.*ruby/o
72
- ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
73
- begin
74
- fd.rewind
75
- ftmp.puts "#!#{ $ruby }"
76
- while((buf = fd.read(8192)))
77
- ftmp.write buf
78
- end
79
- ftmp.close
80
- yield ftmp.path
81
- ensure
82
- ftmp.close!
83
- end
84
- else
85
- yield f
86
- end
87
- end
88
- #}}}
89
- end
90
- def ARGV.switch
91
- #{{{
92
- return nil if self.empty?
93
- arg = self.shift
94
- return nil if arg == '--'
95
- if arg =~ /^-(.)(.*)/
96
- return arg if $1 == '-'
97
- raise 'unknown switch "-"' if $2.index('-')
98
- self.unshift "-#{$2}" if $2.size > 0
99
- "-#{$1}"
100
- else
101
- self.unshift arg
102
- nil
103
- end
104
- #}}}
105
- end
106
- def ARGV.req_arg
107
- #{{{
108
- self.shift || raise('missing argument')
109
- #}}}
110
- end
111
- def linkify d, linked = []
112
- #--{{{
113
- if test ?d, d
114
- versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
115
- versioned.each do |v|
116
- src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
117
- lnk = nil
118
- begin
119
- if test ?l, dst
120
- lnk = "#{ dst }.lnk"
121
- puts "#{ dst } -> #{ lnk }"
122
- File::rename dst, lnk
123
- end
124
- unless test ?e, dst
125
- puts "#{ src } -> #{ dst }"
126
- File::copy src, dst
127
- linked << dst
128
- end
129
- ensure
130
- if lnk
131
- at_exit do
132
- puts "#{ lnk } -> #{ dst }"
133
- File::rename lnk, dst
134
- end
135
- end
136
- end
137
- end
138
- end
139
- linked
140
- #--}}}
141
- end
142
-
143
-
144
- #
145
- # main program
146
- #
147
-
148
- libdir = $site_libdir
149
- bindir = $bindir
150
- no_linkify = false
151
- linked = nil
152
- help = false
153
-
154
- usage = <<-usage
155
- #{ File::basename $0 }
156
- -d, --destdir <destdir>
157
- -l, --libdir <libdir>
158
- -b, --bindir <bindir>
159
- -r, --ruby <ruby>
160
- -n, --no_linkify
161
- -s, --sudo
162
- -h, --help
163
- usage
164
-
165
- begin
166
- while switch = ARGV.switch
167
- case switch
168
- when '-d', '--destdir'
169
- libdir = ARGV.req_arg
170
- when '-l', '--libdir'
171
- libdir = ARGV.req_arg
172
- when '-b', '--bindir'
173
- bindir = ARGV.req_arg
174
- when '-r', '--ruby'
175
- $ruby = ARGV.req_arg
176
- when '-n', '--no_linkify'
177
- no_linkify = true
178
- when '-s', '--sudo'
179
- sudo = 'sudo'
180
- when '-h', '--help'
181
- help = true
182
- else
183
- raise "unknown switch #{switch.dump}"
184
- end
185
- end
186
- rescue
187
- STDERR.puts $!.to_s
188
- STDERR.puts usage
189
- exit 1
190
- end
191
-
192
- if help
193
- STDOUT.puts usage
194
- exit
195
- end
196
-
197
- system "#{ sudo } #{ $ruby } pre-install.rb" if test(?s, 'pre-install.rb')
198
-
199
- unless no_linkify
200
- linked = linkify('lib') + linkify('bin')
201
- end
202
-
203
- system "#{ $ruby } extconf.rb && make && #{ sudo } make install" if test(?s, 'extconf.rb')
204
-
205
- install_rb(LIBDIR, libdir, LIBDIR_MODE)
206
- install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
207
-
208
- if linked
209
- linked.each{|path| File::rm_f path}
210
- end
211
-
212
- system "#{ sudo } #{ $ruby } post-install.rb" if test(?s, 'post-install.rb')