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

Make discovery server's list of projects persist across restarts #250

Merged
merged 6 commits into from
Mar 30, 2017

Conversation

iandioch
Copy link
Member

Connects to #233.

When you start a discovery server, you can set it to read a list of projects from a given file (each self-contained json documents, one per line).
As it receives new project information, it can then append the file with the info for it.

Copy link
Member

@CianLR CianLR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boom boom boom

with open(self.__server_file, 'a') as f:
s = json.dumps(project,
default=lambda x: x.serialize(),
indent=None)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does None actually add anything here?

Copy link
Member Author

@iandioch iandioch Mar 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of. An indent of None means the resulting json is on a single line, which is important here. I'm pretty sure that that is the default value anyway, but it felt better to be explicit and not rely on that behaviour (which only changed recently to that IIRC)

def _write_new_project_to_file(self, project):
with open(self.__server_file, 'a') as f:
s = json.dumps(project,
default=lambda x: x.serialize(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure serialize is the correct word here? Maybe standardize would be better, serializing makes me think of converting to a binary or string format that can be deserialized somewhere else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as json can only encode the primitive types, json.dump-ing a custom object throws an exception. I went looking for a while on how best to go around this, and having a .serialize() method seemed to be a quasi-standard in Python.

Although it kills me to use the american spelling for serialise.

@iandioch iandioch merged commit ac72552 into master Mar 30, 2017
@iandioch iandioch deleted the n/save_servers#233 branch March 30, 2017 13:57
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.

3 participants