2
# -*- Encoding: UTF-8 -*-
4
# Copyright (c) 2008-2009, Elián Hanisch
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
# This script is for convert old Pruebot's database to the new format that is
20
# used in Factos 0.5. It shouldn't be needed anymore once this is done, but
21
# is good reference for using Factos's classes outside the plugin scope.
28
from databases import *
32
('created_by', 'INTEGER'),
33
('created_at', 'TIMESTAMP'),
34
('edited_by', 'INTEGER'),
35
('edited_at', 'TIMESTAMP'),
37
('flags_set_by', 'INTEGER'),
38
('flags_set_at', 'TIMESTAMP'),
39
('last_request_by', 'TEXT'),
40
('last_request_at', 'TIMESTAMP'),
41
('request_count', 'INTEGER'),
46
('history_id', 'INTEGER'),
47
('edited_by', 'INTEGER'),
48
('edited_at', 'TIMESTAMP'),
54
oldTableFact = Table(oldTblFact, 'factos', tableIndex='name')
55
oldTableHist = Table(oldTblHist, 'historial', tableIndex='name')
57
tableFact = Table(objects.tblFactStruct, 'factos', tableIndex='name')
58
tableHist = Table(objects.tblHistStruct, 'historial')
59
tableUser = Table(objects.tblUserStruct, 'usuarios', tableIndex='user_id')
61
def convertAlias(values):
62
values['data'] = values['data'][7:]
63
values['flags'] = values['flags'] | objects.Fact.f['alias']
68
if __name__ == '__main__':
71
parser = optparse.OptionParser(usage='Usage: %prog old_db_file new_db_file')
72
(options, args) = parser.parse_args()
73
if not args or len(args) < 2:
77
old_filename = args[0]
78
new_filename = args[1]
80
olddb = objects.SqliteDB(old_filename, oldTableFact, oldTableHist, tableUser)
81
newdb = objects.SqliteDB(new_filename, tableFact, tableHist, tableUser)
84
# change alias to use the alias status flag, instead of the prefixed '<alias>'
85
# also change field 'fact' to 'data'
86
tables = olddb.getTables(all=tableFact.name)
89
print 'Table: %s' %table.name
90
newtable = Table(tableFact, name=table.name)
91
facts = olddb.get(table=table)
93
fact = newtable.row(fact)
94
if fact['data'].startswith('<alias>'):
95
fact = convertAlias(fact)
96
print 'Alias: %s : %s' %(fact['name'], fact['data'])
97
print 'fact: %s' %fact['name']
99
newdb.add(fact, table=newtable)
102
# change alias edits to use the alias status flag, instead of the prefixed '<alias>'
103
# also change field 'fact' to 'data'
104
tables = olddb.getTables(all=tableHist.name)
107
print 'Table: %s' %table.name
108
newtable = Table(tableHist, name=table.name)
109
facts = olddb.get(table=table)
111
fact_new = (fact[0], fact[1], fact[2], fact[3], 0, fact[4])
112
fact = newtable.row(fact_new)
113
if fact['data'].startswith('<alias>'):
114
fact = convertAlias(fact)
115
print 'Alias: %s : %s' %(fact['name'], fact['data'])
116
print 'fact: %s' %fact['name']
118
newdb.add(fact, table=newtable)
121
# nothing to change, just copy
122
tables = olddb.getTables(all=tableUser.name)
125
print 'Table: %s' %table.name
126
facts = olddb.get(table=table)
128
print 'User: %s' %fact['host']
129
newdb.add(fact, table=table)