Beispiel #1
0
    def load_and_compare(cls):
        """
        Loads the DB from MongoDB (If the selected Document doesn't exist we create it). Checks for changes and calls
        send_mail for every change. In the end we write back the Table to the DataBase. Due to the small maximum size
        of the Table we remove the old one and insert the new.
        :return
        True - if there was a change
        False - if there was no change
        """
        change = False
        client = MongoClient(dbURI)
        coll = client.test.work
        cur = coll.find()
        if cur.count() == 0:
            coll.insert(cls.TableStr)
            return

        tmpdic = {}
        for i in cur:
            tmpdic.update(i)
        diff = DictDiffer(tmpdic, cls.TableStr)
        for i in diff.changed():
            if cls.TableStr[i][0] != tmpdic[i][0]:
                change = True
                cls.TableObj[i][0].send_mail()
            if cls.TableStr[i][1] != tmpdic[i][1]:
                change = True
                cls.TableObj[i][1].send_mail()

        coll.remove({})
        coll.insert(cls.TableStr)
        return change
Beispiel #2
0
 def find_deltas(self):
     """ use DictDiffer to find differences between target and source databases """
     logging.info('finding deltas..')
     delta = DictDiffer(self.source['row'], self.target['row'])
     self.database['deltas'] = {
         'new_columns_in_source': delta.added(),
         'new_columns_in_target': delta.removed(),
         'delta_columns': delta.changed(),
         'unchanged_columns': delta.unchanged()
     }