Example #1
0
    def run(self):
        self.dom = parse(self.args.inputFileName)
        version = self.dom.documentElement.getAttribute("dbversion")
        version = int(version)
        if version != nafdb.DATABASE_VERSION[0]:
            raise cImportException(
                "Database version %d in Xml file does not match required version %d"
                % (version, nafdb.DATABASE_VERSION[0])
            )
        if os.path.exists(self.args.databaseName):
            raise cImportException("database already exists: %s" % self.args.databaseName)
        nafdb.createEmptyDatabase(self.args.databaseName)
        nafdb.openDatabase(self.args.databaseName)
        map(self.importXmlSection, nafdb.getTableNames())

        # -- relations
        relations = self.dom.getElementsByTagName("relations")[0]
        items = relations.getElementsByTagName("item")
        values = []
        for item in items:
            value = (
                int(item.getElementsByTagName("id")[0].firstChild.data.strip()),
                int(item.getElementsByTagName("relatedid")[0].firstChild.data.strip()),
            )
            values.append(value)
        nafdb.connection.executemany("insert into relations values (?, ?);", values)

        # Update counter table
        nafdb.connection.execute("update counter set cnt=?", (self.maxId + 1,))

        nafdb.connection.commit()
Example #2
0
 def run(self):
     self.setupXmlDoc()
     nafdb.openDatabase(self.args.databaseName)
     self.writeDatabaseVersion()
     self.cursor = nafdb.connection.cursor()
     command = []
     for tableName in nafdb.getTableNames():
         command.append('select id, typeid, title, viewpos from %s ' %
                        (tableName, ))
     command = ' union '.join(command)
     command = 'create temporary view allitems as ' + command + ';'
     self.cursor.execute(command)
     self.cursor.execute(
         'create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)'
     )
     self.cursor.execute(
         'create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid'
     )
     tocnode = self._createElement("tableofcontents")
     self.root.appendChild(tocnode)
     node = self._createElement("contents")
     self.root.appendChild(node)
     self.traverseChilds(0, node, tocnode)
     self.cursor.execute('drop view allitems;')
     self.cursor.execute('drop view id_and_pid;')
     self.cursor.execute('drop view ordereditems;')
     self.writeXmlDoc()
Example #3
0
    def run(self):
        self.dom = parse(self.args.inputFileName)
        version = self.dom.documentElement.getAttribute('dbversion')
        version = int(version)
        if version != nafdb.DATABASE_VERSION[0]:
            raise cImportException(
                'Database version %d in Xml file does not match required version %d'
                % (version, nafdb.DATABASE_VERSION[0]))
        if os.path.exists(self.args.databaseName):
            raise cImportException('database already exists: %s' %
                                   self.args.databaseName)
        nafdb.createEmptyDatabase(self.args.databaseName)
        nafdb.openDatabase(self.args.databaseName)
        map(self.importXmlSection, nafdb.getTableNames())

        #-- relations
        relations = self.dom.getElementsByTagName('relations')[0]
        items = relations.getElementsByTagName('item')
        values = []
        for item in items:
            value = (int(
                item.getElementsByTagName('id')[0].firstChild.data.strip()),
                     int(
                         item.getElementsByTagName('relatedid')
                         [0].firstChild.data.strip()))
            values.append(value)
        nafdb.connection.executemany("insert into relations values (?, ?);",
                                     values)

        # Update counter table
        nafdb.connection.execute("update counter set cnt=?",
                                 (self.maxId + 1, ))

        nafdb.connection.commit()
Example #4
0
 def _setUp(self):
     nafdb.openDatabase(self.databaseName)
     self.cursor = nafdb.connection.cursor()
     self.cursor.execute("select version from __info__")
     self.dbVersion = str(self.cursor.fetchone()[0])
     command = []
     for tableName in nafdb.getTableNames():
         command.append('select id, typeid, title, viewpos from %s ' % (tableName, ))
     command = ' union '.join(command)
     command = 'create temporary view allitems as ' + command + ';'
     self.cursor.execute(command)
     self.cursor.execute('create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)')
     self.cursor.execute('create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid')
