/usr/share/yokadi/update/dump.py is in yokadi 0.14.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 | #!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Generates a data-only sqlite dump, with insert statements including column
names.
@author: Aurélien Gâteau <aurelien.gateau@free.fr>
@license: GPL v3 or newer
"""
import os
import re
import subprocess
import sys
try:
# Seems to be the Python 2.6 way to get sqlite
from sqlite3 import dbapi2 as sqlite
except ImportError:
from pysqlite2 import dbapi2 as sqlite
def getTableList(cx):
cursor = cx.cursor()
cursor.execute("select name from sqlite_master where type='table'")
return [x[0] for x in cursor.fetchall()]
def getTableColumnList(cx, table):
cursor = cx.cursor()
cursor.execute("select * from %s" % table)
return [x[0] for x in cursor.description]
def dumpTable(cx, dbFileName, table, fl):
rx = re.compile(u"^insert into %s values" % table, re.IGNORECASE)
columnList = getTableColumnList(cx, table)
newText = u"insert into %s(%s) values" % (table, ",".join(columnList))
child = subprocess.Popen(["sqlite3", dbFileName], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
child.stdin.write(".mode insert %s\nselect * from %s;\n" % (table, table))
child.stdin.close()
for line in child.stdout.readlines():
line = unicode(line, "utf-8")
line = rx.sub(newText, line)
fl.write(line.encode("utf-8"))
def dumpDatabase(dbFileName, dumpFile):
cx = sqlite.connect(os.path.abspath(dbFileName))
for table in getTableList(cx):
dumpTable(cx, dbFileName, table, dumpFile)
def main():
dbFileName = sys.argv[1]
dumpFileName = sys.argv[2]
dumpFile = file(dumpFileName, "w")
dumpDatabase(dbFileName, dumpFile)
if __name__ == "__main__":
main()
# vi: ts=4 sw=4 et
|