spreadbase 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/COPYING.LESSER +165 -0
- data/README.md +140 -0
- data/lib/spreadbase/codecs/open_document_12.rb +148 -0
- data/lib/spreadbase/codecs/open_document_12_modules/decoding.rb +169 -0
- data/lib/spreadbase/codecs/open_document_12_modules/encoding.rb +200 -0
- data/lib/spreadbase/document.rb +99 -0
- data/lib/spreadbase/helpers/helpers.rb +138 -0
- data/lib/spreadbase/table.rb +273 -0
- data/lib/spreadbase/version.rb +5 -0
- data/lib/spreadbase.rb +37 -0
- data/spec/codecs/open_document_12_spec.rb +137 -0
- data/spec/elements/document_spec.rb +134 -0
- data/spec/elements/table_spec.rb +267 -0
- data/spec/spec_helpers.rb +47 -0
- data/spreadbase.gemspec +24 -0
- data/utils/convert_sqlite_to_ods.rb +154 -0
- data/utils/prettify_file.rb +46 -0
- data/utils/test_ods_folder.rb +40 -0
- data/utils/test_recoding_file.rb +38 -0
- data/utils/test_recoding_from_content.rb +43 -0
- data/utils/utils_helpers.rb +69 -0
- metadata +89 -0
@@ -0,0 +1,267 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
=begin
|
4
|
+
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
5
|
+
|
6
|
+
This file is part of SpreadBase.
|
7
|
+
|
8
|
+
SpreadBase is free software: you can redistribute it and/or modify it under the
|
9
|
+
terms of the GNU Lesser General Public License as published by the Free Software
|
10
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
11
|
+
version.
|
12
|
+
|
13
|
+
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
14
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
15
|
+
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License along
|
18
|
+
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
=end
|
20
|
+
|
21
|
+
require File.expand_path( '../../../lib/spreadbase', __FILE__ )
|
22
|
+
require File.expand_path( '../../spec_helpers', __FILE__ )
|
23
|
+
|
24
|
+
include SpecHelpers
|
25
|
+
|
26
|
+
describe SpreadBase::Table do
|
27
|
+
|
28
|
+
before :each do
|
29
|
+
@sample_table = SpreadBase::Table.new(
|
30
|
+
'abc', [
|
31
|
+
[ 1, 1.1, T_BIGDECIMAL ],
|
32
|
+
[ T_DATE, T_DATETIME, T_TIME ],
|
33
|
+
[ true, 'a', nil ]
|
34
|
+
]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# The full test for checking the row index is here; all the other tests assume that
|
39
|
+
# this routine is called, by checking against the index (-1).
|
40
|
+
#
|
41
|
+
it "should check the row index" do
|
42
|
+
lambda { @sample_table.row( 4 ) }.should raise_error( RuntimeError, "Invalid row index (4) - allowed 0 to 2" )
|
43
|
+
|
44
|
+
# called with :allow_append
|
45
|
+
lambda { @sample_table.insert_row( -1, [] ) }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 3" )
|
46
|
+
lambda { @sample_table.insert_row( 40, [] ) }.should raise_error( RuntimeError, "Invalid row index (40) - allowed 0 to 3" )
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should initialize with data" do
|
50
|
+
expected_data = [
|
51
|
+
[ 1, 1.1, T_BIGDECIMAL ],
|
52
|
+
[ T_DATE, T_DATETIME, T_TIME ],
|
53
|
+
[ true, 'a', nil ]
|
54
|
+
]
|
55
|
+
|
56
|
+
@sample_table.data.should == expected_data
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should raise an error when the initialization requirements are not met" do
|
60
|
+
lambda { SpreadBase::Table.new( nil ) }.should raise_error( "Table name required" )
|
61
|
+
lambda { SpreadBase::Table.new( '' ) }.should raise_error( "Table name required" )
|
62
|
+
|
63
|
+
# This is acceptable
|
64
|
+
#
|
65
|
+
SpreadBase::Table.new( ' ' )
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should access a cell" do
|
69
|
+
@sample_table[ 'a', 0 ].should == 1
|
70
|
+
@sample_table[ 1, 0 ].should == 1.1
|
71
|
+
@sample_table[ 2, 0 ].should == T_BIGDECIMAL
|
72
|
+
@sample_table[ 0, 1 ].should == T_DATE
|
73
|
+
@sample_table[ 'B', 1 ].should == T_DATETIME
|
74
|
+
@sample_table[ 2, 1 ].should == T_TIME
|
75
|
+
@sample_table[ 0, 2 ].should == true
|
76
|
+
@sample_table[ 1, 2 ].should == 'a'
|
77
|
+
@sample_table[ 2, 2 ].should == nil
|
78
|
+
|
79
|
+
lambda { @sample_table[ -1, 0 ] }.should raise_error( RuntimeError, "Negative column indexes not allowed: -1" )
|
80
|
+
lambda { @sample_table[ 0, -1 ] }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 2" )
|
81
|
+
lambda { @sample_table[ 3, 0 ] }.should raise_error( RuntimeError, "Invalid column index (3) for the given row - allowed 0 to 2" )
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should set a cell value" do
|
85
|
+
@sample_table[ 0, 0 ] = 10
|
86
|
+
@sample_table[ 'B', 1 ] = T_TIME
|
87
|
+
|
88
|
+
@sample_table.data.should == [
|
89
|
+
[ 10, 1.1, T_BIGDECIMAL ],
|
90
|
+
[ T_DATE, T_TIME, T_TIME ],
|
91
|
+
[ true, 'a', nil ],
|
92
|
+
]
|
93
|
+
|
94
|
+
lambda { @sample_table[ 0, -1 ] = 33 }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 2" )
|
95
|
+
lambda { @sample_table[ 3, 0 ] = 44 }.should raise_error( RuntimeError, "Invalid column index (3) for the given row - allowed 0 to 2" )
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should access a row" do
|
99
|
+
@sample_table.row( 0 ).should == [ 1, 1.1, T_BIGDECIMAL ]
|
100
|
+
@sample_table.row( 1 ).should == [ T_DATE, T_DATETIME, T_TIME ]
|
101
|
+
|
102
|
+
lambda { @sample_table.row( -1 ) }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 2" )
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should delete a row" do
|
106
|
+
@sample_table.delete_row( 1 ).should == [ T_DATE, T_DATETIME, T_TIME ]
|
107
|
+
|
108
|
+
@sample_table.data.should == [
|
109
|
+
[ 1, 1.1, T_BIGDECIMAL ],
|
110
|
+
[ true, 'a', nil ],
|
111
|
+
]
|
112
|
+
|
113
|
+
lambda { @sample_table.delete_row( -1 ) }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 1" )
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should insert a row" do
|
117
|
+
@sample_table.insert_row( 1, [ 4, 5, 6 ] )
|
118
|
+
|
119
|
+
@sample_table.data.should == [
|
120
|
+
[ 1, 1.1, T_BIGDECIMAL ],
|
121
|
+
[ 4, 5, 6 ],
|
122
|
+
[ T_DATE, T_DATETIME, T_TIME ],
|
123
|
+
[ true, 'a', nil ],
|
124
|
+
]
|
125
|
+
|
126
|
+
# illegal row index tested in separate UT
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should insert a row without error if there is no data" do
|
130
|
+
@sample_table.data = []
|
131
|
+
|
132
|
+
@sample_table.insert_row( 0, [ 4, 5 ] )
|
133
|
+
|
134
|
+
@sample_table.data.size.should == 1
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should append a row" do
|
138
|
+
@sample_table.append_row( [ 4, 5, 6 ] )
|
139
|
+
|
140
|
+
@sample_table.data.should == [
|
141
|
+
[ 1, 1.1, T_BIGDECIMAL ],
|
142
|
+
[ T_DATE, T_DATETIME, T_TIME ],
|
143
|
+
[ true, 'a', nil ],
|
144
|
+
[ 4, 5, 6 ],
|
145
|
+
]
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should access a column" do
|
149
|
+
@sample_table.column( 0 ).should == [ 1, T_DATE, true ]
|
150
|
+
@sample_table.column( 1 ).should == [ 1.1, T_DATETIME, 'a' ]
|
151
|
+
|
152
|
+
@sample_table.column( 3 ).should == [ nil, nil, nil ]
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should delete a column" do
|
156
|
+
@sample_table.column_width_styles = [ 'abc', nil, 'cde' ]
|
157
|
+
|
158
|
+
@sample_table.delete_column( 0 ).should == [ 1, T_DATE, true ]
|
159
|
+
|
160
|
+
@sample_table.column_width_styles.should == [ nil, 'cde' ]
|
161
|
+
|
162
|
+
@sample_table.delete_column( 3 ).should == [ nil, nil, nil ]
|
163
|
+
|
164
|
+
@sample_table.column_width_styles.should == [ nil, 'cde' ]
|
165
|
+
|
166
|
+
@sample_table.data.should == [
|
167
|
+
[ 1.1, T_BIGDECIMAL ],
|
168
|
+
[ T_DATETIME, T_TIME ],
|
169
|
+
[ 'a', nil ]
|
170
|
+
]
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should insert a column" do
|
174
|
+
# Setup/fill table
|
175
|
+
|
176
|
+
@sample_table.column_width_styles = [ 'abc', nil, 'cde' ]
|
177
|
+
|
178
|
+
@sample_table.insert_column( 1, [ 34, 'abc', nil ] )
|
179
|
+
|
180
|
+
@sample_table.data.should == [
|
181
|
+
[ 1, 34, 1.1, T_BIGDECIMAL ],
|
182
|
+
[ T_DATE, 'abc', T_DATETIME, T_TIME ],
|
183
|
+
[ true, nil, 'a', nil ],
|
184
|
+
]
|
185
|
+
|
186
|
+
@sample_table.column_width_styles = [ 'abc', nil, nil, 'cde' ]
|
187
|
+
|
188
|
+
# Empty table
|
189
|
+
|
190
|
+
table = SpreadBase::Table.new( 'abc' )
|
191
|
+
|
192
|
+
table.insert_column( 0, [ 34, 'abc', 1 ] )
|
193
|
+
|
194
|
+
table.data.should == [
|
195
|
+
[ 34, ],
|
196
|
+
[ 'abc' ],
|
197
|
+
[ 1 ],
|
198
|
+
]
|
199
|
+
|
200
|
+
@sample_table.column_width_styles = [ nil ]
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should not insert a column if the size is not correct" do
|
204
|
+
lambda { @sample_table.insert_column( 1, [ 34, 'abc' ] ) }.should raise_error( RuntimeError, "Inserting column size (2) different than existing columns size (3)" )
|
205
|
+
|
206
|
+
@sample_table.data.first.size.should == 3
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should insert a column outside the row boundaries" do
|
210
|
+
@sample_table.insert_column( 5, [ 34, 'abc', nil ] )
|
211
|
+
|
212
|
+
@sample_table.data.should == [
|
213
|
+
[ 1, 1.1, T_BIGDECIMAL, nil, nil, 34 ],
|
214
|
+
[ T_DATE, T_DATETIME, T_TIME, nil, nil, 'abc' ],
|
215
|
+
[ true, 'a', nil, nil, nil, nil ],
|
216
|
+
]
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should append a column" do
|
220
|
+
table = SpreadBase::Table.new( 'abc' )
|
221
|
+
|
222
|
+
table.append_column( [ 34, 'abc', 1 ] )
|
223
|
+
|
224
|
+
table.data.should == [
|
225
|
+
[ 34, ],
|
226
|
+
[ 'abc' ],
|
227
|
+
[ 1 ],
|
228
|
+
]
|
229
|
+
|
230
|
+
table.append_column( [ 'cute', 'little', 'spielerin' ] )
|
231
|
+
|
232
|
+
table.data.should == [
|
233
|
+
[ 34, 'cute' ],
|
234
|
+
[ 'abc', 'little' ],
|
235
|
+
[ 1, 'spielerin' ],
|
236
|
+
]
|
237
|
+
end
|
238
|
+
|
239
|
+
it "return the data as string (:to_s)" do
|
240
|
+
expected_string = "\
|
241
|
+
+------------+---------------------------+---------------------------+
|
242
|
+
| 1 | 1.1 | 0.133E1 |
|
243
|
+
| 2012-04-10 | 2012-04-11T23:33:42+00:00 | 2012-04-11 23:33:42 +0200 |
|
244
|
+
| true | a | |
|
245
|
+
+------------+---------------------------+---------------------------+
|
246
|
+
"
|
247
|
+
@sample_table.to_s.should == expected_string
|
248
|
+
end
|
249
|
+
|
250
|
+
it "return the data as string, with headers (:to_s)" do
|
251
|
+
expected_string = "\
|
252
|
+
+------------+---------------------------+---------------------------+
|
253
|
+
| 1 | 1.1 | 0.133E1 |
|
254
|
+
+------------+---------------------------+---------------------------+
|
255
|
+
| 2012-04-10 | 2012-04-11T23:33:42+00:00 | 2012-04-11 23:33:42 +0200 |
|
256
|
+
| true | a | |
|
257
|
+
+------------+---------------------------+---------------------------+
|
258
|
+
"
|
259
|
+
|
260
|
+
@sample_table.to_s( :with_headers => true ).should == expected_string
|
261
|
+
|
262
|
+
@sample_table.data = []
|
263
|
+
|
264
|
+
@sample_table.to_s( :with_headers => true ).should == ""
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
=begin
|
4
|
+
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
5
|
+
|
6
|
+
This file is part of SpreadBase.
|
7
|
+
|
8
|
+
SpreadBase is free software: you can redistribute it and/or modify it under the
|
9
|
+
terms of the GNU Lesser General Public License as published by the Free Software
|
10
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
11
|
+
version.
|
12
|
+
|
13
|
+
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
14
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
15
|
+
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License along
|
18
|
+
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
=end
|
20
|
+
|
21
|
+
require 'date'
|
22
|
+
require 'bigdecimal'
|
23
|
+
|
24
|
+
module SpecHelpers
|
25
|
+
|
26
|
+
T_DATE = Date.new( 2012, 4, 10 )
|
27
|
+
T_DATETIME = DateTime.new( 2012, 4, 11, 23, 33, 42 )
|
28
|
+
T_TIME = Time.local( 2012, 4, 11, 23, 33, 42 )
|
29
|
+
T_BIGDECIMAL = BigDecimal.new( '1.33' )
|
30
|
+
|
31
|
+
# This method is cool beyond any argument about the imperfect name.
|
32
|
+
#
|
33
|
+
def assert_size( collection, expected_size )
|
34
|
+
collection.size.should == expected_size
|
35
|
+
|
36
|
+
yield( *collection ) if block_given?
|
37
|
+
end
|
38
|
+
|
39
|
+
def stub_initializer( klazz, *args )
|
40
|
+
instance = klazz.new( *args )
|
41
|
+
|
42
|
+
klazz.stub!( :new ).and_return( instance )
|
43
|
+
|
44
|
+
instance
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spreadbase.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
$:.push( File.expand_path( "../lib", __FILE__ ) )
|
4
|
+
|
5
|
+
require "spreadbase/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "spreadbase"
|
9
|
+
s.version = SpreadBase::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = [ "Saverio Miroddi" ]
|
12
|
+
s.email = [ "saverio.pub2@gmail.com" ]
|
13
|
+
s.homepage = ""
|
14
|
+
s.summary = %q{Library for reading/writing OpenOffice Calc documents.}
|
15
|
+
s.description = %q{Library for reading/writing OpenOffice Calc documents.}
|
16
|
+
|
17
|
+
s.add_runtime_dependency "zipruby", "~>0.3.6"
|
18
|
+
s.add_development_dependency "rspec", "~>2.9.0"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split( "\n" )
|
21
|
+
s.test_files = `git ls-files -- {spec,temp,utils}/*`.split( "\n" )
|
22
|
+
s.executables = []
|
23
|
+
s.require_paths = [ "lib" ]
|
24
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
=begin
|
5
|
+
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
6
|
+
|
7
|
+
This file is part of SpreadBase.
|
8
|
+
|
9
|
+
SpreadBase is free software: you can redistribute it and/or modify it under the
|
10
|
+
terms of the GNU Lesser General Public License as published by the Free Software
|
11
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
+
version.
|
13
|
+
|
14
|
+
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
15
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
+
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License along
|
19
|
+
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
=end
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'sqlite3'
|
24
|
+
require 'spreadbase'
|
25
|
+
|
26
|
+
def decode_cmdline_params
|
27
|
+
if [ '-h', '--help' ].include?( ARGV[ 0 ] ) || ARGV.size == 0 || ARGV.size > 1
|
28
|
+
puts "Usage: convert_sqlite_to_ods.rb <filename>"
|
29
|
+
|
30
|
+
exit
|
31
|
+
else
|
32
|
+
ARGV[ 0 ]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_destination_filename( source_filename )
|
37
|
+
"#{ source_filename }.ods"
|
38
|
+
end
|
39
|
+
|
40
|
+
def with_database( filename, &block )
|
41
|
+
@db = SQLite3::Database.new( filename )
|
42
|
+
@db.type_translation = true
|
43
|
+
@db.extend( SQLite3::Pragmas )
|
44
|
+
|
45
|
+
yield
|
46
|
+
ensure
|
47
|
+
@db.close if @db
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_spreadsheet( filename )
|
51
|
+
@spreadsheet = SpreadBase::Document.new( filename )
|
52
|
+
|
53
|
+
yield
|
54
|
+
ensure
|
55
|
+
@spreadsheet.save if @spreadsheet
|
56
|
+
end
|
57
|
+
|
58
|
+
def find_tables
|
59
|
+
sql = "
|
60
|
+
SELECT name
|
61
|
+
FROM sqlite_master
|
62
|
+
WHERE type = 'table'
|
63
|
+
"
|
64
|
+
|
65
|
+
@db.execute( sql ).map( &:first ) - [ 'sqlite_sequence' ]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Sample:
|
69
|
+
#
|
70
|
+
# {
|
71
|
+
# "cid" => 3,
|
72
|
+
# "name" => "title_en",
|
73
|
+
# "type" => "TEXT",
|
74
|
+
# "notnull" => 0,
|
75
|
+
# "dflt_value" => nil,
|
76
|
+
# "pk" => 0
|
77
|
+
# },
|
78
|
+
#
|
79
|
+
def find_table_columns( table )
|
80
|
+
raw_data = @db.table_info( table )
|
81
|
+
|
82
|
+
raw_data.map { | column_data | column_data[ 'name' ] }
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_destination_table( table_name, columns )
|
86
|
+
table = SpreadBase::Table.new( table_name )
|
87
|
+
|
88
|
+
@spreadsheet.tables << table
|
89
|
+
|
90
|
+
table
|
91
|
+
end
|
92
|
+
|
93
|
+
def select_all_rows( table )
|
94
|
+
sql = "SELECT * FROM #{ table }"
|
95
|
+
|
96
|
+
@db.execute( sql )
|
97
|
+
end
|
98
|
+
|
99
|
+
def insert_row_into_destination( destination_table, row )
|
100
|
+
# row = row.map do | value |
|
101
|
+
# if value.is_a?( String )
|
102
|
+
# begin
|
103
|
+
# value.encode( 'UTF-8' )
|
104
|
+
|
105
|
+
# value
|
106
|
+
# rescue
|
107
|
+
# puts "#{ value.inspect } => #{ $! }"
|
108
|
+
|
109
|
+
# value.force_encoding( 'UTF-8' )
|
110
|
+
# end
|
111
|
+
# else
|
112
|
+
# value
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
|
116
|
+
# holy crap it's really easy to work with SB. kudos to myself.
|
117
|
+
#
|
118
|
+
destination_table.append_row( row )
|
119
|
+
end
|
120
|
+
|
121
|
+
# +options+:
|
122
|
+
# +insert_headers+:: (true) insert the column names as headers
|
123
|
+
#
|
124
|
+
def convert_sqlite_to_ods( source_filename, options={} )
|
125
|
+
insert_headers = ! options.has_key?( :insert_headers ) || options[ :insert_headers ]
|
126
|
+
|
127
|
+
destination_filename = generate_destination_filename( source_filename )
|
128
|
+
|
129
|
+
with_database( source_filename ) do
|
130
|
+
with_spreadsheet( destination_filename ) do
|
131
|
+
tables = find_tables
|
132
|
+
|
133
|
+
tables.each do | table |
|
134
|
+
columns = find_table_columns( table )
|
135
|
+
|
136
|
+
destination_table = create_destination_table( table, columns )
|
137
|
+
|
138
|
+
insert_row_into_destination( destination_table, columns ) if insert_headers
|
139
|
+
|
140
|
+
value_rows = select_all_rows( table )
|
141
|
+
|
142
|
+
value_rows.each do | row |
|
143
|
+
insert_row_into_destination( destination_table, row )
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if __FILE__ == $0
|
151
|
+
filename = decode_cmdline_params
|
152
|
+
|
153
|
+
convert_sqlite_to_ods( filename )
|
154
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
=begin
|
5
|
+
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
6
|
+
|
7
|
+
This file is part of SpreadBase.
|
8
|
+
|
9
|
+
SpreadBase is free software: you can redistribute it and/or modify it under the
|
10
|
+
terms of the GNU Lesser General Public License as published by the Free Software
|
11
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
+
version.
|
13
|
+
|
14
|
+
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
15
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
+
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License along
|
19
|
+
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
=end
|
21
|
+
|
22
|
+
require 'rexml/document'
|
23
|
+
|
24
|
+
def pretty_print( file_path, output=$stdout )
|
25
|
+
xml_str = IO.read( file_path )
|
26
|
+
|
27
|
+
root = REXML::Document.new( xml_str )
|
28
|
+
|
29
|
+
xml_formatter = REXML::Formatters::Pretty.new
|
30
|
+
xml_formatter.compact = true
|
31
|
+
xml_formatter.write( root, output )
|
32
|
+
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def prettify_file( file_path )
|
37
|
+
File.open( file_path, 'r+' ) do | file |
|
38
|
+
pretty_print( file_path, file )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if __FILE__ == $0
|
43
|
+
file_path = ARGV[ 0 ] || raise( "Usage: prettify_file.rb <file>" )
|
44
|
+
|
45
|
+
prettify_file( file_path )
|
46
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
=begin
|
5
|
+
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
6
|
+
|
7
|
+
This file is part of SpreadBase.
|
8
|
+
|
9
|
+
SpreadBase is free software: you can redistribute it and/or modify it under the
|
10
|
+
terms of the GNU Lesser General Public License as published by the Free Software
|
11
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
+
version.
|
13
|
+
|
14
|
+
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
15
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
+
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License along
|
19
|
+
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
=end
|
21
|
+
|
22
|
+
require File.expand_path( '../utils_helpers', __FILE__ )
|
23
|
+
|
24
|
+
include UtilsHelpers
|
25
|
+
|
26
|
+
def test_ods_folder( folder_path )
|
27
|
+
with_tempfile do | temp_file |
|
28
|
+
relative_compress_to_zip( folder_path, :zip_filename => temp_file.path )
|
29
|
+
|
30
|
+
`openoffice.org3 #{ temp_file.path }`
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Not sure if 'folder' is an accepted name in the linux world.
|
35
|
+
#
|
36
|
+
if __FILE__ == $0
|
37
|
+
folder_path = ARGV[ 0 ] || raise( "Usage: test_ods_folder.rb <folder>" )
|
38
|
+
|
39
|
+
test_ods_folder( folder_path )
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
=begin
|
5
|
+
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
6
|
+
|
7
|
+
This file is part of SpreadBase.
|
8
|
+
|
9
|
+
SpreadBase is free software: you can redistribute it and/or modify it under the
|
10
|
+
terms of the GNU Lesser General Public License as published by the Free Software
|
11
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
+
version.
|
13
|
+
|
14
|
+
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
15
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
+
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License along
|
19
|
+
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
=end
|
21
|
+
|
22
|
+
require File.expand_path( '../../lib/spreadbase', __FILE__ )
|
23
|
+
|
24
|
+
def test_recoding_file( file_path )
|
25
|
+
destination_file_path = file_path.sub( /\.ods$/, '.2.ods' )
|
26
|
+
|
27
|
+
document = SpreadBase::Document.new( file_path )
|
28
|
+
document.document_path = destination_file_path
|
29
|
+
document.save( :prettify => true )
|
30
|
+
|
31
|
+
`openoffice.org3 #{ destination_file_path }`
|
32
|
+
end
|
33
|
+
|
34
|
+
if __FILE__ == $0
|
35
|
+
file_path = ARGV[ 0 ] || raise( "Usage: test_recoding_file.rb <file>" )
|
36
|
+
|
37
|
+
test_recoding_file( file_path )
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
=begin
|
5
|
+
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
6
|
+
|
7
|
+
This file is part of SpreadBase.
|
8
|
+
|
9
|
+
SpreadBase is free software: you can redistribute it and/or modify it under the
|
10
|
+
terms of the GNU Lesser General Public License as published by the Free Software
|
11
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
+
version.
|
13
|
+
|
14
|
+
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
15
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
+
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License along
|
19
|
+
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
=end
|
21
|
+
|
22
|
+
require File.expand_path( '../../lib/spreadbase', __FILE__ )
|
23
|
+
require File.expand_path( '../utils_helpers', __FILE__ )
|
24
|
+
|
25
|
+
include UtilsHelpers
|
26
|
+
|
27
|
+
def test_recoding_from_content( file_path )
|
28
|
+
content_xml_data = IO.read( file_path )
|
29
|
+
document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml( content_xml_data )
|
30
|
+
|
31
|
+
with_tempfile do | temp_file |
|
32
|
+
document.document_path = temp_file.path
|
33
|
+
document.save( :prettify => true )
|
34
|
+
|
35
|
+
`openoffice.org3 #{ temp_file.path }`
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if __FILE__ == $0
|
40
|
+
file_path = ARGV[ 0 ] || raise( "Usage: test_recoding_from_content.rb <file>" )
|
41
|
+
|
42
|
+
test_recoding_from_content( file_path )
|
43
|
+
end
|