Example #5
0
 def _setUp(self):
     nafdb.openDatabase(self.databaseName)
     self.cursor = nafdb.connection.cursor()
     self.cursor.execute("select version from __info__")
     self.dbVersion = str(self.cursor.fetchone()[0])
     command = []
     for tableName in nafdb.getTableNames():
         command.append('select id, typeid, title, viewpos from %s ' %
                        (tableName, ))
     command = ' union '.join(command)
     command = 'create temporary view allitems as ' + command + ';'
     self.cursor.execute(command)
     self.cursor.execute(
         'create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)'
     )
     self.cursor.execute(
         'create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid'
     )
Example #6
0
 def run(self):
     self.setupXmlDoc()
     nafdb.openDatabase(self.args.databaseName)
     self.writeDatabaseVersion()
     self.cursor = nafdb.connection.cursor()
     command = []
     for tableName in nafdb.getTableNames():
         command.append('select id, typeid, title, viewpos from %s ' % (tableName, ))
     command = ' union '.join(command)
     command = 'create temporary view allitems as ' + command + ';'
     self.cursor.execute(command)
     self.cursor.execute('create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)')
     self.cursor.execute('create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid')
     tocnode = self._createElement("tableofcontents")
     self.root.appendChild(tocnode)
     node = self._createElement("contents")
     self.root.appendChild(node)
     self.traverseChilds(0, node, tocnode)
     self.cursor.execute('drop view allitems;');
     self.cursor.execute('drop view id_and_pid;');
     self.cursor.execute('drop view ordereditems;');
     self.writeXmlDoc()
Example #7
0
 def __init__(self):
     self.dbitems = []
     self.iconprovider = cIconProvider()
     self.filterDict = {}
     for tablename in nafdb.getTableNames():
         self.filterDict[tablename] = ''
Example #8
0
 def __init__(self):
     self.dbitems = []
     self.iconprovider = cIconProvider()
     self.filterDict = {}
     for tablename in nafdb.getTableNames():
         self.filterDict[tablename] = ""
Example #9
0
def run(args):
    report = cReport(args)
    report.start(args.databaseName1, args.databaseName2)
    connection1 = sqlite3.connect(args.databaseName1)
    connection2 = sqlite3.connect(args.databaseName2)
    cursor1 = connection1.cursor()
    cursor2 = connection2.cursor()
    version1 = cursor1.execute("select version from __info__;").fetchone()[0]
    version2 = cursor2.execute("select version from __info__;").fetchone()[0]
    if version1 != version2:
        report.nonMatchingVersions(version1, version2)
        sys.exit()
    
    command = []
    for tableName in nafdb.getTableNames():
        command.append('select id, typeid from %s' % (tableName, ))
    command = ' union '.join(command)
    command = 'create temporary view allids as ' + command + ';'
    cursor1.execute(command)
    cursor2.execute(command)
    
    # TODO: check if parents of two items have changed
    # TODO: check if viewpos of two items has changed
    # TODO: check if relations of two items has changed
    
    # look at all id present in first file 
    cursor1.execute("select * from allids;")
    for (id1, typeid1) in cursor1:
        try:
            (id2, typeid2) = cursor2.execute("select * from allids where id=?", (id1, )).fetchone()
            if typeid1 == nafdb.TYPE_ROOT and typeid2 == nafdb.TYPE_ROOT:
                pass
            elif typeid1 == typeid2:
                # same types, so compare all columns 
                logging.debug("same types (%d, %d), (%d, %d)" % (id1, typeid1, id2, typeid2))
                table = nafdb.getTableForTypeId(typeid1)
                columns = table.columns
                printId = True
                for column in columns:
                    item1 = getItemForId(connection1, table.name, id1, column.name)
                    item2 = getItemForId(connection2, table.name, id2, column.name)
                    if column._type == 'text':# and (item1.lstrip().startswith("<!DOCTYPE") or item2.lstrip().startswith("<!DOCTYPE")):
                        doc = QtGui.QTextDocument()
                        doc.setHtml(item1)
                        item1 = '<br/>'.join(unicode(doc.toPlainText()).splitlines(1))
                        doc.setHtml(item2)
                        item2 = '<br/>'.join(unicode(doc.toPlainText()).splitlines(1))
                    if item1 != item2:
                        report.differentItem(id1, column.displayname, item1, item2, printId)
                        printId = False
            else:
                # different types, nothing to compare, report only
                logging.debug("different types (%d, %d), (%d, %d)" % (id1, typeid1, id2, typeid2))
                report.differentTypes(id1, typeid1, typeid2)
        except TypeError:
            # id present in first file but not in second file
            logging.debug("item (%d, %d) not found in second file" % (id1, typeid1))
            report.missingItem(id1, typeid1, None)
            pass
            
    # finally we look for all id present in second file but not in first file
    cursor2.execute("select * from allids;")
    for (id2, typeid2) in cursor2:
        try:
            (id2, typeid2) = cursor1.execute("select * from allids where id=?", (id2, )).fetchone()
        except TypeError:
            # id present in second file but not in first file
            logging.debug("item (%d, %d) not found in first file" % (id2, typeid2))
            report.missingItem(id2, None, typeid2)
            pass
    
        
        
        
    connection1.close()
    connection2.close()
