Skip to content

Commit

Permalink
fixed a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Otoupal committed Feb 28, 2024
1 parent dec3866 commit 86150b8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
4 changes: 3 additions & 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.22"
__version__ = "2.3.23"
__author__ = "Jiri Otoupal"
__author_email__ = "jiri-otoupal@ips-database.eu"
__license__ = "MIT"
Expand All @@ -23,4 +23,6 @@
* Sharing and Pasting now works for sets too, you can use set_name/context for both\n
* When pasting, it will ask if you want to change IP and for bastion name renaming\n
* Removed unused packages\n
* Fixed filename .json search\n
* Abst is filtering not json files from context search\n
"""
4 changes: 2 additions & 2 deletions abst/bastion_support/bastion_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def run(cls, force=False, set_dir: Optional[Path] = None):
t.start()
rich.print(f"Started {context_name}")
else:
for context_path in filter(lambda p: not str(p.name).startswith("."), set_dir.iterdir()):
for context_path in filter(lambda p: not str(p.name).startswith(".") and str(p.name).endswith(".json"),
set_dir.iterdir()):
if cls.stopped:
return
context_name = context_path.name[:-5]
Expand All @@ -149,7 +150,6 @@ def run(cls, force=False, set_dir: Optional[Path] = None):
t.start()
rich.print(f"Started {context_name}")


cls.__display_loop()

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion abst/cfg_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __upgrade(context_name, path, _all):

for file in default_contexts_location.iterdir():
append_minimizable(file, minimize_files)
for set_folder in filter(lambda p: not str(p.name).startswith("."), default_parallel_sets_location.iterdir()):
for set_folder in filter(lambda p: not str(p.name).startswith(".") and str(p.name).endswith(".json"),
default_parallel_sets_location.iterdir()):
for file in set_folder.iterdir():
if file.name.startswith(".") or not append_minimizable(file, minimize_files):
continue
Expand Down
13 changes: 9 additions & 4 deletions abst/cli_commands/context/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,28 @@ def display(name, debug=False):
@context.command(
help="Will print context without local paths and put it in clipboard for sharing")
@click.option("--debug", is_flag=True, default=False)
@click.option("--raw", is_flag=True, default=False)
@click.argument("name")
def share(name: str, debug=False):
def share(name: str, debug=False, raw=False):
setup_calls(debug)
rich.print("Copied context into clipboard")

if "/" in name:
data = get_context_set_data(name)
else:
data = get_context_data(name)
if data is None:
return

for key in share_excluded_keys:
data.pop(key, None)
data["default-name"] = "!YOUR NAME!"

if not raw:
rich.print(f"[bold]Context '{name}' config contents:[/bold]\n")
logging.debug("Data transmitted into clipboard")
pyperclip.copy(str(data))
rich.print("Copied context into clipboard")
rich.print_json(data=data)
logging.debug("Data transmitted into clipboard")
pyperclip.copy(str(data))


@context.command(help="Will paste context from clipboard into provided context name")
Expand Down
2 changes: 1 addition & 1 deletion abst/cli_commands/parallel/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _list(debug):
setup_calls(debug)
rich.print("Sets in parallel folder")
for _set in default_parallel_sets_location.iterdir():
if _set.name.startswith("."):
if _set.name.startswith(".") and not _set.name.endswith(".json"):
continue
rich.print(f" {_set.name}")
for ctx in _set.iterdir():
Expand Down
2 changes: 1 addition & 1 deletion abst/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def display_scheduled(set_dir: Optional[Path] = None):
table.add_column("Active", justify="right", style="green", no_wrap=True)
table.add_column("Status", justify="right", style="green", no_wrap=True)
if set_dir:
for context_path in filter(lambda p: not str(p.name).startswith("."),
for context_path in filter(lambda p: not str(p.name).startswith(".") and str(p.name).endswith(".json"),
set_dir.iterdir()):
conf = Bastion.load_json(context_path)
context_name = context_path.name[:-5]
Expand Down
21 changes: 11 additions & 10 deletions abst/utils/misc_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def print_eligible(searched: str):


def get_context_data(name) -> Optional[dict]:
if name in [file.name.replace(".json", "") for file in
Path(default_contexts_location).iterdir()]:
rich.print("[bold]Context config contents:[/bold]\n")
with open(Path(default_contexts_location) / (name + ".json"), "r") as f:
normalized_name = name if ".json" in name else name + ".json"
if normalized_name in [file.name for file in
Path(default_contexts_location).iterdir()]:
with open(Path(default_contexts_location) / normalized_name, "r") as f:
data = json.load(f)
return data
else:
Expand All @@ -63,13 +63,14 @@ def get_context_set_data(name) -> Optional[dict]:
if len(path) != 2:
rich.print(f"[red]Invalid path '{name}'[/red]")

if path[0] in [file.name for file in
Path(default_parallel_sets_location).iterdir()]:
if path[1] in [file.name.replace(".json", "") for file in
Path(default_parallel_sets_location / path[0]).iterdir()]:
rich.print(f"[bold]Context '{name}' config contents:[/bold]\n")
set_dir_name = path[0]
if set_dir_name in [file.name for file in
Path(default_parallel_sets_location).iterdir()]:
normalized_name = path[1] if ".json" in path[1] else path[1] + ".json"
if normalized_name in [file.name for file in
Path(default_parallel_sets_location / set_dir_name).iterdir()]:
with open(
Path(default_parallel_sets_location) / path[0] / (path[1] + ".json"),
Path(default_parallel_sets_location) / set_dir_name / normalized_name,
"r") as f:
data = json.load(f)
return data
Expand Down

0 comments on commit 86150b8

Please sign in to comment.