blob: 079ae14747daeb588785a55c2ab3797866b1e353 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/usr/bin/env python
'''PyLibChorus -- Python Chorus API Library'''
import logging
from pylibchorus.chorus_api import login
from pylibchorus.chorus_api import logout
from pylibchorus.chorus_api import check_login_status
from pylibchorus.chorus_api import create_workfile
from pylibchorus.chorus_api import update_workfile_version
from pylibchorus.chorus_api import delete_workfile
LOG = logging.getLogger(__name__)
#pylint: disable=R0903
class ChorusSession(object):
'''Chorus User Session Object'''
def __init__(self, config):
self.config = config
self.sid = None
self.cookies = None
def __enter__(self):
'''create session and return sid and cookies'''
LOG.debug("Opening Chorus Session")
code, json, cookies = login(
self.config.get('alpine', 'username'),
self.config.get('alpine', 'password'),
self)
if code != 201:
raise RuntimeError("Chorus Session Login Failed")
self.sid = json['response']['session_id']
self.cookies = dict(cookies)
return self
def __exit__(self, _type, _value, _traceback):
'''Close chorus session'''
LOG.debug("Closing Chorus Session")
logout(self)
|