Skip to content

Commit

Permalink
Python method for retrieving the list of environment names from the s…
Browse files Browse the repository at this point in the history
…erver (fossasia#463)

Summary:
Introduces a way to get a list of all of the environment names from the server. Could be useful to make some python tooling around sorting and deleting environments, and also later around downloading and saving environments.

Implements fossasia#445

Tested by running in terminal

<img width="493" alt="screen shot 2018-08-29 at 11 19 51 pm" src="https://user-images.githubusercontent.com/1276867/44827666-12baf100-abe2-11e8-9151-56bce8a49f84.png">

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [ ] For JavaScript changes, I have re-generated the minified JavaScript code.
Pull Request resolved: fossasia#463

Differential Revision: D9616314

Pulled By: JackUrb

fbshipit-source-id: e04d21fc3da1cff7ce7e96b31766eb44dbeb2595
  • Loading branch information
JackUrb authored and facebook-github-bot committed Aug 31, 2018
1 parent e258d36 commit b7eda6e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ vis._send({'data': [trace], 'layout': layout, 'win': 'mywin'})
- [`vis.close`](#visclose) : close a window by id
- [`vis.delete_env`](#visdelete_env) : delete an environment by env_id
- [`vis.win_exists`](#viswin_exists) : check if a window already exists by id
- [`vis.get_env_list`](#visget_env_list) : get a list of all of the environments on your server
- [`vis.win_hash`](#viswin_hash): get md5 hash of window's contents
- [`vis.get_window_data`](#visget_window_data): get current data for a window
- [`vis.check_connection`](#vischeck_connection): check if the server is connected
Expand Down Expand Up @@ -626,6 +627,10 @@ This function returns a bool indicating whether or not a window `win` exists on
Optional arguments:
- `env`: Environment to search for the window in. Default is `None`.

#### vis.get_env_list

This function returns a list of all of the environments on the server at the time of calling. It takes no arguments.

#### vis.win_hash

This function returns md5 hash of the contents of a window `win` if it exists on the server. Returns None otherwise.
Expand Down
7 changes: 7 additions & 0 deletions py/visdom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,13 @@ def _win_exists_wrap(self, win, env=None):
'eid': env,
}, endpoint='win_exists', quiet=True)

def get_env_list(self):
"""
This function returns a list of all of the env names that are currently
in the server.
"""
return json.loads(self._send({}, endpoint='env_state', quiet=True))

def win_exists(self, win, env=None):
"""
This function returns a bool indicating whether
Expand Down
20 changes: 20 additions & 0 deletions py/visdom/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __init__(self, port=DEFAULT_PORT, env_path=DEFAULT_ENV_PATH,
(r"/win_data", DataHandler, {'app': self}),
(r"/delete_env", DeleteEnvHandler, {'app': self}),
(r"/win_hash", HashHandler, {'app': self}),
(r"/env_state", EnvStateHandler, {'app': self}),
(r"/(.*)", IndexHandler, {'app': self}),
]
super(Application, self).__init__(handlers, **tornado_settings)
Expand Down Expand Up @@ -671,6 +672,25 @@ def post(self):
)
self.wrap_func(self, args)


class EnvStateHandler(BaseHandler):
def initialize(self, app):
self.app = app
self.state = app.state

@staticmethod
def wrap_func(handler, args):
# TODO if an env is provided return the state of that env
all_eids = list(handler.state.keys())
handler.write(json.dumps(all_eids))

def post(self):
args = tornado.escape.json_decode(
tornado.escape.to_basestring(self.request.body)
)
self.wrap_func(self, args)


class HashHandler(BaseHandler):
def initialize(self, app):
self.app = app
Expand Down

0 comments on commit b7eda6e

Please sign in to comment.