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.
40 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 |
# File 'lib/sqlite2dbf.rb', line 40 def initialize(*args) = ArgParser::parse(args) @config = Configuration.instance() @config.set() 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 = @config.target if @config.target if(@config.out) dbf_file = @config.out << File::Separator << @config.name end dbf_file ||= File.dirname(sqlite_file) << File::Separator << File.basename(sqlite_file, '.*') msg = nil 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 if(!msg) @log.debug('will transform ' << sqlite_file << ' to ' << dbf_file.to_s << '.dbf') transform(db, dbf_file) else 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 |