More refactoring for an Issue #254

This commit is contained in:
Miroslav Stampar 2012-11-28 11:16:00 +01:00
parent 87a92ab330
commit 5bf5b95588

View File

@ -333,7 +333,7 @@ class Dump:
if conf.dumpFormat == DUMP_FORMAT.SQLITE: if conf.dumpFormat == DUMP_FORMAT.SQLITE:
replication = Replication("%s%s%s.sqlite3" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db))) replication = Replication("%s%s%s.sqlite3" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db)))
else: elif conf.dumpFormat == DUMP_FORMAT.CSV:
dumpDbPath = "%s%s%s" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db)) dumpDbPath = "%s%s%s" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db))
if not os.path.isdir(dumpDbPath): if not os.path.isdir(dumpDbPath):
@ -407,7 +407,7 @@ class Dump:
self._write("| %s%s" % (column, blank), newline=False) self._write("| %s%s" % (column, blank), newline=False)
if conf.dumpFormat != DUMP_FORMAT.SQLITE: if conf.dumpFormat == DUMP_FORMAT.CSV:
if field == fields: if field == fields:
dataToDumpFile(dumpFP, "%s" % safeCSValue(column)) dataToDumpFile(dumpFP, "%s" % safeCSValue(column))
else: else:
@ -417,10 +417,10 @@ class Dump:
self._write("|\n%s" % separator) self._write("|\n%s" % separator)
if conf.dumpFormat != DUMP_FORMAT.SQLITE: if conf.dumpFormat == DUMP_FORMAT.CSV:
dataToDumpFile(dumpFP, "\n") dataToDumpFile(dumpFP, "\n")
if conf.dumpFormat == DUMP_FORMAT.SQLITE: elif conf.dumpFormat == DUMP_FORMAT.SQLITE:
rtable.beginTransaction() rtable.beginTransaction()
if count > TRIM_STDOUT_DUMP_SIZE: if count > TRIM_STDOUT_DUMP_SIZE:
@ -452,7 +452,7 @@ class Dump:
blank = " " * (maxlength - len(value)) blank = " " * (maxlength - len(value))
self._write("| %s%s" % (value, blank), newline=False, console=console) self._write("| %s%s" % (value, blank), newline=False, console=console)
if conf.dumpFormat != DUMP_FORMAT.SQLITE: if conf.dumpFormat == DUMP_FORMAT.CSV:
if field == fields: if field == fields:
dataToDumpFile(dumpFP, "%s" % safeCSValue(value)) dataToDumpFile(dumpFP, "%s" % safeCSValue(value))
else: else:
@ -465,19 +465,18 @@ class Dump:
rtable.insert(values) rtable.insert(values)
except sqlmapValueException: except sqlmapValueException:
pass pass
elif conf.dumpFormat == DUMP_FORMAT.CSV:
dataToDumpFile(dumpFP, "\n")
self._write("|", console=console) self._write("|", console=console)
if conf.dumpFormat != DUMP_FORMAT.SQLITE:
dataToDumpFile(dumpFP, "\n")
self._write("%s\n" % separator) self._write("%s\n" % separator)
if conf.dumpFormat == DUMP_FORMAT.SQLITE: if conf.dumpFormat == DUMP_FORMAT.SQLITE:
rtable.endTransaction() rtable.endTransaction()
logger.info("table '%s.%s' dumped to sqlite3 database '%s'" % (db, table, replication.dbpath)) logger.info("table '%s.%s' dumped to sqlite3 database '%s'" % (db, table, replication.dbpath))
else: elif conf.dumpFormat == DUMP_FORMAT.CSV:
dataToDumpFile(dumpFP, "\n") dataToDumpFile(dumpFP, "\n")
dumpFP.close() dumpFP.close()
logger.info("table '%s.%s' dumped to CSV file '%s'" % (db, table, dumpFileName)) logger.info("table '%s.%s' dumped to CSV file '%s'" % (db, table, dumpFileName))