From a1b42ae577a2eb18d8ad2818b1716b14c79d9bac Mon Sep 17 00:00:00 2001 From: Justaus3r <72691864+Justaus3r@users.noreply.github.com> Date: Wed, 21 Sep 2022 22:12:06 +0500 Subject: [PATCH] feat: read files independent of path(for post/patch) --- README.rst | 2 ++ ceg/ceg.py | 9 +++++---- ceg/misc.py | 2 +- pyproject.toml | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 65cdac8..9818d51 100644 --- a/README.rst +++ b/README.rst @@ -151,6 +151,8 @@ you can also update the gist description by passing ``--description/-desc NEWDES $ ceg --patch "file4" "file4" -desc "My dirty secrets." -gi abcdef +*From v0.4.0 your files doesn't have to be in running directory of ceg, i.e: you can use files from other directories by giving their path.* + Listing public/secret(private) gists ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can list all of your gists, which will be beautified before printing to stdout. please note that if you are not authenticated(not giving GitHub secret key) then you can use ``--list-other/-lo`` but you will only be shown public gists. diff --git a/ceg/ceg.py b/ceg/ceg.py index 63cf103..c8b70e6 100755 --- a/ceg/ceg.py +++ b/ceg/ceg.py @@ -427,9 +427,9 @@ def post(self, **kwargs) -> Optional[str]: files_to_ignore: List[str] = [] file_to_content_map: Dict[str, Dict[str, str]] = {} for file in self.arg_val: # type: ignore - if file not in [file for file in os.listdir() if os.path.isfile(file)]: + if not os.path.exists(file): self.logger.info( - f"{file} not found in current directory,opening in default editor.." + f"{file} not found in given path,opening in default editor.." ) ret_code: int = open_file(file) if ret_code != 0: @@ -445,7 +445,8 @@ def post(self, **kwargs) -> Optional[str]: continue with open(file, "r") as r_obj: file_content: str = r_obj.read() - file_to_content_map.update({file: {"content": file_content}}) + file_basename: str = os.path.basename(file) + file_to_content_map.update({file_basename: {"content": file_content}}) if is_patch and new_filenames.get(file): # type: ignore file_to_content_map[file].update( {"filename": new_filenames.get(file)} # type: ignore @@ -502,7 +503,6 @@ def backup(self) -> None: try: self.get() except requests.exceptions.ConnectionError: - os.chdir("../") dir_handler.return_code = 1 raise requests.exceptions.ConnectionError( "Connection Error!,please check your internet connection." @@ -555,6 +555,7 @@ def perform_operation(self) -> int: except ( CegExceptions.BadCredentials, CegExceptions.ResourceNotFound, + CegExceptions.UnprocessableRequest, CegExceptions.InsufficientSubArguments, requests.exceptions.ConnectionError, ): diff --git a/ceg/misc.py b/ceg/misc.py index 810dc26..e90a751 100755 --- a/ceg/misc.py +++ b/ceg/misc.py @@ -59,7 +59,7 @@ class UtilInfo: DESCRIPTION: str = "A simple gist crud utility." # Caution(message to myself): Be careful when updating the version because # wrong updates can be a mess. - VERSION: str = "0.3.0" + VERSION: str = "0.4.0" def exception_executioner(exception_obj) -> None: diff --git a/pyproject.toml b/pyproject.toml index cdb9d7a..ff8c506 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ceg" -version = "0.3.0" +version = "0.4.0" description = "A simple gist crud utility." license = "GPL-3.0-or-later" authors = ["Justaus3r "]