import json
import os
import click
import sys
from aihub.domain.auth import AuthSettings
class AuthFileManager(object):
"""
Manages .ai-auth file in the current directory
"""
AUTH_FILE_PATH = os.path.join(os.getcwd() + "/.ai-auth")
@classmethod
def set_auth(self, auth_settings):
with open(self.AUTH_FILE_PATH, "w") as file:
file.write(json.dumps(auth_settings.to_dict()))
@classmethod
def get_auth(self):
if not os.path.isfile(self.AUTH_FILE_PATH):
raise Exception("Missing .ai-auth file")
with open(self.AUTH_FILE_PATH, "r") as file:
auth_settings = json.loads(file.read())
return AuthSettings.from_dict(auth_settings)
@classmethod
def exists_auth(self):
is_init_already = os.path.isfile(self.AUTH_FILE_PATH)
if is_init_already is False:
click.echo(click.style('[INFO] Please login first.', fg='yellow'))
sys.exit()
Replies to Re: Re: Re: Re: Re: Re: Re: Re: Untitled 
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}