Beispiel #1
0
    def diffSettings(self, settings, refDbPath):
        refDb = Database(refDbPath)
        if "schema" in settings and settings["schema"]:
            if os.path.exists(settings["schema"]):
                cuffSchemaFile = open(settings["schema"])
                currDb = Database(cuffSchemaFile.read())
                cuffSchemaFile.close()
            else:
                currDb = Database(settings["schema"])

            if "version" in settings:
                currDb.setVersion(int(settings["version"]))

        else:
            currDb = None
        diffSettings = {
            "data": {}
        }
        databaseContent = {
            "data": {}
        }

        if not currDb or not refDb.isEqualSchema(currDb):
            diffSettings["schema"] = refDb.getSchema()
        if not currDb or not refDb.getVersion() == currDb.getVersion():
            diffSettings["version"] = refDb.getVersion()

        colKeyName = settings["col_key"] if "col_key" in settings else "name"
        colValueName = settings["col_val"] if "col_val" in settings else "value"

        refSettingsData = settings["data"]

        for table in refDb.getTables():
            if not table.name in refSettingsData:
                databaseContent["data"][table.name] = []
                rows = table.selectRows()
                for row in rows:
                    databaseContent["data"][table.name].append(row.toDict())
            else:
                refSettingsTable = refSettingsData[table.name]

                diffSettings["data"][table.name] = {}

                for row in table.selectRows():
                    key = row.getValueFor(colKeyName)
                    value = row.getValueFor(colValueName)
                    if not key in refSettingsTable or refSettingsTable[key] != value:
                        diffSettings["data"][table.name][key] = value


        return (diffSettings, databaseContent)
Beispiel #2
0
    def diffSettings(self, settings, refDbPath):
        refDb = Database(refDbPath)
        if "schema" in settings and settings["schema"]:
            if os.path.exists(settings["schema"]):
                cuffSchemaFile = open(settings["schema"])
                currDb = Database(cuffSchemaFile.read())
                cuffSchemaFile.close()
            else:
                currDb = Database(settings["schema"])

            if "version" in settings:
                currDb.setVersion(int(settings["version"]))

        else:
            currDb = None
        diffSettings = {
            "data": {}
        }
        databaseContent = {
            "data": {}
        }

        if not currDb or not refDb.isEqualSchema(currDb):
            diffSettings["schema"] = refDb.getSchema()
        if not currDb or not refDb.getVersion() == currDb.getVersion():
            diffSettings["version"] = refDb.getVersion()

        colKeyName = settings["col_key"] if "col_key" in settings else "name"
        colValueName = settings["col_val"] if "col_val" in settings else "value"

        refSettingsData = settings["data"]

        for table in refDb.getTables():
            if not table.name in refSettingsData:
                databaseContent["data"][table.name] = []
                rows = table.selectRows()
                for row in rows:
                    databaseContent["data"][table.name].append(row.toDict())
            else:
                refSettingsTable = refSettingsData[table.name]

                diffSettings["data"][table.name] = {}

                for row in table.selectRows():
                    key = row.getValueFor(colKeyName)
                    value = row.getValueFor(colValueName)
                    if not key in refSettingsTable or refSettingsTable[key] != value:
                        diffSettings["data"][table.name][key] = value


        return (diffSettings, databaseContent)