ChristianTremblay / pyhaystack

Pyhaystack is a module that allow python programs to connect to a haystack server project-haystack.org. Connection can be established with Niagara Platform running the nhaystack, Skyspark and Widesky. For this to work with Anaconda IPython Notebook in Windows, be sure to use "python setup.py install" using the Anaconda Command Prompt in Windows. If not, module will be installed for System path python but won't work in the environment of Anaconda IPython Notebook. You will need hszinc 1.3+ for this to work.
Apache License 2.0
74 stars 32 forks source link

SkysparkScramHaystackSession can now be used as a context manager #90

Closed criverc closed 4 years ago

criverc commented 4 years ago

Hi, I found the need to use SkysparkScramHaystackSession to get some data from a Skyspark server, but I didn't like that sessions lingered there for 3 hours. So I wrote some code to close the session using an advice given by Brian Frank. I like the use of the with statement in Python so I made changes to SkysparkScramHaystackSession to become a ContextManager. Please consider these changes for upstream.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.2%) to 39.607% when pulling 79b3984b9f6208611a82cf89ea30a6bb3ef39f37 on criverc:develop into eac2cbc8545587b42b85ceb8c89fef11be4f9a75 on ChristianTremblay:develop.

ChristianTremblay commented 4 years ago

I like the idea. Thanks

sjlongland commented 4 years ago

It'd probably be worth having a logout() method on the session object itself and putting the context manager stuff in the base session class.

WideSky implements a log-out using a REST call (DELETE /oauth2/token IIRC). Not sure how nHaystack does a log-out.

ChristianTremblay commented 4 years ago

Absolutely, I'm on it

ChristianTremblay commented 4 years ago

@sjlongland can you take care of the widesky logout function ? I will test nhaystack

sjlongland commented 4 years ago

On 12/8/20 10:19 am, Christian Tremblay wrote:

@sjlongland can you take care of the widesky logout function ? I will test nhaystack

I'll try to slot it in somewhere in the TO-DO list.

ChristianTremblay commented 4 years ago

@criverc I've tested the best I can on my side and things seem to work properly on Skyspark and nhaystack. I'd like you to test the develop branch please. Just to be sure.

@sjlongland Whenever you have time... Feel free to bring your touch to what I did. It's been a long time a digged into pyhaystack...

criverc commented 4 years ago

@ChristianTremblay The move to the base class looks good. I see also that using print was a bad idea. I will test it now and let you know.

criverc commented 4 years ago

@ChristianTremblay Hi, I tried by hand, using my code with changes to use the context manager, pyhaystack is from the head of develop branch and I see that everything works as expected and sessions are closed at skyspark.

ChristianTremblay commented 4 years ago

@criverc Thanks for the test... and for the idea.

criverc commented 4 years ago

@ChristianTremblay I am glad I could help, thank you for pyhaystack.

sjlongland commented 4 years ago

Before I forget (since this PR is merged) I've filed myself an issue on my own fork to do this.

https://github.com/sjlongland/pyhaystack/issues/1