Class: SQLite2DBF
- Inherits:
-
Object
- Object
- SQLite2DBF
- Includes:
- Logging, Translating
- Defined in:
- lib/sqlite2dbf.rb
Overview
The main program class. Does it.
Instance Method Summary collapse
-
#initialize(*args) ⇒ SQLite2DBF
constructor
A new instance of SQLite2DBF.
Methods included from Translating
Methods included from Logging
#init_logger, #log_level=, #log_target=
Methods included from File_Checking
Constructor Details
#initialize(*args) ⇒ SQLite2DBF
Returns a new instance of SQLite2DBF.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sqlite2dbf.rb', line 41 def initialize(*args) = ArgParser::parse(args) @config = Configuration.instance() @config.set() # Object level logger. “There can only be one!” init_logger level = (@config.debug ? Logger::DEBUG : @log.level) @log.level = level @date_fields = @config.date ? @config.date : [] @time_fields = @config.time ? @config.time : [] if(@config.source) @dbf_path = nil sqlite_file = @config.source msg = File_Checking::file_check(sqlite_file, :exist, :readable) if msg @log.error(trl("ERROR! Cannot read the source-file" ) << ": " << msg) exit false end SQLite3::Database.new(sqlite_file) do |db| tables = list(db) if(@config.list) puts "\n" << trl("Tables in the database") << ":\n\t" << tables.join("\n\t") << "\n\n" exit true elsif tables.include?(@config.name) @mapping = mapping(db) else @log.error(trl("Verify table-name! %s is not found in the database!") %(@config.name)) @log.error(trl("Tables are %s") %tables.join(', ') ) exit false end # dbf_file is eather named explicitly dbf_file = @config.target if @config.target # .., derived from the table-name dbf_file = @config.out << File::Separator << @config.name if(@config.out) # .., or identical with the original sqlite-file, minus extension, plus dbf dbf_file ||= File.dirname(sqlite_file) << File::Separator << File.basename(sqlite_file, '.*') << '.dbf' msg = nil # check if dbf_file can be used if(File.exist?(dbf_file)) msg = File_Checking.file_check(dbf_file, :file, :writable) elsif(File.exist?(File.dirname(dbf_file))) msg = File_Checking.file_check(File.dirname(dbf_file), :directory, :writable) end # then do it if(!msg) @log.debug('will transform ' << sqlite_file << ' to ' << dbf_file.to_s) transform(db, dbf_file) else # or not msg = trl("ERROR! Unsuitable file") << " : %s" %msg @log.error(msg) exit false end end else log.error trl("ERROR! Source-file is a mandatory program parameter!") log.error trl("Start this program with parameter -h or --help to see the usage-message.") end end |