Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JSON Save and Load #166

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Added JSON Save and Load #166

wants to merge 9 commits into from

Conversation

Lokno
Copy link

@Lokno Lokno commented Aug 31, 2014

I thought it would be useful for Twine to be able to save and load JSON instead of pickle dumps. I wrote some changes to use the jsonpickle library instead of pickle. You can now "Save as JSON..." and this will save a .twjs file. Open now loads both the original .tws files and the JSON .twjs files. I use a regex in StoryPanel to remove the time fields from the jsonpickled classes. This is because I see they are being phased out, and there is no general way to remove them from the get/setstate methods which will work with legacy files.

@Lokno
Copy link
Author

Lokno commented Aug 31, 2014

I only really did that for completeness (and absentmindedly I thought it might be nice to be able to paste JSON somewhere else and edit it). The actual calls and default parameters for those functions are such that the operation is still carried out in pickle. Happy to remove those extra lines, that's a simple change.

Edit: I'll just take the initiative and remove it.

@Lokno
Copy link
Author

Lokno commented Sep 30, 2014

I added a line in app.py to intend the JSON so it's human readable, and also to sort the tags. Sorting the tags makes the regex in the storypanel.py stripTimeFields method more rebust. However, using this regex to strip out the time information is a hack I would rather do without. The trouble is: the JSON is too messy with the time codes left in, but the time codes have to stay in the pickling of the class, otherwise the original file format won't be backwards comparable.

@Lokno
Copy link
Author

Lokno commented Oct 23, 2014

Line 324 of tiddlywiki.py states that pickling has been broken for older versions of Twine. However there is a contradicting note on Line 341 about maintaining compatibility with Twine 1.3.5. If compatibility is no longer a requirement, the attributes 'created' and 'modified' could be removed from getstate, which would in turn remove the need to strip these attributes out when saving JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant