-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.