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 __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)
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()
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)
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 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)
def temporary_file(): with NamedTemporaryFile(mode="w") as fobj: fobj.write(TEST_FILE_CONTENTS) fobj.seek(0) yield LocalTools(fobj.name)
def setUp(self): self.local = LocalTools(TEST_FILE) self.cwd = os.getcwd() self.file_path = os.path.join(self.cwd, TEST_FILE)