Skip to content

Commit

Permalink
fix display bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Otoupal committed Mar 18, 2024
1 parent ad49e9d commit 9713762
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion abst/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"CLI Command making OCI Bastion and kubernetes usage simple and fast"
)

__version__ = "2.3.52"
__version__ = "2.3.53"
__author__ = "Jiri Otoupal"
__author_email__ = "jiri-otoupal@ips-database.eu"
__license__ = "MIT"
Expand Down
13 changes: 9 additions & 4 deletions abst/bastion_support/oci_bastion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
default_contexts_location, default_conf_path, \
default_conf_contents, get_public_key, default_parallel_sets_location, broadcast_shm_name
from abst.sharing.local_broadcast import LocalBroadcast
from abst.utils.misc_funcs import run_once
from abst.wrappers import mark_on_exit


Expand Down Expand Up @@ -678,10 +679,7 @@ def __run_ssh_tunnel(self, ssh_tunnel_arg_str, shell, already_split=False):
self.connected = False
return False
if "pledge:" in line:
rich.print(f"({self.get_print_name()}) Success !")
rich.print(
f"({self.get_print_name()}) SSH Tunnel Running from "
f"{datetime.datetime.now()}")
self.print_succeeded()
self.connected = True
self.current_status = "connected"
self.tries = 10
Expand Down Expand Up @@ -715,3 +713,10 @@ def __run_ssh_tunnel(self, ssh_tunnel_arg_str, shell, already_split=False):
self.current_status = f"failed {self.tries} left"
self.connected = False
return True

@run_once
def print_succeeded(self):
rich.print(f"({self.get_print_name()}) Success !")
rich.print(
f"({self.get_print_name()}) SSH Tunnel Running from "
f"{datetime.datetime.now()}")
1 change: 1 addition & 0 deletions abst/cli_commands/create_cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ def managed(shell, debug, context_name):
bastion.kill()
exit(0)


_do.add_command(forward)
_do.add_command(managed)
24 changes: 23 additions & 1 deletion abst/utils/misc_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import os
import signal
import subprocess
import threading
from datetime import datetime, timedelta
from functools import wraps
from pathlib import Path
from threading import Thread
from time import sleep
Expand All @@ -11,7 +14,6 @@
import rich
from rich.logging import RichHandler

from abst.bastion_support.oci_bastion import Bastion
from abst.config import default_contexts_location, default_parallel_sets_location


Expand All @@ -34,6 +36,7 @@ def setup_debug(debug):


def print_eligible(searched: str):
from abst.bastion_support.oci_bastion import Bastion
contexts = Bastion.get_contexts()
rich.print("[bold]Configured contexts:[/bold]")
for key, context in contexts.items():
Expand Down Expand Up @@ -169,3 +172,22 @@ def exit_gracefully(bastion, signum, frame):
if bastion is not None:
bastion.kill()
exit(0)


def run_once(func):
"""
A decorator that runs a function only once.
"""

func_last_run = threading.local()
seconds = 10

@wraps(func)
def wrapper(*args, **kwargs):
now = datetime.now()
last_run = getattr(func_last_run, 'last_run', None)
if last_run is None or now - last_run >= timedelta(seconds=seconds):
func_last_run.last_run = now
return func(*args, **kwargs)

return wrapper

0 comments on commit 9713762

Please sign in to comment.