flattendb 0.1.0 → 0.1.1

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/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to flattendb version 0.1.0
5
+ This documentation refers to flattendb version 0.1.1
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ begin
14
14
  :summary => %q{Flatten relational databases.},
15
15
  :author => %q{Jens Wille},
16
16
  :email => %q{jens.wille@uni-koeln.de},
17
- :dependencies => %w[libxml-ruby builder ruby-nuggets] << ['athena', '>= 0.1.5']
17
+ :dependencies => %w[libxml-ruby builder] << ['ruby-nuggets', '>= 0.7.3'] << ['athena', '>= 0.1.5']
18
18
  }
19
19
  }}
20
20
  rescue LoadError => err
data/bin/flattendb CHANGED
@@ -29,9 +29,4 @@
29
29
  #++
30
30
 
31
31
  require 'flattendb/cli'
32
-
33
- begin
34
- FlattenDB::CLI.execute($flattendb_type, ARGV, STDIN, STDOUT, STDERR)
35
- rescue ArgumentError => err
36
- abort err
37
- end
32
+ FlattenDB::CLI.execute($flattendb)
data/bin/flattendb.mdb CHANGED
@@ -1,7 +1,6 @@
1
1
  #! /usr/bin/ruby
2
2
 
3
- ext = File.extname(__FILE__)
4
- $flattendb_type = ext.sub(/\A\./, '')
3
+ $flattendb = (ext = File.extname(__FILE__)).sub(/\A\./, '')
5
4
  load __FILE__.sub(/#{Regexp.escape(ext)}\z/, '')
6
5
 
7
6
  # vim:ft=ruby
data/bin/flattendb.mysql CHANGED
@@ -1,7 +1,6 @@
1
1
  #! /usr/bin/ruby
2
2
 
3
- ext = File.extname(__FILE__)
4
- $flattendb_type = ext.sub(/\A\./, '')
3
+ $flattendb = (ext = File.extname(__FILE__)).sub(/\A\./, '')
5
4
  load __FILE__.sub(/#{Regexp.escape(ext)}\z/, '')
6
5
 
7
6
  # vim:ft=ruby
data/lib/flattendb/cli.rb CHANGED
@@ -26,23 +26,12 @@
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- require 'optparse'
30
- require 'yaml'
31
- require 'zlib'
29
+ require 'nuggets/util/cli'
32
30
  require 'flattendb'
33
31
 
34
32
  module FlattenDB
35
33
 
36
- class CLI
37
-
38
- USAGE = "Usage: #{$0} [-h|--help] [options]"
39
-
40
- DEFAULTS = {
41
- :input => '-',
42
- :inputs => [],
43
- :output => '-',
44
- :config => 'config.yaml'
45
- }
34
+ class CLI < ::Util::CLI
46
35
 
47
36
  TYPES = {
48
37
  :mysql => {
@@ -64,31 +53,30 @@ module FlattenDB
64
53
  }
65
54
  }
66
55
 
67
- def self.execute(type = nil, *args)
68
- new(type).execute(*args)
69
- end
70
-
71
- attr_reader :type, :options, :config, :defaults
72
- attr_reader :stdin, :stdout, :stderr
56
+ class << self
73
57
 
74
- def initialize(type = nil, defaults = DEFAULTS)
75
- @defaults = defaults
58
+ def defaults
59
+ super.merge(
60
+ :input => '-',
61
+ :inputs => [],
62
+ :output => '-',
63
+ :config => 'config.yaml'
64
+ )
65
+ end
76
66
 
77
- reset(type)
67
+ def execute(type = nil, *args)
68
+ new(nil, type).execute(*args)
69
+ end
78
70
 
79
- # prevent backtrace on ^C
80
- trap(:INT) { exit 130 }
81
71
  end
82
72
 
83
- def execute(arguments = [], *inouterr)
84
- reset(type, *inouterr)
85
-
86
- parse_options(arguments, defaults)
73
+ attr_reader :type
87
74
 
75
+ def run(arguments)
88
76
  if type
89
77
  require "flattendb/types/#{type}"
90
78
  else
91
- abort 'Database type is required!'
79
+ quit 'Database type is required!'
92
80
  end
93
81
 
94
82
  options[:input] = if type == :mdb
@@ -108,78 +96,44 @@ module FlattenDB
108
96
  )
109
97
  end
110
98
 
111
- abort USAGE unless arguments.empty?
99
+ quit unless arguments.empty?
112
100
 
113
101
  options[:output] = open_file_or_std(options[:output], true)
114
102
 
115
103
  FlattenDB[type].to_flat!(options)
116
- ensure
117
- options[:output].close if options[:output].is_a?(Zlib::GzipWriter)
118
- end
119
-
120
- def reset(type = nil, stdin = STDIN, stdout = STDOUT, stderr = STDERR)
121
- @stdin, @stdout, @stderr = stdin, stdout, stderr
122
- self.type, @options, @config = type, {}, {}
123
104
  end
124
105
 
125
106
  private
126
107
 
108
+ def init(type)
109
+ super()
110
+ self.type = type
111
+ end
112
+
127
113
  def type=(type)
128
114
  if type
129
115
  @type = type.to_s.downcase.to_sym
130
- abort "Database type not supported: #{type}" unless TYPES.has_key?(@type)
116
+ quit "Database type not supported: #{type}" unless TYPES.has_key?(@type)
131
117
  else
132
118
  @type = nil
133
119
  end
134
120
  end
135
121
 
136
- def open_file_or_std(file, write = false)
137
- if file == '-'
138
- write ? stdout : stdin
139
- else
140
- gz = file =~ /\.gz\z/i
141
-
142
- if write
143
- gz ? Zlib::GzipWriter.open(file) : File.open(file, 'w')
144
- else
145
- abort "No such file: #{file}" unless File.readable?(file)
146
- (gz ? Zlib::GzipReader : File).open(file)
147
- end
148
- end
149
- end
150
-
151
- def warn(msg, output = stderr)
152
- output.puts(msg)
153
- end
154
-
155
- def abort(msg = nil, status = 1, output = stderr)
156
- warn(msg, output) if msg
157
- exit(status)
158
- end
159
-
160
- def parse_options(arguments, defaults)
161
- option_parser(defaults).parse!(arguments)
162
-
163
- config_file = options[:config] || defaults[:config]
164
- @config = YAML.load_file(config_file) if File.readable?(config_file)
165
-
166
- [config, defaults].each { |hash| hash.each { |key, value| options[key] ||= value } }
122
+ def option_parser
123
+ @sorted_types = TYPES.keys.sort_by { |t| t.to_s }
124
+ super
125
+ ensure
126
+ remove_instance_variable(:@sorted_types)
167
127
  end
168
128
 
169
- def option_parser(defaults)
170
- sorted_types = TYPES.keys.sort_by { |t| t.to_s }
171
-
172
- OptionParser.new { |opts|
173
- opts.banner = USAGE
174
-
129
+ def pre_opts(opts)
175
130
  if type
176
131
  opts.separator ''
177
132
  opts.separator "TYPE = #{type} (#{TYPES[type][:title]})"
178
133
  end
134
+ end
179
135
 
180
- opts.separator ''
181
- opts.separator 'Options:'
182
-
136
+ def opts(opts)
183
137
  unless type
184
138
  opts.on('-t', '--type TYPE', 'Type of database [REQUIRED]') { |type|
185
139
  self.type = type
@@ -188,39 +142,29 @@ module FlattenDB
188
142
  opts.separator ''
189
143
  end
190
144
 
191
- opts.on('-i', '--input FILE', 'Input file(s) [Default: STDIN]') { |input|
192
- (options[:inputs] ||= []) << input
193
- }
194
-
195
- opts.on('-o', '--output FILE', 'Output file (flat XML) [Default: STDOUT]') { |output|
196
- options[:output] = output
197
- }
198
-
199
- opts.on('-c', '--config FILE', "Configuration file (YAML) [Default: #{defaults[:config]}#{' (currently not present)' unless File.readable?(defaults[:config])}]") { |config|
200
- options[:config] = config
201
- }
202
-
203
- opts.separator ''
204
- opts.separator 'Database-specific options:'
145
+ opts.on('-i', '--input FILE', 'Input file(s) [Default: STDIN]') { |input|
146
+ (options[:inputs] ||= []) << input
147
+ }
205
148
 
206
- type ? type_options(opts) : sorted_types.each { |t| type_options(opts, true, t) }
149
+ opts.on('-o', '--output FILE', 'Output file (flat XML) [Default: STDOUT]') { |output|
150
+ options[:output] = output
151
+ }
207
152
 
208
- opts.separator ''
209
- opts.separator 'Generic options:'
153
+ opts.on('-c', '--config FILE', "Configuration file (YAML) [Default: #{defaults[:config]}#{' (currently not present)' unless File.readable?(defaults[:config])}]") { |config|
154
+ options[:config] = config
155
+ }
210
156
 
211
- opts.on('-h', '--help', 'Print this help message and exit') {
212
- abort opts.to_s
213
- }
157
+ opts.separator ''
158
+ opts.separator 'Database-specific options:'
214
159
 
215
- opts.on('--version', 'Print program version and exit') {
216
- abort "#{File.basename($0)} v#{FlattenDB::VERSION}"
217
- }
160
+ type ? type_options(opts) : @sorted_types.each { |t| type_options(opts, true, t) }
161
+ end
218
162
 
163
+ def post_opts(opts)
219
164
  unless type
220
165
  opts.separator ''
221
- opts.separator "Supported database types: #{sorted_types.map { |t| "#{t} (#{TYPES[t][:title]})" }.join(', ')}."
166
+ opts.separator "Supported database types: #{@sorted_types.map { |t| "#{t} (#{TYPES[t][:title]})" }.join(', ')}."
222
167
  end
223
- }
224
168
  end
225
169
 
226
170
  def type_options(opts, heading = false, type = type)
@@ -47,7 +47,11 @@ module FlattenDB
47
47
  abort "Command not found: #{cmd}! Please install `mdbtools' first."
48
48
  }
49
49
 
50
- # ...
50
+ databases.each { |database|
51
+ %x{mdb-tables -1 #{database}}.split($/).each { |table|
52
+ FasterCSV.parse(%x{mdb-export #{database} #{table}}, :headers => true)
53
+ }
54
+ }
51
55
  end
52
56
 
53
57
  def flatten!(options = {}, builder_options = {})
@@ -4,7 +4,7 @@ module FlattenDB
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 0
7
+ TINY = 1
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flattendb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-12 00:00:00 Z
18
+ date: 2011-07-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: libxml-ruby
@@ -53,10 +53,12 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- hash: 3
56
+ hash: 5
57
57
  segments:
58
58
  - 0
59
- version: "0"
59
+ - 7
60
+ - 3
61
+ version: 0.7.3
60
62
  type: :runtime
61
63
  version_requirements: *id003
62
64
  - !ruby/object:Gem::Dependency
@@ -113,10 +115,10 @@ post_install_message:
113
115
  rdoc_options:
114
116
  - --charset
115
117
  - UTF-8
116
- - --title
117
- - flattendb Application documentation (v0.1.0)
118
118
  - --main
119
119
  - README
120
+ - --title
121
+ - flattendb Application documentation (v0.1.1)
120
122
  - --line-numbers
121
123
  - --all
122
124
  require_paths: