Skip to content

Commit

Permalink
clone-git-repo@anaximeno: Version 1.3.0 (#404)
Browse files Browse the repository at this point in the history
* Correctly format addresses

* Ask user if residual folder should be sent to trash on cancel

* Refactor update some if-elif-else blocks

* Update text and pt translations

* Bump version
  • Loading branch information
anaximeno authored Jun 8, 2024
1 parent 9c8c05f commit 1747d33
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 38 deletions.
82 changes: 59 additions & 23 deletions clone-git-repo@anaximeno/files/clone-git-repo@anaximeno/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
gi.require_version("Gio", "2.0")
from gi.repository import Gtk, Gdk, Gio
from pathlib import Path


Expand Down Expand Up @@ -44,17 +45,18 @@ def __init__(self, directory: str, assume_protocol: str = "http") -> None:
self._formatted_address = ""
self._folder_path = ""
self._buff = ""
self._cancelled = False

def get_address_from_clipboard(self) -> str:
clipcontent: str = self.clipboard.wait_for_text()
addresscontent: str = ""

if clipcontent:
clipcontent = clipcontent.strip().rstrip("/").rstrip("?")
reponame = self.extract_repo_name_from_address(clipcontent)
if reponame and not " " in clipcontent:
addresscontent = clipcontent
log("Info: Got clipboard address:", addresscontent)
clipaddress = self._format_address(clipcontent)
reponame = self.extract_repo_name_from_address(clipaddress)
if reponame and not " " in clipaddress:
log("Info: Got clipboard address:", clipaddress)
addresscontent = clipaddress

if not addresscontent:
log("Info: Couldn't get a valid git address from the clipboard")
Expand Down Expand Up @@ -138,14 +140,16 @@ def prompt_folder_already_exists(self, folder_name: str) -> None:
window.destroy()

def _format_address(self, address: str) -> str:
address = address.replace("git clone", "")
address = address.strip().rstrip("/")
address = address.replace("git clone", "").strip()
address = address.rstrip("?").rstrip("/")

if os.path.exists(address):
return f"file://{Path(address).resolve()}"
address = f"file://{Path(address).resolve()}"

if address.startswith("file://"):
return address
if address.startswith("git@"):
pass # Don't prepend anything
elif address.startswith("file://"):
pass # Don't prepend anything
elif address.startswith("://"):
address = f"{self._assume_protocol}{address}"
elif not "://" in address:
Expand All @@ -169,8 +173,8 @@ def clone_git_repo(self, address: str, local_path: str) -> bool:
window_icon_path=self._win_icon_path,
timeout_callback=self._handle_progress,
timeout_ms=35,
on_cancel_callback=self._handle_cancel,
expander_label=text.MORE_INFO,
on_cancel_callback=lambda: self._process.kill(),
)

window.run()
Expand All @@ -186,19 +190,18 @@ def run(self) -> None:
if not address or not folder_name:
self.prompt_user_git_address_invalid(address)
exit(1)
else:
log("Info: Address:", address)

log("Info: Address:", address)

folder_name = self.prompt_user_for_cloned_folder_name(folder_name)

if not folder_name:
exit(1)

if folder_name == "":
exit(1) # On user cancel
elif folder_name == "":
self.prompt_user_folder_name_invalid(folder_name)
exit(1)
else:
log("Info: Folder name:", folder_name)

log("Info: Folder name:", folder_name)

self._folder_path = os.path.join(self._directory, folder_name)

Expand All @@ -209,11 +212,15 @@ def run(self) -> None:
self._formatted_address = self._format_address(address)
success = self.clone_git_repo(self._formatted_address, self._folder_path)

if not success or not os.path.exists(self._folder_path):
if self._cancelled and os.path.exists(self._folder_path):
self.prompt_remove_residual_folder_on_clone_canceled(self._folder_path)
exit(0)
elif not success or not os.path.exists(self._folder_path):
self.prompt_unsuccessful_cloning(self._formatted_address)
exit(1)

self.prompt_successful_cloning(self._folder_path)
else:
self.prompt_successful_cloning(self._folder_path)
exit(0)

def _handle_progress(self, user_data, window: aui.ProgressbarDialogWindow) -> bool:
if self._process and self._process.poll() is None:
Expand All @@ -228,13 +235,42 @@ def _handle_progress(self, user_data, window: aui.ProgressbarDialogWindow) -> bo
except UnicodeDecodeError as e:
log("Exception:", e)

