nishidayuya-rd2odt 0.1.1.20090704.01 → 0.1.1.20090706.01
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/NEWS +9 -0
- data/lib/rd2odt/compat/ruby-1.9.x/ftools.rb +261 -0
- data/lib/rd2odt/compat/ruby-1.9.x.rb +11 -0
- data/lib/rd2odt.rb +4 -3
- data/rd2odt.gemspec +3 -1
- data/test/unit/rd2odt-spec.rb +1 -1
- metadata +3 -1
data/NEWS
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
= version 0.1.2 2009-XX-XX
|
2
2
|
|
3
|
+
== a little feature
|
4
|
+
|
5
|
+
* Supported RubyZip 0.9.1 on Ruby 1.9.1 without
|
6
|
+
rubyzip-0.9.1-for-ruby1.9.1.patch.
|
7
|
+
http://sourceforge.net/tracker/?func=detail&aid=2731184&group_id=43107&atid=435172
|
8
|
+
|
3
9
|
== bug fixes
|
4
10
|
|
5
11
|
* Fixed RubyGem dependency (rubyzip).
|
12
|
+
* Fixed name-prefix sepalator (":" => "-").
|
13
|
+
Because OpenOffice.org 3.1.0 cannot handle the OLE object filename (IO error)
|
14
|
+
which is used by ":" charactor.
|
6
15
|
|
7
16
|
= version 0.1.1 2009-07-01
|
8
17
|
|
@@ -0,0 +1,261 @@
|
|
1
|
+
#
|
2
|
+
# = ftools.rb: Extra tools for the File class
|
3
|
+
#
|
4
|
+
# Author:: WATANABE, Hirofumi
|
5
|
+
# Documentation:: Zachary Landau
|
6
|
+
#
|
7
|
+
# This library can be distributed under the terms of the Ruby license.
|
8
|
+
# You can freely distribute/modify this library.
|
9
|
+
#
|
10
|
+
# It is included in the Ruby standard library.
|
11
|
+
#
|
12
|
+
# == Description
|
13
|
+
#
|
14
|
+
# ftools adds several (class, not instance) methods to the File class, for
|
15
|
+
# copying, moving, deleting, installing, and comparing files, as well as
|
16
|
+
# creating a directory path. See the File class for details.
|
17
|
+
#
|
18
|
+
# FileUtils contains all or nearly all the same functionality and more, and
|
19
|
+
# is a recommended option over ftools
|
20
|
+
#
|
21
|
+
# When you
|
22
|
+
#
|
23
|
+
# require 'ftools'
|
24
|
+
#
|
25
|
+
# then the File class aquires some utility methods for copying, moving, and
|
26
|
+
# deleting files, and more.
|
27
|
+
#
|
28
|
+
# See the method descriptions below, and consider using FileUtils as it is
|
29
|
+
# more comprehensive.
|
30
|
+
#
|
31
|
+
class File
|
32
|
+
end
|
33
|
+
|
34
|
+
class << File
|
35
|
+
|
36
|
+
BUFSIZE = 8 * 1024
|
37
|
+
|
38
|
+
#
|
39
|
+
# If +to+ is a valid directory, +from+ will be appended to +to+, adding
|
40
|
+
# and escaping backslashes as necessary. Otherwise, +to+ will be returned.
|
41
|
+
# Useful for appending +from+ to +to+ only if the filename was not specified
|
42
|
+
# in +to+.
|
43
|
+
#
|
44
|
+
def catname(from, to)
|
45
|
+
if directory? to
|
46
|
+
join to.sub(%r([/\\]$), ''), basename(from)
|
47
|
+
else
|
48
|
+
to
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Copies a file +from+ to +to+. If +to+ is a directory, copies +from+
|
54
|
+
# to <tt>to/from</tt>.
|
55
|
+
#
|
56
|
+
def syscopy(from, to)
|
57
|
+
to = catname(from, to)
|
58
|
+
|
59
|
+
fmode = stat(from).mode
|
60
|
+
tpath = to
|
61
|
+
not_exist = !exist?(tpath)
|
62
|
+
|
63
|
+
from = open(from, "rb")
|
64
|
+
to = open(to, "wb")
|
65
|
+
|
66
|
+
begin
|
67
|
+
while true
|
68
|
+
to.syswrite from.sysread(BUFSIZE)
|
69
|
+
end
|
70
|
+
rescue EOFError
|
71
|
+
ret = true
|
72
|
+
rescue
|
73
|
+
ret = false
|
74
|
+
ensure
|
75
|
+
to.close
|
76
|
+
from.close
|
77
|
+
end
|
78
|
+
chmod(fmode, tpath) if not_exist
|
79
|
+
ret
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Copies a file +from+ to +to+ using #syscopy. If +to+ is a directory,
|
84
|
+
# copies +from+ to <tt>to/from</tt>. If +verbose+ is true, <tt>from -> to</tt>
|
85
|
+
# is printed.
|
86
|
+
#
|
87
|
+
def copy(from, to, verbose = false)
|
88
|
+
$stderr.print from, " -> ", catname(from, to), "\n" if verbose
|
89
|
+
syscopy from, to
|
90
|
+
end
|
91
|
+
|
92
|
+
alias cp copy
|
93
|
+
|
94
|
+
#
|
95
|
+
# Moves a file +from+ to +to+ using #syscopy. If +to+ is a directory,
|
96
|
+
# copies from +from+ to <tt>to/from</tt>. If +verbose+ is true, <tt>from ->
|
97
|
+
# to</tt> is printed.
|
98
|
+
#
|
99
|
+
def move(from, to, verbose = false)
|
100
|
+
to = catname(from, to)
|
101
|
+
$stderr.print from, " -> ", to, "\n" if verbose
|
102
|
+
|
103
|
+
if RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ and file? to
|
104
|
+
unlink to
|
105
|
+
end
|
106
|
+
fstat = stat(from)
|
107
|
+
begin
|
108
|
+
rename from, to
|
109
|
+
rescue
|
110
|
+
begin
|
111
|
+
symlink readlink(from), to and unlink from
|
112
|
+
rescue
|
113
|
+
from_stat = stat(from)
|
114
|
+
syscopy from, to and unlink from
|
115
|
+
utime(from_stat.atime, from_stat.mtime, to)
|
116
|
+
begin
|
117
|
+
chown(fstat.uid, fstat.gid, to)
|
118
|
+
rescue
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
alias mv move
|
125
|
+
|
126
|
+
#
|
127
|
+
# Returns +true+ if and only if the contents of files +from+ and +to+ are
|
128
|
+
# identical. If +verbose+ is +true+, <tt>from <=> to</tt> is printed.
|
129
|
+
#
|
130
|
+
def compare(from, to, verbose = false)
|
131
|
+
$stderr.print from, " <=> ", to, "\n" if verbose
|
132
|
+
|
133
|
+
return false if stat(from).size != stat(to).size
|
134
|
+
|
135
|
+
from = open(from, "rb")
|
136
|
+
to = open(to, "rb")
|
137
|
+
|
138
|
+
ret = false
|
139
|
+
fr = tr = ''
|
140
|
+
|
141
|
+
begin
|
142
|
+
while fr == tr
|
143
|
+
fr = from.read(BUFSIZE)
|
144
|
+
if fr
|
145
|
+
tr = to.read(fr.size)
|
146
|
+
else
|
147
|
+
ret = to.read(BUFSIZE)
|
148
|
+
ret = !ret || ret.length == 0
|
149
|
+
break
|
150
|
+
end
|
151
|
+
end
|
152
|
+
rescue
|
153
|
+
ret = false
|
154
|
+
ensure
|
155
|
+
to.close
|
156
|
+
from.close
|
157
|
+
end
|
158
|
+
ret
|
159
|
+
end
|
160
|
+
|
161
|
+
alias cmp compare
|
162
|
+
|
163
|
+
#
|
164
|
+
# Removes a list of files. Each parameter should be the name of the file to
|
165
|
+
# delete. If the last parameter isn't a String, verbose mode will be enabled.
|
166
|
+
# Returns the number of files deleted.
|
167
|
+
#
|
168
|
+
def safe_unlink(*files)
|
169
|
+
verbose = if files[-1].is_a? String then false else files.pop end
|
170
|
+
files.each do |file|
|
171
|
+
begin
|
172
|
+
unlink file
|
173
|
+
$stderr.print "removing ", file, "\n" if verbose
|
174
|
+
rescue Errno::EACCES # for Windows
|
175
|
+
continue if symlink? file
|
176
|
+
begin
|
177
|
+
mode = stat(file).mode
|
178
|
+
o_chmod mode | 0200, file
|
179
|
+
unlink file
|
180
|
+
$stderr.print "removing ", file, "\n" if verbose
|
181
|
+
rescue
|
182
|
+
o_chmod mode, file rescue nil
|
183
|
+
end
|
184
|
+
rescue
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
alias rm_f safe_unlink
|
190
|
+
|
191
|
+
#
|
192
|
+
# Creates a directory and all its parent directories.
|
193
|
+
# For example,
|
194
|
+
#
|
195
|
+
# File.makedirs '/usr/lib/ruby'
|
196
|
+
#
|
197
|
+
# causes the following directories to be made, if they do not exist.
|
198
|
+
# * /usr
|
199
|
+
# * /usr/lib
|
200
|
+
# * /usr/lib/ruby
|
201
|
+
#
|
202
|
+
# You can pass several directories, each as a parameter. If the last
|
203
|
+
# parameter isn't a String, verbose mode will be enabled.
|
204
|
+
#
|
205
|
+
def makedirs(*dirs)
|
206
|
+
verbose = if dirs[-1].is_a? String then false else dirs.pop end
|
207
|
+
mode = 0755
|
208
|
+
for dir in dirs
|
209
|
+
parent = dirname(dir)
|
210
|
+
next if parent == dir or directory? dir
|
211
|
+
makedirs parent unless directory? parent
|
212
|
+
$stderr.print "mkdir ", dir, "\n" if verbose
|
213
|
+
if basename(dir) != ""
|
214
|
+
begin
|
215
|
+
Dir.mkdir dir, mode
|
216
|
+
rescue SystemCallError
|
217
|
+
raise unless directory? dir
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
alias mkpath makedirs
|
224
|
+
|
225
|
+
alias o_chmod chmod
|
226
|
+
|
227
|
+
vsave, $VERBOSE = $VERBOSE, false
|
228
|
+
|
229
|
+
#
|
230
|
+
# Changes permission bits on +files+ to the bit pattern represented
|
231
|
+
# by +mode+. If the last parameter isn't a String, verbose mode will
|
232
|
+
# be enabled.
|
233
|
+
#
|
234
|
+
# File.chmod 0755, 'somecommand'
|
235
|
+
# File.chmod 0644, 'my.rb', 'your.rb', true
|
236
|
+
#
|
237
|
+
def chmod(mode, *files)
|
238
|
+
verbose = if files[-1].is_a? String then false else files.pop end
|
239
|
+
$stderr.printf "chmod %04o %s\n", mode, files.join(" ") if verbose
|
240
|
+
o_chmod mode, *files
|
241
|
+
end
|
242
|
+
$VERBOSE = vsave
|
243
|
+
|
244
|
+
#
|
245
|
+
# If +src+ is not the same as +dest+, copies it and changes the permission
|
246
|
+
# mode to +mode+. If +dest+ is a directory, destination is <tt>dest/src</tt>.
|
247
|
+
# If +mode+ is not set, default is used. If +verbose+ is set to true, the
|
248
|
+
# name of each file copied will be printed.
|
249
|
+
#
|
250
|
+
def install(from, to, mode = nil, verbose = false)
|
251
|
+
to = catname(from, to)
|
252
|
+
unless exist? to and cmp from, to
|
253
|
+
safe_unlink to if exist? to
|
254
|
+
cp from, to, verbose
|
255
|
+
chmod mode, to, verbose if mode
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
# vi:set sw=2:
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# rubyzip-0.9.1 is not supported on Ruby 1.9.x.
|
2
|
+
# Because Ruby 1.9.x is NOT contain ftools.rb.
|
3
|
+
#
|
4
|
+
# This problem is resolved:
|
5
|
+
# http://sourceforge.net/tracker/?func=detail&aid=2731184&group_id=43107&atid=435172
|
6
|
+
# But rubyzip is not released yet.
|
7
|
+
#
|
8
|
+
# So, rd2odt is contain ftools.rb (Ruby 1.8.7p174)
|
9
|
+
# for running with rubyzip-0.9.1 on Ruby 1.9.x.
|
10
|
+
|
11
|
+
$:.push(File.join(File.dirname(__FILE__), "ruby-1.9.x"))
|
data/lib/rd2odt.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
+
require "rd2odt/compat/ruby-1.8.6" if RUBY_VERSION < "1.8.7"
|
4
|
+
require "rd2odt/compat/ruby-1.9.x" if RUBY_VERSION >= "1.9.0"
|
5
|
+
|
3
6
|
require "pp"
|
4
7
|
require "optparse"
|
5
8
|
require "find"
|
@@ -10,8 +13,6 @@ require "rd/rdvisitor"
|
|
10
13
|
require "rd/rdfmt"
|
11
14
|
require "zip/zip"
|
12
15
|
|
13
|
-
require "rd2odt/compat/ruby-1.8.6" if RUBY_VERSION < "1.8.7"
|
14
|
-
|
15
16
|
module RD2ODT
|
16
17
|
@@options = {
|
17
18
|
:backtrace => false,
|
@@ -530,7 +531,7 @@ module RD2ODT
|
|
530
531
|
|
531
532
|
def create_name_prefix
|
532
533
|
t = Time.now
|
533
|
-
return sprintf("rd2odt
|
534
|
+
return sprintf("rd2odt-%d-%06d-%d-",
|
534
535
|
t.tv_sec, t.tv_usec, number_of_include_files)
|
535
536
|
end
|
536
537
|
private :create_name_prefix
|
data/rd2odt.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rd2odt"
|
3
|
-
s.version = "0.1.1.
|
3
|
+
s.version = "0.1.1.20090706.01"
|
4
4
|
|
5
5
|
s.authors = "Yuya.Nishida."
|
6
6
|
s.email = "yuyaAT@ATj96DOT.DOTorg"
|
@@ -27,6 +27,8 @@ EOF
|
|
27
27
|
# "lib/**/*.rb",
|
28
28
|
"lib/rd2odt.rb",
|
29
29
|
"lib/rd2odt/compat/ruby-1.8.6.rb",
|
30
|
+
"lib/rd2odt/compat/ruby-1.9.x.rb",
|
31
|
+
"lib/rd2odt/compat/ruby-1.9.x/ftools.rb",
|
30
32
|
"lib/rd2odt/rdtool/NOTICE.rd2odt",
|
31
33
|
"lib/rd2odt/rdtool/README.rd",
|
32
34
|
"lib/rd2odt/rdtool/README.rd.ja",
|
data/test/unit/rd2odt-spec.rb
CHANGED
@@ -584,7 +584,7 @@ describe RD2ODT::RD2ODTVisitor, "apply_to_Include" do
|
|
584
584
|
end
|
585
585
|
end
|
586
586
|
|
587
|
-
@name_prefix = sprintf("rd2odt
|
587
|
+
@name_prefix = sprintf("rd2odt-%d-%06d-%d-",
|
588
588
|
Time.now.tv_sec, Time.now.tv_usec, 1)
|
589
589
|
|
590
590
|
@visitor = RD2ODT::RD2ODTVisitor.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nishidayuya-rd2odt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1.
|
4
|
+
version: 0.1.1.20090706.01
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuya.Nishida.
|
@@ -34,6 +34,8 @@ files:
|
|
34
34
|
- bin/rd2odt
|
35
35
|
- lib/rd2odt.rb
|
36
36
|
- lib/rd2odt/compat/ruby-1.8.6.rb
|
37
|
+
- lib/rd2odt/compat/ruby-1.9.x.rb
|
38
|
+
- lib/rd2odt/compat/ruby-1.9.x/ftools.rb
|
37
39
|
- lib/rd2odt/rdtool/NOTICE.rd2odt
|
38
40
|
- lib/rd2odt/rdtool/README.rd
|
39
41
|
- lib/rd2odt/rdtool/README.rd.ja
|