make login optional, support passing config dict
This commit is contained in:
parent
c9eccc6aaa
commit
e44dad7dec
2 changed files with 20 additions and 8 deletions
|
@ -47,14 +47,19 @@ def encode(filename, profile):
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
with open(config) as f:
|
if isinstance(config, basestring):
|
||||||
self._config = json.loads(f.read())
|
with open(config) as f:
|
||||||
self.api = API(self._config['url'])
|
self._config = json.loads(f.read())
|
||||||
r = self.api.login({'username':self._config['username'], 'password':self._config['password']})
|
|
||||||
if r['status']['code'] == 200:
|
|
||||||
self.user = r['data']['user']
|
|
||||||
else:
|
else:
|
||||||
print 'login failed'
|
self.config = config
|
||||||
|
self.api = API(self._config['url'])
|
||||||
|
|
||||||
|
if 'username' in self._config:
|
||||||
|
r = self.api.login({'username':self._config['username'], 'password':self._config['password']})
|
||||||
|
if r['status']['code'] == 200:
|
||||||
|
self.user = r['data']['user']
|
||||||
|
else:
|
||||||
|
print 'login failed'
|
||||||
|
|
||||||
conn, c = self._conn()
|
conn, c = self._conn()
|
||||||
|
|
||||||
|
|
9
setup.py
9
setup.py
|
@ -3,9 +3,16 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
|
def get_bzr_version():
|
||||||
|
import os
|
||||||
|
rev = int(os.popen('bzr revno').read())
|
||||||
|
if rev:
|
||||||
|
return u'%s' % rev
|
||||||
|
return u'unknown'
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pandora_client",
|
name="pandora_client",
|
||||||
version="1.0",
|
version="1.0.%s" % get_bzr_version() ,
|
||||||
description='''pandora_client - headless archive client for pan.do/ra
|
description='''pandora_client - headless archive client for pan.do/ra
|
||||||
|
|
||||||
can be used instead of OxFF to keep archive and pan.do/ra instance in sync.
|
can be used instead of OxFF to keep archive and pan.do/ra instance in sync.
|
||||||
|
|
Loading…
Reference in a new issue