if self._process.poll() is not None:
if self._process and self._process.poll() is not None:
window.stop()
window.destroy()
return False

return True

def _handle_cancel(self) -> None:
self._process.kill()
self._cancelled = True

def send_item_to_trash(self, item: Path) -> bool:
try:
file = Gio.File.new_for_path(item.as_posix())
file.trash(cancellable=None)
return True
except Exception as e:
log("Exception:", e)
return False

def prompt_remove_residual_folder_on_clone_canceled(self, folder: str) -> None:
window = aui.QuestionDialogWindow(
title=text.ACTION_TITLE,
message=text.REMOVE_RESIDUAL_FOLDER_ON_CANCEL,
window_icon_path=self._win_icon_path,
)
response = window.run()
window.destroy()

trashed = False
if response == window.RESPONSE_YES:
trashed = self.send_item_to_trash(Path(folder))

res = "was" if trashed else "wasn't"
log(f"Info: residual folder from cancellation {folder!r} {res} sent to trash")

def prompt_successful_cloning(self, folder_path):
log(f"Info: repo {self._formatted_address!r} was successfully cloned")
window = aui.InfoDialogWindow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"uuid": "clone-git-repo@anaximeno",
"name": "Clone git repo",
"author": "anaximeno",
"version": "1.2.1"
"version": "1.3.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.2.0\n"
"Project-Id-Version: clone-git-repo@anaximeno 1.2.1\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -76,6 +76,13 @@ msgstr ""
msgid "More info"
msgstr ""

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: 2024-05-14 17:23-0400\n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down Expand Up @@ -82,6 +82,13 @@ msgstr "Información de clonación"
msgid "More info"
msgstr "Más información"

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: 2024-05-14 14:50-0100\n"
"Last-Translator: Kimmo Kujansuu <mrkujansuu@gmail.com>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -83,6 +83,13 @@ msgstr ""
msgid "More info"
msgstr ""

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: 2024-06-04 13:26+0200\n"
"Last-Translator: Claudiux <claude.clerc@gmail.com>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -83,6 +83,13 @@ msgstr "Infos sur le clonage"
msgid "More info"
msgstr "Plus d'infos"

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: 2024-05-14 14:51-0100\n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down Expand Up @@ -83,6 +83,13 @@ msgstr ""
msgid "More info"
msgstr ""

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: 2024-05-14 14:51-0100\n"
"Last-Translator: qadzek\n"
"Language-Team: \n"
Expand Down Expand Up @@ -82,6 +82,13 @@ msgstr ""
msgid "More info"
msgstr ""

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
17 changes: 14 additions & 3 deletions clone-git-repo@anaximeno/files/clone-git-repo@anaximeno/po/pt.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"PO-Revision-Date: 2024-05-14 14:52-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: 2024-06-08 21:04-0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: pt\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.2\n"
"X-Generator: Poedit 3.4.4\n"

#: text.py:14
msgid "Clone a repository"
Expand Down Expand Up @@ -83,6 +83,17 @@ msgstr "Informações da clonagem"
msgid "More info"
msgstr "Mais informações"

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""
"A operação de clonagem foi cancelada, deixando uma pasta residual. Deve "
"esta pasta ser enviada para o lixo? Por favor, note que devido ao "
"cancelamento, a pasta residual contém apenas uma clonagem incompleta do "
"repositório."

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-05-14 14:49-0100\n"
"PO-Revision-Date: 2024-05-14 14:52-0100\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"PO-Revision-Date: 2024-06-08 21:05-0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: pt_BR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.2\n"
"X-Generator: Poedit 3.4.4\n"

#: text.py:14
msgid "Clone a repository"
Expand Down Expand Up @@ -83,6 +83,17 @@ msgstr "Informações da clonagem"
msgid "More info"
msgstr "Mais informações"

#: text.py:54
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
"the residual folder contains only an incomplete clone of the repository."
msgstr ""
"A operação de clonagem foi cancelada, deixando uma pasta residual. Essa "
"pasta deve ser enviada para a lixeira? Por favor, note que, devido ao "
"cancelamento, a pasta residual contém apenas uma clonagem incompleta do "
"repositório."

#. metadata.json->description
#. clone-git-repo@anaximeno.nemo_action.in->Comment
msgid "Clone a git repository into the current folder."
Expand Down
Loading

0 comments on commit 1747d33

Please sign in to comment.