Skip to content

Commit d032fe9

Browse files
committed
Add working tue-install-ppa-now
1 parent 37c54df commit d032fe9

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

src/tue_get/installer_impl.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def tue_install_target(self, target: str, now: bool = False) -> bool:
431431
else:
432432
self.tue_install_debug(f"Sourcing {install_bash_file}")
433433
resource_file = os.path.join(os.path.dirname(__file__), "resources", "installer_impl.bash")
434-
cmd = f'bash -c \"source {resource_file} && source {install_bash_file}\"'
434+
cmd = f'bash -c "source {resource_file} && source {install_bash_file}"'
435435
sub = self._default_background_popen(cmd)
436436
if sub.returncode != 0:
437437
self.tue_install_error(f"Error while running({sub.returncode}):\n {repr(cmd)}")
@@ -626,7 +626,7 @@ def tue_install_add_text(self, source_file: str, target_file: str) -> bool:
626626
"appending to {target_file_path}"
627627
)
628628
source_text = "\n".join(source_text)
629-
cmd = f"bash -c \"echo - e \'{source_text}\' | {sudo_cmd}tee -a {target_file_path}\""
629+
cmd = f"bash -c \"echo - e '{source_text}' | {sudo_cmd}tee -a {target_file_path}\""
630630
else:
631631
self.tue_install_debug(
632632
f"tue-install-add-text: {begin_tag=} found in {target_file_path=}, "
@@ -648,7 +648,7 @@ def tue_install_add_text(self, source_file: str, target_file: str) -> bool:
648648
print(target_text)
649649
target_text = "\n".join(target_text)
650650

651-
cmd = f"bash -c \"echo -e \'{target_text}\' | {sudo_cmd}tee {target_file_path}\""
651+
cmd = f"bash -c \"echo -e '{target_text}' | {sudo_cmd}tee {target_file_path}\""
652652

653653
cmd, cmds = _which_split_cmd(cmd)
654654
self.tue_install_echo(repr(cmd))
@@ -763,7 +763,54 @@ def tue_install_ppa(self, ppas: List[str]) -> bool:
763763
self._ppas.extend(ppas)
764764
return True
765765

766-
def tue_install_ppa_now(self, ppa: List[str]) -> bool:
766+
def tue_install_ppa_now(self, ppas: List[str]) -> bool:
767+
self.tue_install_debug(f"tue-install-ppa-now {ppas=}")
768+
769+
if not ppas:
770+
self.tue_install_error("Invalid tue-install-ppa-now call: needs ppas as argument")
771+
# ToDo: This depends on behaviour of tue-install-error
772+
return False
773+
774+
ppa_added = False
775+
for ppa in ppas:
776+
if not ppa.startswith("ppa:") and not ppa.startswith("deb "):
777+
self.tue_install_error(f"Invalid ppa: needs to start with 'ppa:' or 'deb ' ({ppa=})")
778+
# ToDo: This depends on behaviour of tue-install-error
779+
return False
780+
781+
if ppa.startswith("ppa:"):
782+
ppa_pattern = f"^deb.*{ppa[4:]}".replace("[", "\[").replace("]", "\]").replace("/", "\/")
783+
ppa_pattern = re.compile(ppa_pattern)
784+
if grep_directory(self._sources_list_dir, ppa_pattern):
785+
self.tue_install_debug(f"PPA '{ppa}' is already added previously")
786+
continue
787+
788+
elif ppa.startswith("deb "):
789+
ppa_pattern = f"^{ppa}$".replace("[", "\[").replace("]", "\]").replace("/", "\/")
790+
ppa_pattern = re.compile(ppa_pattern)
791+
if grep_file(self._sources_list, ppa_pattern):
792+
self.tue_install_debug(f"PPA '{ppa}' is already added previously")
793+
continue
794+
795+
self.tue_install_system_now(["software-properties-common"])
796+
797+
self.tue_install_info(f"Adding ppa: {ppa}")
798+
799+
# Wait for apt-lock first (https://askubuntu.com/a/375031)
800+
_wait_for_dpkg_lock()
801+
802+
cmd = f"sudo add-apt-repository --no-update --yes '{ppa}'"
803+
sub = self._default_background_popen(cmd)
804+
if sub.returncode != 0:
805+
self.tue_install_error(f"An error occurred while adding ppa: {ppa}")
806+
# ToDo: This depends on behaviour of tue-install-error
807+
return False
808+
809+
ppa_added = True
810+
811+
if ppa_added:
812+
self.tue_install_apt_get_update()
813+
767814
return True
768815

769816
def tue_install_pip(self, pkgs: List[str]) -> bool:

0 commit comments

Comments
 (0)