Beispiel #1
0
def keyfs_changelog_view(request):
    pformat = partial(pprint.pformat, width=100)
    storage = request.registry['xom'].keyfs._storage
    serial = request.matchdict['serial']
    query = request.params.get('query')
    with storage.get_connection() as conn:
        data = conn.get_raw_changelog_entry(serial)
        last_changelog_serial = conn.last_changelog_serial
        (changes, rel_renames) = loads(data)
        for k, v in list(changes.items()):
            prev_formatted = ''
            if v[1] >= 0:
                prev_data = conn.get_raw_changelog_entry(v[1])
                prev_changes = loads(prev_data)[0]
                for prev_k, prev_v in prev_changes.items():
                    if prev_k == k and prev_v[0] == v[0]:
                        prev_formatted = pformat(prev_v[2])
            formatted = pformat(v[2])
            diffed = diff(prev_formatted, formatted)
            (_, latest_serial) = conn.db_read_typedkey(k)
            changes[k] = dict(type=v[0],
                              previous_serial=v[1],
                              latest_serial=latest_serial,
                              diffed=diffed)
    return dict(changes=changes,
                rel_renames=rel_renames,
                pformat=pformat,
                last_changelog_serial=last_changelog_serial,
                serial=int(serial),
                query=query)
Beispiel #2
0
 def test_get_since(self, testapp, mapp, noiter, reqchangelog):
     mapp.create_user("this", password="******")
     latest_serial = self.get_latest_serial(testapp)
     r = reqchangelog(latest_serial)
     body = b''.join(r.app_iter)
     data = loads(body)
     assert "this" in str(data)
Beispiel #3
0
 def get_changes(self, serial):
     changes = self._changelog_cache.get(serial)
     if changes is None:
         data = self.get_raw_changelog_entry(serial)
         changes, rel_renames = loads(data)
         # make values in changes read only so no calling site accidentally
         # modifies data
         changes = ensure_deeply_readonly(changes)
         self.cache_commit_changes(serial, changes)
     return changes
Beispiel #4
0
 def test_multiple_changes(self, mapp, noiter, reqchangelogs, testapp):
     mapp.create_user("this", password="******")
     mapp.create_user("that", password="******")
     latest_serial = self.get_latest_serial(testapp)
     assert latest_serial > 1
     r = reqchangelogs(0)
     body = b''.join(r.app_iter)
     data = loads(body)
     assert isinstance(data, list)
     assert len(data) == (latest_serial + 1)
     assert "this/.config" in str(data[-2])
     assert "that/.config" in str(data[-1])
Beispiel #5
0
def keyfs_changelog_view(request):
    storage = request.registry['xom'].keyfs._storage
    serial = request.matchdict['serial']
    query = request.params.get('query')
    with storage.get_connection() as conn:
        data = conn.get_raw_changelog_entry(serial)
    (changes, rel_renames) = loads(data)
    return dict(changes=changes,
                rel_renames=rel_renames,
                pformat=partial(pformat, width=180),
                serial=serial,
                query=query)
Beispiel #6
0
 def test_size_limit(self, mapp, monkeypatch, noiter, reqchangelogs, testapp):
     monkeypatch.setattr(MasterChangelogRequest, "MAX_REPLICA_CHANGES_SIZE", 1024)
     mapp.create_and_login_user("this", password="******")
     for i in range(10):
         mapp.create_index("this/dev%s" % i)
     latest_serial = self.get_latest_serial(testapp)
     assert latest_serial > 1
     r = reqchangelogs(0)
     body = b''.join(r.app_iter)
     data = loads(body)
     assert isinstance(data, list)
     assert len(data) < latest_serial