diff options
author | bnewbold <bnewbold@robocracy.org> | 2017-07-16 14:08:42 -0700 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2017-07-16 14:08:42 -0700 |
commit | 0dfe130eec2387cbfb78b707c4dd733d7ab8d1f4 (patch) | |
tree | 3487c46b20fae8a708ac26fcecc65203afebf212 | |
parent | 34a7f24b05122484e26d049df50a2ed40424e26a (diff) | |
download | divergence-0dfe130eec2387cbfb78b707c4dd733d7ab8d1f4.tar.gz divergence-0dfe130eec2387cbfb78b707c4dd733d7ab8d1f4.zip |
more attempts to get a clean diff
-rwxr-xr-x | divergence | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -38,11 +38,11 @@ class DivergenceProgram: """ Returns None if not found, otherwise a dict with id, space, and body (in storage format) """ - # TODO: could remove the body_view stuff here + # TODO: could remove the body_view and body_editor stuff here? resp = self.api.get(self.base_url + "/rest/api/content", params={"spaceKey": self.space, "title": title, - "expand": "body.storage,body.view,version,space", + "expand": "body.storage,body.view,body.editor,version,space", "type": "page"}) log.debug(resp) @@ -59,7 +59,21 @@ class DivergenceProgram: "version": int(page['version']['number']), "space": page['space']['key'], "body": page['body']['storage']['value'], - "body_view": page['body']['view']['value']} + "body_view": page['body']['view']['value'], + "body_editor": page['body']['editor']['value']} + + def get_conversion(self, body): + """ + Uses the REST API to convert from storage to 'editor' format. + """ + resp = self.api.post(self.base_url + "/rest/api/contentbody/convert/editor", + json={"representation": "storage", + "value": body }) + + log.debug(resp) + log.debug(resp.content) + assert resp.status_code == 200 + return resp.json()['value'] def create_page(self, title, body): resp = self.api.post(self.base_url + "/rest/api/content", @@ -114,10 +128,11 @@ class DivergenceProgram: # TODO: too much changes in the diff here. Should do # something like store the file sha1 in a comment, regex # that out, and compare? - from difflib import Differ - sys.stdout.writelines(Differ().compare( - prev['body'].splitlines(keepends=True), - body.splitlines(keepends=True))) + #this_body = self.get_conversion(body) + #from difflib import Differ + #sys.stdout.writelines(Differ().compare( + # prev['body_editor'].splitlines(keepends=True), + # this_body.splitlines(keepends=True))) self.update_page(title, body, prev['id'], prev['version']) print(f + ": updated") else: |