Facebook
From Tiny Crane, 2 Years ago, written in Python.
This paste is a reply to Re: Re: Re: Re: Re: Re: Re: Untitled from Rude Porcupine - go back
Embed
import json
import os
import click
import sys
from aihub.domain.auth import AuthSettings

class BaseModel(object):
AuthFileManager(object):
    """
    Base for all model classes
Manages .ai-auth file in the current directory
    """

    def to_dict(self):
        return self.schema.dump(self)

AUTH_FILE_PATH = os.path.join(os.getcwd() + "/.ai-auth")

    @classmethod
    def from_dict(self, dct):
        
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 self.schema.load(dct)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 rss

Title Name Language When
Re: Re: Re: Re: Re: Re: Re: Re: Re: Untitled Round Prairie Dog python 2 Years ago.