Example #10
0
def run(args):
    report = cReport(args)
    report.start(args.databaseName1, args.databaseName2)
    connection1 = sqlite3.connect(args.databaseName1)
    connection2 = sqlite3.connect(args.databaseName2)
    cursor1 = connection1.cursor()
    cursor2 = connection2.cursor()
    version1 = cursor1.execute("select version from __info__;").fetchone()[0]
    version2 = cursor2.execute("select version from __info__;").fetchone()[0]
    if version1 != version2:
        report.nonMatchingVersions(version1, version2)
        sys.exit()

    command = []
    for tableName in nafdb.getTableNames():
        command.append("select id, typeid from %s" % (tableName,))
    command = " union ".join(command)
    command = "create temporary view allids as " + command + ";"
    cursor1.execute(command)
    cursor2.execute(command)

    # TODO: check if parents of two items have changed
    # TODO: check if viewpos of two items has changed
    # TODO: check if relations of two items has changed

    # look at all id present in first file
    cursor1.execute("select * from allids;")
    for (id1, typeid1) in cursor1:
        try:
            (id2, typeid2) = cursor2.execute("select * from allids where id=?", (id1,)).fetchone()
            if typeid1 == nafdb.TYPE_ROOT and typeid2 == nafdb.TYPE_ROOT:
                pass
            elif typeid1 == typeid2:
                # same types, so compare all columns
                logging.debug("same types (%d, %d), (%d, %d)" % (id1, typeid1, id2, typeid2))
                table = nafdb.getTableForTypeId(typeid1)
                columns = table.columns
                printId = True
                for column in columns:
                    item1 = getItemForId(connection1, table.name, id1, column.name)
                    item2 = getItemForId(connection2, table.name, id2, column.name)
                    if (
                        column._type == "text"
                    ):  # and (item1.lstrip().startswith("<!DOCTYPE") or item2.lstrip().startswith("<!DOCTYPE")):
                        doc = QtGui.QTextDocument()
                        doc.setHtml(item1)
                        item1 = "<br/>".join(unicode(doc.toPlainText()).splitlines(1))
                        doc.setHtml(item2)
                        item2 = "<br/>".join(unicode(doc.toPlainText()).splitlines(1))
                    if item1 != item2:
                        report.differentItem(id1, column.displayname, item1, item2, printId)
                        printId = False
            else:
                # different types, nothing to compare, report only
                logging.debug("different types (%d, %d), (%d, %d)" % (id1, typeid1, id2, typeid2))
                report.differentTypes(id1, typeid1, typeid2)
        except TypeError:
            # id present in first file but not in second file
            logging.debug("item (%d, %d) not found in second file" % (id1, typeid1))
            report.missingItem(id1, typeid1, None)
            pass

    # finally we look for all id present in second file but not in first file
    cursor2.execute("select * from allids;")
    for (id2, typeid2) in cursor2:
        try:
            (id2, typeid2) = cursor1.execute("select * from allids where id=?", (id2,)).fetchone()
        except TypeError:
            # id present in second file but not in first file
            logging.debug("item (%d, %d) not found in first file" % (id2, typeid2))
            report.missingItem(id2, None, typeid2)
            pass

    connection1.close()
    connection2.close()