示例#1
0
    def __init__(self, **kwargs):
        """
        Instantiate GitHubTools & LocalTools (if needed), and set the variables required
        to get, create or update gists (filename and public/private flag)
        :param user: (str) GitHub username
        :param filename: (str) name of file from any Gist or local file system
        :param allow_none: (bool) flag to use GitHubTools.select_gist
        differently with `getgist` and `putgist` commands (if no gist/filename
        is found it raises an error for `getgist`, or sets `putgist` to create
        a new gist).
        :param create_private: (bool) create a new gist as private
        :param assume_yes: (bool) assume yes (or first option) for all prompts
        :return: (None)
        """
        user = kwargs.get("user")
        allow_none = kwargs.get("allow_none", False)
        assume_yes = kwargs.get("assume_yes", False)
        filename = kwargs.get("filename")
        self.public = not kwargs.get("create_private", False)

        if not user:
            message = """
            No default user set yet. To avoid this prompt set an
            environmental variable called  `GETGIST_USER`.'
            """
            GetGistCommons().oops(message)
            exit(1)

        self.github = GitHubTools(user, filename, assume_yes)
        self.local = LocalTools(filename, assume_yes) if filename else None
        self.gist = self.github.select_gist(allow_none) if filename else None
示例#2
0
文件: __main__.py 项目: hilam/getgist
    def __init__(self, **kwargs):
        """
        Instantiate GitHubTools & LocalTools, and set the variables required
        to get, create or update gists (filename and public/private flag)
        :param user: (str) GitHub username
        :param filename: (str) name of file from any Gist or local file system
        :param allow_none: (bool) flag to use GitHubTools.select_gist
        differently with `getgist` and `putgist` commands (if no gist/filename
        is found it raises an error for `getgist`, or sets `putgist` to create
        a new gist).
        :param create_private: (bool) create a new gist as private
        :param assume_yes: (bool) assume yes (or first option) for all prompts
        :return: (None)
        """

        # get arguments
        user = kwargs.get('user')
        allow_none = kwargs.get('allow_none', False)
        assume_yes = kwargs.get('assume_yes', False)
        filename = kwargs.get('filename')
        self.public = not kwargs.get('create_private', False)

        # instantiate local tools & check for user
        self.local = LocalTools(filename, assume_yes)
        if not user:
            message = """
                No default user set yet. To avoid this prompt set an
                environmental variable called  `GETGIST_USER`.'
            """
            self.local.oops(message)

        # instantiate filename, guthub tools and fetch gist
        self.github = GitHubTools(user, filename, assume_yes)
        self.gist = self.github.select_gist(allow_none)
示例#3
0
class GetGist(object):
    """
    Main GetGist objects linking inputs from the CLI to the helpers from
    GitHubTools (to deal with the API) and LocalTools (to deal with the local
    file system.
    """
    def __init__(self, **kwargs):
        """
        Instantiate GitHubTools & LocalTools (if needed), and set the variables required
        to get, create or update gists (filename and public/private flag)
        :param user: (str) GitHub username
        :param filename: (str) name of file from any Gist or local file system
        :param allow_none: (bool) flag to use GitHubTools.select_gist
        differently with `getgist` and `putgist` commands (if no gist/filename
        is found it raises an error for `getgist`, or sets `putgist` to create
        a new gist).
        :param create_private: (bool) create a new gist as private
        :param assume_yes: (bool) assume yes (or first option) for all prompts
        :return: (None)
        """
        user = kwargs.get("user")
        allow_none = kwargs.get("allow_none", False)
        assume_yes = kwargs.get("assume_yes", False)
        filename = kwargs.get("filename")
        self.public = not kwargs.get("create_private", False)

        if not user:
            message = """
            No default user set yet. To avoid this prompt set an
            environmental variable called  `GETGIST_USER`.'
            """
            GetGistCommons().oops(message)
            exit(1)

        self.github = GitHubTools(user, filename, assume_yes)
        self.local = LocalTools(filename, assume_yes) if filename else None
        self.gist = self.github.select_gist(allow_none) if filename else None

    def get(self):
        """Reads the remote file from Gist and save it locally"""
        if self.gist:
            content = self.github.read_gist_file(self.gist)
            self.local.save(content)

    def put(self):
        """ Reads local file & update the remote gist (or create a new one)"""
        content = self.local.read()
        if self.gist:
            self.github.update(self.gist, content)
        else:
            self.github.create(content, public=self.public)

    def ls(self):
        """ Lists all gists from a github user """
        self.github.list_gists()
