sqlite2dbf 0.2 → 0.2.2
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.
- checksums.yaml +4 -4
- data/lib/argparser.rb +27 -25
- data/lib/config +1 -1
- data/lib/constants.rb +1 -1
- data/lib/log.conf +0 -1
- data/lib/mapping.rb +2 -2
- data/lib/sqlite2dbf.rb +12 -8
- data/lib/translating.rb +11 -0
- data/lib/translations +2 -2
- data/sqlite2dbf.gemspec +4 -1
- metadata +46 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b3185c1faa5124f320a012e00126f27bf98959f
|
4
|
+
data.tar.gz: 916a050f7b7cf55108f73f2871aff56ab6149fd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00850c4fe8bf96a5e21f0d8fb4c809cb9909ab30ef3c132b20166a9ac6eaf726f28018d47f486e244039e537729e20a4b00b13b4b066327a00ac1f985d0eb194'
|
7
|
+
data.tar.gz: 8a8a6fda0faef19b4be0ba93927ce2066a1589b99c64381b3549253b0c5f14ba6f84ec174399593a70c741622032d0e20d64d3ff1465b199cae17ddb6c65a6a4
|
data/lib/argparser.rb
CHANGED
@@ -33,13 +33,15 @@ class ArgParser
|
|
33
33
|
self.extend(Logging)
|
34
34
|
self.extend(Translating)
|
35
35
|
@@log = init_logger()
|
36
|
-
|
36
|
+
|
37
37
|
# Returns a structure describing the options.
|
38
38
|
#
|
39
39
|
def self.parse(args)
|
40
|
-
# The options specified on the command line will be collected in
|
41
|
-
#
|
42
|
-
|
40
|
+
# The options specified on the command line will be collected in
|
41
|
+
# <b>options</b>. No defaults. Most options are optional and do not
|
42
|
+
# have to be set at all.
|
43
|
+
# The others must be named for each transformation or be set in the
|
44
|
+
# configuration-file.
|
43
45
|
options = OpenStruct.new
|
44
46
|
|
45
47
|
op = OptionParser.new do |opts|
|
@@ -49,36 +51,36 @@ class ArgParser
|
|
49
51
|
opts.separator trl("Specific options") << ':'
|
50
52
|
|
51
53
|
opts.on('-' << trl("s"), '--' << trl("source [PATH]"), trl( "SQLite-file to read.")) do |source|
|
52
|
-
|
54
|
+
options.source = source
|
53
55
|
end
|
54
56
|
|
55
57
|
opts.on('-' << trl('c'), '--' << trl("config [PATH]"), trl('Configuration file for this transformation')) do |config|
|
56
|
-
|
58
|
+
options.config = config
|
57
59
|
end
|
58
60
|
|
59
61
|
opts.on('-' << trl('n'), '--' << trl("name [TABLE]"), trl('The name of the table from the SQLite-database to convert')) do |name|
|
60
|
-
|
62
|
+
options.name = name
|
61
63
|
end
|
62
64
|
|
63
65
|
opts.on('-' << trl("t"), '--' << trl("target [PATH]"), trl( "Path to the dBase-file to be written.")) do |target|
|
64
|
-
|
66
|
+
options.target = target
|
65
67
|
end
|
66
68
|
|
67
69
|
opts.on('-' << trl("l"), '--' << trl("list"), trl( "Show the list of available tables and exit")) do |target|
|
68
|
-
|
70
|
+
options.list = true
|
69
71
|
end
|
70
72
|
|
71
73
|
opts.on('-' << trl('o'), '--' << trl("out [PATH]"), trl('Use the table-name as file-name for the DBF-result, store output in PATH')) do |path|
|
72
|
-
|
73
|
-
|
74
|
+
options.name_like_table = true
|
75
|
+
options.out = path
|
74
76
|
end
|
75
77
|
|
76
78
|
opts.on('--' << trl("time [list]"), trl( "Fields (table-columns) which shall be handled as timestamp values.")) do |list|
|
77
|
-
|
79
|
+
options.time = list.gsub(/[,;]/, '').split
|
78
80
|
end
|
79
81
|
|
80
82
|
opts.on('--' << trl("date [list]"), trl( "Fields (table-columns) which shall be handled as date-time values.")) do |list|
|
81
|
-
|
83
|
+
options.datetime = list.gsub(/[,;]/, '').split
|
82
84
|
end
|
83
85
|
|
84
86
|
=begin
|
@@ -88,13 +90,13 @@ class ArgParser
|
|
88
90
|
# much management.
|
89
91
|
|
90
92
|
opts.on("-c", "--config [CONFIG FILE]",
|
91
|
-
|
92
|
-
|
93
|
-
|
93
|
+
"Read alternative configuration from this file") do |conf|
|
94
|
+
$LOG.debug("config-file should be #{conf}") if $LOG
|
95
|
+
options.config = File.expand_path(conf )
|
94
96
|
end
|
95
97
|
opts.on("-g", "--generic [CONFIG FILE]",
|
96
|
-
|
97
|
-
|
98
|
+
"Write generic configuration options to this file") do |file|
|
99
|
+
options.generic = File.expand_path(file )
|
98
100
|
end
|
99
101
|
=end
|
100
102
|
opts.separator ""
|
@@ -103,20 +105,20 @@ end
|
|
103
105
|
# No argument, shows at tail. This will print an options summary.
|
104
106
|
#
|
105
107
|
opts.on_tail(trl("-d"), trl("--debug"), trl("Show debug-messages") ) do
|
106
|
-
|
107
|
-
|
108
|
+
options.debug = true
|
109
|
+
@@log.level = Logger::DEBUG
|
108
110
|
end
|
109
111
|
|
110
112
|
|
111
113
|
opts.on_tail(trl("-h"), trl("--help"), trl("Show this message") ) do
|
112
|
-
|
113
|
-
|
114
|
+
puts opts
|
115
|
+
exit true
|
114
116
|
end
|
115
117
|
|
116
118
|
opts.on_tail(trl("-v"), trl("--version"), trl("Show version and program information") ) do
|
117
|
-
|
118
|
-
|
119
|
-
|
119
|
+
puts "\t#{$APPNAME}"
|
120
|
+
puts "\t© #{$YEARS}, <#{$AUTHORS.join(', ')}>"
|
121
|
+
exit true
|
120
122
|
end
|
121
123
|
end
|
122
124
|
begin
|
data/lib/config
CHANGED
data/lib/constants.rb
CHANGED
data/lib/log.conf
CHANGED
@@ -35,7 +35,6 @@ warn = Logger::WARN
|
|
35
35
|
unknown = Logger::UNKNOWN
|
36
36
|
{
|
37
37
|
# <---------------- to here !
|
38
|
-
|
39
38
|
# Enter your settings here, but take into consideration that not all
|
40
39
|
# the named classes will really produce readable output. Well, you can
|
41
40
|
# always try... Either name just the log-level or make the log-level
|
data/lib/mapping.rb
CHANGED
@@ -52,8 +52,8 @@ class Mapping
|
|
52
52
|
}
|
53
53
|
|
54
54
|
# Constructor
|
55
|
-
# Creates a mapping for the table of name
|
56
|
-
#
|
55
|
+
# Creates a mapping for the table of name config.name and basedon the
|
56
|
+
# table_info.
|
57
57
|
def initialize config, table_info, content
|
58
58
|
init_logger()
|
59
59
|
|
data/lib/sqlite2dbf.rb
CHANGED
@@ -73,24 +73,28 @@ class SQLite2DBF
|
|
73
73
|
exit false
|
74
74
|
end
|
75
75
|
|
76
|
+
# dbf_file is eather named explicitly
|
76
77
|
dbf_file = @config.target if @config.target
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
dbf_file ||= File.dirname(sqlite_file) << File::Separator << File.basename(sqlite_file, '.*')
|
78
|
+
# .., derived from the table-name
|
79
|
+
dbf_file = @config.out << File::Separator << @config.name if(@config.out)
|
80
|
+
# .., or identical with the original sqlite-file, minus extension, plus dbf
|
81
|
+
dbf_file ||= File.dirname(sqlite_file) << File::Separator << File.basename(sqlite_file, '.*') << '.dbf'
|
81
82
|
|
82
83
|
msg = nil
|
83
84
|
|
85
|
+
# check if dbf_file can be used
|
84
86
|
if(File.exist?(dbf_file))
|
85
87
|
msg = File_Checking.file_check(dbf_file, :file, :writable)
|
86
88
|
elsif(File.exist?(File.dirname(dbf_file)))
|
87
89
|
msg = File_Checking.file_check(File.dirname(dbf_file), :directory, :writable)
|
88
90
|
end
|
89
91
|
|
92
|
+
# then do it
|
90
93
|
if(!msg)
|
91
|
-
@log.debug('will transform ' << sqlite_file << ' to ' << dbf_file.to_s
|
94
|
+
@log.debug('will transform ' << sqlite_file << ' to ' << dbf_file.to_s)
|
92
95
|
transform(db, dbf_file)
|
93
96
|
else
|
97
|
+
# or not
|
94
98
|
msg = trl("ERROR! Unsuitable file") << " : %s" %msg
|
95
99
|
@log.error(msg)
|
96
100
|
exit false
|
@@ -124,20 +128,20 @@ class SQLite2DBF
|
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
131
|
+
# create a date-value from value
|
127
132
|
def date(db, value)
|
128
133
|
dbf_value = db.execute("select strftime('%Y-%m-%d %H:%M:%S', " << value.to_s << ", 'unixepoch')").join
|
134
|
+
# ... or not.
|
129
135
|
@log.warn(trl("ATTN! SQLite2DBF cannot convert the date-value %s into DBF-compatible format.") %value.to_s) if dbf_value.start_with?('-')
|
130
136
|
dbf_value = db.execute("select strftime('%s', " << value.to_s << ")").join if dbf_value.start_with?('-')
|
131
137
|
end
|
132
138
|
|
139
|
+
# create a time-vaue from value
|
133
140
|
def time(db, value)
|
134
141
|
db.execute("select strftime('%s', " << value.to_s << ", 'unixepoch')").join
|
135
142
|
end
|
136
143
|
|
137
|
-
|
138
|
-
|
139
144
|
def transform(db, dbf_file)
|
140
|
-
|
141
145
|
begin
|
142
146
|
tname = @config.name
|
143
147
|
table_info = db.table_info(tname)
|
data/lib/translating.rb
CHANGED
@@ -35,15 +35,23 @@ require_relative 'logging'
|
|
35
35
|
=end
|
36
36
|
module Translating
|
37
37
|
self.extend(Logging)
|
38
|
+
|
39
|
+
# intitialize class variabes (static attributes)
|
40
|
+
|
38
41
|
@@log = init_logger(STDOUT)
|
39
42
|
# There are better ways to extend a translated
|
40
43
|
# string, but I keep the 'wild-card' for
|
41
44
|
# historical reasons.
|
45
|
+
# TODO: get rid of this crap!
|
42
46
|
@@awild = 'XX'
|
43
47
|
|
44
48
|
@@lang = nil
|
49
|
+
# TODO: reflect about this. The possibility to write a LANG-file is
|
50
|
+
# okay, sometimes. Most of the time it is not.
|
45
51
|
@@lang_file = format("%s%s", RD, 'LANG')
|
52
|
+
|
46
53
|
@@tr = YAML::load_file("#{RD}translations")
|
54
|
+
|
47
55
|
# find the current language-setting and return it.
|
48
56
|
def self.language()
|
49
57
|
if @@lang == nil
|
@@ -62,6 +70,9 @@ module Translating
|
|
62
70
|
# The args parameter may contain replacement-text which
|
63
71
|
# will appear at the positions indicated by wildcard-characters
|
64
72
|
# in the original string.
|
73
|
+
#
|
74
|
+
# TODO: Come on! sprintf-syntax is far better than the awkward 'wildcard'.
|
75
|
+
# Just remove this crap.
|
65
76
|
def self.trl(t, *args)
|
66
77
|
|
67
78
|
@@log.debug('@tr is ' << @@tr.to_s)
|
data/lib/translations
CHANGED
@@ -29,7 +29,7 @@ Usage:
|
|
29
29
|
|
30
30
|
or %s [Common options]:
|
31
31
|
de: oder %s [Allgemeine Optionen]
|
32
|
-
fr: ou %s [Options
|
32
|
+
fr: ou %s [Options générales]
|
33
33
|
|
34
34
|
Specific options:
|
35
35
|
de: Spezielle Optionen
|
@@ -134,7 +134,7 @@ out [PATH]:
|
|
134
134
|
|
135
135
|
Common options:
|
136
136
|
de: Allgemeine Optionen
|
137
|
-
fr: Options
|
137
|
+
fr: Options générales
|
138
138
|
|
139
139
|
# program option -d (debug)
|
140
140
|
-d:
|
data/sqlite2dbf.gemspec
CHANGED
@@ -3,13 +3,16 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = $APPNAME
|
4
4
|
s.version = $VERSION
|
5
5
|
s.date = $DATE
|
6
|
-
s.summary = "Rewrite of the main-class SQLite2DBF, mappings in the new class Mappings, the configuration can be persisted. New program-options. New translations."
|
6
|
+
s.summary = "Runtime-requirements added. Rewrite of the main-class SQLite2DBF, mappings in the new class Mappings, the configuration can be persisted. New program-options. New translations."
|
7
7
|
s.description = "converts SQLite to DBase"
|
8
8
|
s.authors = $AUTHORS
|
9
9
|
s.email = $EMAIL
|
10
10
|
s.files = %w~sqlite2dbf~.collect{|f| 'bin/' << f} + %w~constants.rb mapping.rb argparser.rb sqlite2dbf.rb file_checking.rb log.conf logging.rb mapping.rb configuration.rb config translating.rb translations ~.collect{|f| 'lib/' << f} + %w~sqlite2dbf.gemspec~.collect{|f|f}
|
11
11
|
s.requirements = 'shp, sqlite3'
|
12
|
+
s.add_runtime_dependency 'shp', '~> 0.0', '>= 0.0.3'
|
13
|
+
s.add_runtime_dependency 'sqlite3', '~> 1.3', '>= 1.3.12'
|
12
14
|
s.executables = 'sqlite2dbf'
|
13
15
|
s.license = $LICENSE
|
16
|
+
s.homepage = 'https://rubygems.org/gems/sqlite2dbf'
|
14
17
|
s.required_ruby_version = '>= 2.3'
|
15
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlite2dbf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Uplawski <michael.uplawski@uplawski.eu>
|
@@ -9,7 +9,47 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-11-24 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.0.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sqlite3
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.3.12
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.12
|
13
53
|
description: converts SQLite to DBase
|
14
54
|
email: michael.uplawski@uplawski.eu
|
15
55
|
executables:
|
@@ -30,7 +70,7 @@ files:
|
|
30
70
|
- lib/translating.rb
|
31
71
|
- lib/translations
|
32
72
|
- sqlite2dbf.gemspec
|
33
|
-
homepage:
|
73
|
+
homepage: https://rubygems.org/gems/sqlite2dbf
|
34
74
|
licenses:
|
35
75
|
- GPL-3.0
|
36
76
|
metadata: {}
|
@@ -54,6 +94,7 @@ rubyforge_project:
|
|
54
94
|
rubygems_version: 2.6.8
|
55
95
|
signing_key:
|
56
96
|
specification_version: 4
|
57
|
-
summary: Rewrite of the main-class SQLite2DBF, mappings
|
58
|
-
the configuration can be persisted. New program-options.
|
97
|
+
summary: Runtime-requirements added. Rewrite of the main-class SQLite2DBF, mappings
|
98
|
+
in the new class Mappings, the configuration can be persisted. New program-options.
|
99
|
+
New translations.
|
59
100
|
test_files: []
|