makiolo

Untitled

Jan 31st, 2017
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. from os.path import expanduser
  3.  
  4. default_auth = os.path.join(os.environ.get('APPDATA', os.getcwd()), '.pyqbs.auth')
  5. home_auth = os.path.join(expanduser("~"), '.pyqbs.auth')
  6.  
  7. '''
  8. pyqbs auth file is not found in your machine
  9. '''
  10. class PyQBSAuthNotFound(Exception):
  11.     def __init__(self):
  12.         pass
  13.     def __str__(self):
  14.         return ('PyQBS is not found.\ntry set environment variable PYQBS_AUTH')
  15.  
  16. def find_pyqbs_auth(env = os.environ):
  17.     '''
  18.    1. check variable PYQBS_AUTH
  19.    2. check if exists default_auth
  20.    2. check if exists home_auth
  21.    3. exception in other case
  22.    '''
  23.  
  24.     if 'PYQBS_AUTH' in env:
  25.         return env['PYQBS_AUTH']
  26.  
  27.     if os.path.isfile(default_auth):
  28.         return default_auth
  29.  
  30.     if os.path.isfile(home_auth):
  31.         return home_auth
  32.  
  33.     raise PyQBSAuthNotFound()
RAW Paste Data