示例#4
0
class GetGist(object):
    """
    Main GetGist objects linking inputs from the CLI to the helpers from
    GitHubTools (to deal with the API) and LocalTools (to deal with the local
    file system.
    """

    def __init__(self, **kwargs):
        """
        Instantiate GitHubTools & LocalTools, and set the variables required
        to get, create or update gists (filename and public/private flag)
        :param user: (str) GitHub username
        :param filename: (str) name of file from any Gist or local file system
        :param allow_none: (bool) flag to use GitHubTools.select_gist
        differently with `getgist` and `putgist` commands (if no gist/filename
        is found it raises an error for `getgist`, or sets `putgist` to create
        a new gist).
        :param create_private: (bool) create a new gist as private
        :param assume_yes: (bool) assume yes (or first option) for all prompts
        :return: (None)
        """

        # get arguments
        user = kwargs.get('user')
        allow_none = kwargs.get('allow_none', False)
        assume_yes = kwargs.get('assume_yes', False)
        filename = kwargs.get('filename')
        self.public = not kwargs.get('create_private', False)

        # instantiate local tools & check for user
        self.local = LocalTools(filename, assume_yes)
        if not user:
            message = """
                No default user set yet. To avoid this prompt set an
                environmental variable called  `GETGIST_USER`.'
            """
            self.local.oops(message)

        # instantiate filename, guthub tools and fetch gist
        self.github = GitHubTools(user, filename, assume_yes)
        self.gist = self.github.select_gist(allow_none)

    def get(self):
        """Reads the remote file from Gist and save it locally"""
        if self.gist:
            content = self.github.read_gist_file(self.gist)
            self.local.save(content)

    def put(self):
        """ Reads local file & update the remote gist (or create a new one)"""
        content = self.local.read(self.github.filename)
        if self.gist:
            self.github.update(self.gist, content)
        else:
            self.github.create(content, public=self.public)
示例#5
0
    def __init__(self, **kwargs):
        """
        Instantiate GitHubTools & LocalTools, and set the variables required
        to get, create or update gists (filename and public/private flag)
        :param user: (str) GitHub username
        :param filename: (str) name of file from any Gist or local file system
        :param allow_none: (bool) flag to use GitHubTools.select_gist
        differently with `getgist` and `putgist` commands (if no gist/filename
        is found it raises an error for `getgist`, or sets `putgist` to create
        a new gist).
        :param create_private: (bool) create a new gist as private
        :param assume_yes: (bool) assume yes (or first option) for all prompts
        :return: (None)
        """

        # get arguments
        user = kwargs.get('user')
        allow_none = kwargs.get('allow_none', False)
        assume_yes = kwargs.get('assume_yes', False)
        filename = kwargs.get('filename')
        self.public = not kwargs.get('create_private', False)

        # instantiate local tools & check for user
        self.local = LocalTools(filename, assume_yes)
        if not user:
            message = """
                No default user set yet. To avoid this prompt set an
                environmental variable called  `GETGIST_USER`.'
            """
            self.local.oops(message)

        # instantiate filename, guthub tools and fetch gist
        self.github = GitHubTools(user, filename, assume_yes)
        self.gist = self.github.select_gist(allow_none)
示例#6
0
def local():
    with open(TEST_FILE, "w") as fobj:
        fobj.write(TEST_FILE_CONTENTS)

    yield LocalTools(TEST_FILE)

    for path in glob("{}*".format(TEST_FILE)):
        os.remove(path)
示例#7
0
def temporary_file():
    with NamedTemporaryFile(mode="w") as fobj:
        fobj.write(TEST_FILE_CONTENTS)
        fobj.seek(0)
        yield LocalTools(fobj.name)
示例#8
0
 def setUp(self):
     self.local = LocalTools(TEST_FILE)
     self.cwd = os.getcwd()
     self.file_path = os.path.join(self.cwd, TEST_FILE)