python-ox/ox/web/auth.py

34 lines
910 B
Python
Raw Normal View History

2010-07-07 23:25:57 +00:00
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
# GPL 2009
2014-09-30 19:27:26 +00:00
from __future__ import print_function
2010-07-07 23:25:57 +00:00
import os
from ox.utils import json
2010-07-07 23:25:57 +00:00
def get(key):
user_auth = os.environ.get('oxAUTH', os.path.expanduser('~/.ox/auth.json'))
auth = {}
if os.path.exists(user_auth):
f = open(user_auth, "r")
data = f.read()
f.close()
auth = json.loads(data)
2010-07-07 23:25:57 +00:00
if key in auth:
return auth[key]
2014-09-30 19:27:26 +00:00
print("please add key %s to json file '%s'" % (key, user_auth))
2016-06-03 22:39:01 +00:00
raise Exception("no key %s found" % key)
2010-07-07 23:25:57 +00:00
2010-08-24 17:08:42 +00:00
def update(key, value):
user_auth = os.environ.get('oxAUTH', os.path.expanduser('~/.ox/auth.json'))
auth = {}
if os.path.exists(user_auth):
f = open(user_auth, "r")
data = f.read()
f.close()
auth = json.loads(data)
auth[key] = value
f = open(user_auth, "w")
f.write(json.dumps(auth, indent=2))
f.close()