machineconfig 2.1__py3-none-any.whl ā 2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of machineconfig might be problematic. Click here for more details.
- machineconfig/cluster/sessions_managers/enhanced_command_runner.py +0 -2
- machineconfig/cluster/sessions_managers/layout_types.py +29 -0
- machineconfig/cluster/sessions_managers/wt_local.py +68 -62
- machineconfig/cluster/sessions_managers/wt_local_manager.py +51 -22
- machineconfig/cluster/sessions_managers/wt_remote.py +30 -108
- machineconfig/cluster/sessions_managers/wt_remote_manager.py +14 -11
- machineconfig/cluster/sessions_managers/wt_utils/layout_generator.py +33 -37
- machineconfig/cluster/sessions_managers/wt_utils/process_monitor.py +22 -17
- machineconfig/cluster/sessions_managers/wt_utils/session_manager.py +59 -10
- machineconfig/cluster/sessions_managers/wt_utils/status_reporter.py +16 -14
- machineconfig/cluster/sessions_managers/zellij_local.py +75 -57
- machineconfig/cluster/sessions_managers/zellij_local_manager.py +51 -23
- machineconfig/cluster/sessions_managers/zellij_remote.py +47 -27
- machineconfig/cluster/sessions_managers/zellij_remote_manager.py +13 -12
- machineconfig/cluster/sessions_managers/zellij_utils/example_usage.py +14 -10
- machineconfig/cluster/sessions_managers/zellij_utils/layout_generator.py +31 -15
- machineconfig/cluster/sessions_managers/zellij_utils/process_monitor.py +47 -21
- machineconfig/cluster/sessions_managers/zellij_utils/session_manager.py +1 -1
- machineconfig/cluster/sessions_managers/zellij_utils/status_reporter.py +8 -7
- machineconfig/cluster/templates/utils.py +0 -35
- machineconfig/jobs/python/check_installations.py +1 -1
- machineconfig/jobs/python_custom_installers/dev/code.py +0 -13
- machineconfig/jobs/python_generic_installers/config.json +1 -1
- machineconfig/profile/create.py +13 -4
- machineconfig/profile/create_hardlinks.py +3 -1
- machineconfig/profile/shell.py +8 -7
- machineconfig/scripts/__init__.py +0 -2
- machineconfig/scripts/linux/devops +6 -4
- machineconfig/scripts/python/ai/generate_files.py +14 -15
- machineconfig/scripts/python/ai/mcinit.py +8 -5
- machineconfig/scripts/python/archive/tmate_conn.py +5 -5
- machineconfig/scripts/python/archive/tmate_start.py +7 -7
- machineconfig/scripts/python/choose_wezterm_theme.py +35 -32
- machineconfig/scripts/python/cloud_copy.py +22 -13
- machineconfig/scripts/python/cloud_mount.py +35 -23
- machineconfig/scripts/python/cloud_repo_sync.py +38 -25
- machineconfig/scripts/python/cloud_sync.py +4 -4
- machineconfig/scripts/python/croshell.py +37 -28
- machineconfig/scripts/python/devops.py +46 -27
- machineconfig/scripts/python/devops_add_identity.py +15 -25
- machineconfig/scripts/python/devops_add_ssh_key.py +7 -7
- machineconfig/scripts/python/devops_backup_retrieve.py +17 -15
- machineconfig/scripts/python/devops_devapps_install.py +26 -20
- machineconfig/scripts/python/devops_update_repos.py +142 -57
- machineconfig/scripts/python/dotfile.py +16 -14
- machineconfig/scripts/python/fire_agents.py +30 -23
- machineconfig/scripts/python/fire_jobs.py +86 -98
- machineconfig/scripts/python/fire_jobs_args_helper.py +84 -0
- machineconfig/scripts/python/fire_jobs_layout_helper.py +66 -0
- machineconfig/scripts/python/ftpx.py +24 -14
- machineconfig/scripts/python/get_zellij_cmd.py +8 -7
- machineconfig/scripts/python/helpers/cloud_helpers.py +33 -28
- machineconfig/scripts/python/helpers/helpers2.py +25 -14
- machineconfig/scripts/python/helpers/helpers4.py +44 -31
- machineconfig/scripts/python/helpers/helpers5.py +1 -1
- machineconfig/scripts/python/helpers/repo_sync_helpers.py +31 -9
- machineconfig/scripts/python/mount_nfs.py +8 -15
- machineconfig/scripts/python/mount_nw_drive.py +10 -5
- machineconfig/scripts/python/mount_ssh.py +8 -6
- machineconfig/scripts/python/repos.py +215 -57
- machineconfig/scripts/python/snapshot.py +0 -1
- machineconfig/scripts/python/start_slidev.py +10 -5
- machineconfig/scripts/python/start_terminals.py +22 -16
- machineconfig/scripts/python/viewer_template.py +0 -1
- machineconfig/scripts/python/wifi_conn.py +49 -76
- machineconfig/scripts/python/wsl_windows_transfer.py +8 -6
- machineconfig/settings/lf/linux/lfrc +1 -0
- machineconfig/setup_linux/web_shortcuts/croshell.sh +5 -0
- machineconfig/setup_linux/web_shortcuts/interactive.sh +1 -1
- machineconfig/setup_linux/web_shortcuts/ssh.sh +0 -4
- machineconfig/setup_windows/wt_and_pwsh/set_pwsh_theme.py +3 -12
- machineconfig/setup_windows/wt_and_pwsh/set_wt_settings.py +1 -1
- machineconfig/utils/code.py +2 -3
- machineconfig/utils/installer.py +2 -2
- machineconfig/utils/installer_utils/installer_abc.py +2 -4
- machineconfig/utils/installer_utils/installer_class.py +6 -4
- machineconfig/utils/links.py +103 -33
- machineconfig/utils/notifications.py +52 -38
- machineconfig/utils/options.py +14 -21
- machineconfig/utils/path.py +12 -12
- machineconfig/utils/path_reduced.py +239 -200
- machineconfig/utils/procs.py +1 -1
- machineconfig/utils/source_of_truth.py +27 -0
- machineconfig/utils/ssh.py +9 -19
- machineconfig/utils/terminal.py +4 -2
- machineconfig/utils/upgrade_packages.py +91 -0
- machineconfig/utils/utils2.py +1 -2
- machineconfig/utils/utils5.py +23 -11
- machineconfig/utils/ve.py +4 -1
- {machineconfig-2.1.dist-info ā machineconfig-2.3.dist-info}/METADATA +13 -13
- {machineconfig-2.1.dist-info ā machineconfig-2.3.dist-info}/RECORD +105 -121
- machineconfig-2.3.dist-info/entry_points.txt +2 -0
- machineconfig/cluster/sessions_managers/archive/create_zellij_template.py +0 -59
- machineconfig/cluster/sessions_managers/archive/session_managers.py +0 -183
- machineconfig/cluster/sessions_managers/demo_rich_zellij.py +0 -0
- machineconfig/jobs/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/jobs/python_custom_installers/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/jobs/python_generic_installers/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/jobs/python_linux_installers/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/scripts/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/scripts/python/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/scripts/python/__pycache__/croshell.cpython-313.pyc +0 -0
- machineconfig/scripts/python/__pycache__/devops.cpython-313.pyc +0 -0
- machineconfig/scripts/python/__pycache__/devops_devapps_install.cpython-313.pyc +0 -0
- machineconfig/scripts/python/__pycache__/devops_update_repos.cpython-313.pyc +0 -0
- machineconfig/scripts/python/__pycache__/fire_jobs.cpython-313.pyc +0 -0
- machineconfig/scripts/python/ai/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/scripts/python/ai/__pycache__/generate_files.cpython-313.pyc +0 -0
- machineconfig/scripts/python/ai/__pycache__/mcinit.cpython-313.pyc +0 -0
- machineconfig/scripts/python/helpers/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/scripts/python/helpers/__pycache__/helpers4.cpython-313.pyc +0 -0
- machineconfig/setup_linux/web_shortcuts/all.sh +0 -48
- machineconfig/setup_linux/web_shortcuts/update_system.sh +0 -48
- machineconfig/utils/utils.py +0 -97
- /machineconfig/cluster/{cloud_manager.py ā remote/cloud_manager.py} +0 -0
- /machineconfig/cluster/{data_transfer.py ā remote/data_transfer.py} +0 -0
- /machineconfig/cluster/{distribute.py ā remote/distribute.py} +0 -0
- /machineconfig/cluster/{file_manager.py ā remote/file_manager.py} +0 -0
- /machineconfig/cluster/{job_params.py ā remote/job_params.py} +0 -0
- /machineconfig/cluster/{loader_runner.py ā remote/loader_runner.py} +0 -0
- /machineconfig/cluster/{remote_machine.py ā remote/remote_machine.py} +0 -0
- /machineconfig/cluster/{script_execution.py ā remote/script_execution.py} +0 -0
- /machineconfig/cluster/{script_notify_upon_completion.py ā remote/script_notify_upon_completion.py} +0 -0
- /machineconfig/{cluster/sessions_managers/archive/__init__.py ā scripts/python/fire_jobs_streamlit_helper.py} +0 -0
- /machineconfig/setup_linux/web_shortcuts/{tmp.sh ā android.sh} +0 -0
- {machineconfig-2.1.dist-info ā machineconfig-2.3.dist-info}/WHEEL +0 -0
- {machineconfig-2.1.dist-info ā machineconfig-2.3.dist-info}/top_level.txt +0 -0
|
@@ -7,7 +7,8 @@ from machineconfig.utils.terminal import Terminal
|
|
|
7
7
|
from machineconfig.utils.utils2 import randstr, read_ini
|
|
8
8
|
|
|
9
9
|
from machineconfig.scripts.python.helpers.repo_sync_helpers import fetch_dotfiles
|
|
10
|
-
from machineconfig.utils.
|
|
10
|
+
from machineconfig.utils.source_of_truth import CONFIG_PATH, DEFAULTS_PATH, PROGRAM_PATH
|
|
11
|
+
from machineconfig.utils.options import choose_one_option
|
|
11
12
|
from machineconfig.utils.code import get_shell_file_executing_python_script, write_shell_script_to_file
|
|
12
13
|
import platform
|
|
13
14
|
import argparse
|
|
@@ -20,24 +21,23 @@ console = Console()
|
|
|
20
21
|
_ = fetch_dotfiles
|
|
21
22
|
|
|
22
23
|
|
|
23
|
-
def main(cloud: Optional[str] = None, path: Optional[str] = None, message: Optional[str] = None,
|
|
24
|
-
action: Literal["ask", "pushLocalMerge", "overwriteLocal", "InspectRepos", "RemoveLocalRclone"] = "ask",
|
|
25
|
-
pwd: Optional[str] = None):
|
|
24
|
+
def main(cloud: Optional[str] = None, path: Optional[str] = None, message: Optional[str] = None, action: Literal["ask", "pushLocalMerge", "overwriteLocal", "InspectRepos", "RemoveLocalRclone"] = "ask", pwd: Optional[str] = None):
|
|
26
25
|
if cloud is None:
|
|
27
26
|
try:
|
|
28
|
-
cloud_resolved = read_ini(DEFAULTS_PATH)[
|
|
27
|
+
cloud_resolved = read_ini(DEFAULTS_PATH)["general"]["rclone_config_name"]
|
|
29
28
|
console.print(Panel(f"ā ļø Using default cloud: `{cloud_resolved}` from {DEFAULTS_PATH}", title="Default Cloud", border_style="yellow"))
|
|
30
29
|
except FileNotFoundError:
|
|
31
30
|
console.print(Panel(f"ā ERROR: No cloud profile found\nLocation: {DEFAULTS_PATH}\nPlease set one up or provide one via the --cloud flag.", title="Error", border_style="red"))
|
|
32
31
|
return ""
|
|
33
|
-
else:
|
|
32
|
+
else:
|
|
33
|
+
cloud_resolved = cloud
|
|
34
34
|
|
|
35
35
|
# repo_root = PathExtended(args.repo).expanduser().absolute()
|
|
36
36
|
repo_local_root = PathExtended.cwd() if path is None else PathExtended(path).expanduser().absolute()
|
|
37
37
|
repo_local_obj = git.Repo(repo_local_root, search_parent_directories=True)
|
|
38
38
|
repo_local_root = PathExtended(repo_local_obj.working_dir) # cwd might have been in a sub directory of repo_root, so its better to redefine it.
|
|
39
|
-
CONFIG_PATH.joinpath("remote").mkdir(parents=True, exist_ok=True)
|
|
40
|
-
repo_remote_root = CONFIG_PATH.joinpath("remote", repo_local_root.rel2home()) # .delete(sure=True)
|
|
39
|
+
PathExtended(CONFIG_PATH).joinpath("remote").mkdir(parents=True, exist_ok=True)
|
|
40
|
+
repo_remote_root = PathExtended(CONFIG_PATH).joinpath("remote", repo_local_root.rel2home()) # .delete(sure=True)
|
|
41
41
|
|
|
42
42
|
try:
|
|
43
43
|
console.print(Panel("š„ DOWNLOADING REMOTE REPOSITORY", title_align="left", border_style="blue"))
|
|
@@ -80,6 +80,7 @@ git pull originEnc master
|
|
|
80
80
|
console.print(Panel("ā
Pull succeeded!\nš§¹ Removing originEnc remote and local copy\nš¤ Pushing merged repository to cloud storage", title="Success", border_style="green"))
|
|
81
81
|
repo_remote_root.delete(sure=True)
|
|
82
82
|
from git.remote import Remote
|
|
83
|
+
|
|
83
84
|
Remote.remove(repo_local_obj, "originEnc")
|
|
84
85
|
repo_local_root.to_cloud(cloud=cloud_resolved, zip=True, encrypt=True, rel2home=True, pwd=pwd, os_specific=False)
|
|
85
86
|
return "success"
|
|
@@ -87,20 +88,21 @@ git pull originEnc master
|
|
|
87
88
|
console.print(Panel(f"ā ļø MERGE FAILED\nš¾ Keeping local copy of remote at:\nš {repo_remote_root}", title="Merge Failed", border_style="red"))
|
|
88
89
|
|
|
89
90
|
# ================================================================================
|
|
90
|
-
option1 =
|
|
91
|
+
option1 = "Delete remote copy and push local:"
|
|
91
92
|
program_1_py = f"""
|
|
92
93
|
from machineconfig.scripts.python.helpers.repo_sync_helpers import delete_remote_repo_copy_and_push_local as func
|
|
93
94
|
func(remote_repo=r'{str(repo_remote_root)}', local_repo=r'{str(repo_local_root)}', cloud=r'{cloud_resolved}')
|
|
94
95
|
"""
|
|
95
|
-
shell_file_1 = get_shell_file_executing_python_script(python_script=program_1_py, ve_path=str(Path.home().joinpath("code", "
|
|
96
|
+
shell_file_1 = get_shell_file_executing_python_script(python_script=program_1_py, ve_path=str(Path.home().joinpath("code", "machineconfig", ".venv")))
|
|
96
97
|
# ================================================================================
|
|
97
98
|
|
|
98
|
-
option2 =
|
|
99
|
+
option2 = "Delete local repo and replace it with remote copy:"
|
|
99
100
|
program_2 = f"""
|
|
100
101
|
rm -rfd {repo_local_root}
|
|
101
102
|
mv {repo_remote_root} {repo_local_root}
|
|
102
103
|
"""
|
|
103
|
-
if platform.system() in ["Linux", "Darwin"]:
|
|
104
|
+
if platform.system() in ["Linux", "Darwin"]:
|
|
105
|
+
program_2 += """
|
|
104
106
|
sudo chmod 600 $HOME/.ssh/*
|
|
105
107
|
sudo chmod 700 $HOME/.ssh
|
|
106
108
|
sudo chmod +x $HOME/dotfiles/scripts/linux -R
|
|
@@ -109,15 +111,15 @@ sudo chmod +x $HOME/dotfiles/scripts/linux -R
|
|
|
109
111
|
shell_file_2 = write_shell_script_to_file(shell_script=program_2)
|
|
110
112
|
|
|
111
113
|
# ================================================================================
|
|
112
|
-
option3 =
|
|
114
|
+
option3 = "Inspect repos:"
|
|
113
115
|
program_3_py = f"""
|
|
114
116
|
from machineconfig.scripts.python.helper.repo_sync_helpers import inspect_repos as func
|
|
115
117
|
func(repo_local_root=r'{str(repo_local_root)}', repo_remote_root=r'{str(repo_remote_root)}')
|
|
116
118
|
"""
|
|
117
|
-
shell_file_3 = get_shell_file_executing_python_script(python_script=program_3_py, ve_path=str(Path.home().joinpath("code", "
|
|
119
|
+
shell_file_3 = get_shell_file_executing_python_script(python_script=program_3_py, ve_path=str(Path.home().joinpath("code", "machineconfig", ".venv")))
|
|
118
120
|
# ================================================================================
|
|
119
121
|
|
|
120
|
-
option4 =
|
|
122
|
+
option4 = "Remove problematic rclone file from repo and replace with remote:"
|
|
121
123
|
program_4 = f"""
|
|
122
124
|
rm $HOME/dotfiles/creds/rclone/rclone.conf
|
|
123
125
|
cp $HOME/.config/machineconfig/remote/dotfiles/creds/rclone/rclone.conf $HOME/dotfiles/creds/rclone
|
|
@@ -139,26 +141,36 @@ git commit -am "finished merging"
|
|
|
139
141
|
match action:
|
|
140
142
|
case "ask":
|
|
141
143
|
choice = choose_one_option(options=[option1, option2, option3, option4], fzf=False)
|
|
142
|
-
if choice == option1:
|
|
143
|
-
|
|
144
|
-
elif choice ==
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
if choice == option1:
|
|
145
|
+
program_content = shell_file_1.read_text(encoding="utf-8")
|
|
146
|
+
elif choice == option2:
|
|
147
|
+
program_content = program_2
|
|
148
|
+
elif choice == option3:
|
|
149
|
+
program_content = shell_file_3.read_text(encoding="utf-8")
|
|
150
|
+
elif choice == option4:
|
|
151
|
+
program_content = program_4
|
|
152
|
+
else:
|
|
153
|
+
raise NotImplementedError(f"Choice {choice} not implemented.")
|
|
154
|
+
case "pushLocalMerge":
|
|
155
|
+
program_content = shell_file_1.read_text(encoding="utf-8")
|
|
156
|
+
case "overwriteLocal":
|
|
157
|
+
program_content = program_2
|
|
158
|
+
case "InspectRepos":
|
|
159
|
+
program_content = shell_file_3.read_text(encoding="utf-8")
|
|
160
|
+
case "RemoveLocalRclone":
|
|
161
|
+
program_content = program_4
|
|
151
162
|
case _:
|
|
152
163
|
raise ValueError(f"Unknown action: {action}")
|
|
153
164
|
PROGRAM_PATH.write_text(program_content, encoding="utf-8")
|
|
154
165
|
return program_content
|
|
155
166
|
|
|
167
|
+
|
|
156
168
|
def args_parser():
|
|
157
169
|
console.print(Panel("š Repository Synchronization Utility", title_align="left", border_style="blue"))
|
|
158
170
|
|
|
159
171
|
parser = argparse.ArgumentParser(description="Secure Repo CLI.")
|
|
160
172
|
# parser.add_argument("cmd", help="command to run", choices=["pull", "push"])
|
|
161
|
-
parser.add_argument("path", nargs=
|
|
173
|
+
parser.add_argument("path", nargs="?", type=str, help="Repository path, defaults to cwd.", default=None)
|
|
162
174
|
# parser.add_argument("--share", help="Repository path, defaults to cwd.", action="store_true", default=False)
|
|
163
175
|
parser.add_argument("--cloud", "-c", help="rclone cloud profile name.", default=None)
|
|
164
176
|
parser.add_argument("--message", "-m", help="Commit Message", default=f"new message {randstr()}")
|
|
@@ -170,5 +182,6 @@ def args_parser():
|
|
|
170
182
|
args = parser.parse_args()
|
|
171
183
|
main(cloud=args.cloud, path=args.path, message=args.message, action=args.action)
|
|
172
184
|
|
|
185
|
+
|
|
173
186
|
if __name__ == "__main__":
|
|
174
187
|
args_parser()
|
|
@@ -5,7 +5,7 @@ TODO: use typer or typed-argument-parser to parse args
|
|
|
5
5
|
from machineconfig.scripts.python.helpers.helpers2 import parse_cloud_source_target
|
|
6
6
|
from machineconfig.scripts.python.helpers.cloud_helpers import Args
|
|
7
7
|
from machineconfig.scripts.python.cloud_mount import get_mprocs_mount_txt
|
|
8
|
-
from machineconfig.utils.
|
|
8
|
+
from machineconfig.utils.source_of_truth import PROGRAM_PATH
|
|
9
9
|
import argparse
|
|
10
10
|
from rich.console import Console
|
|
11
11
|
from rich.panel import Panel
|
|
@@ -57,9 +57,9 @@ def args_parser():
|
|
|
57
57
|
target_line = f"Target: {target}"
|
|
58
58
|
console.print(Panel(f"{source_line}\n{arrow_line}\n{target_line}", title=title, border_style="blue"))
|
|
59
59
|
if delete:
|
|
60
|
-
rclone_cmd = f
|
|
60
|
+
rclone_cmd = f'rclone sync -P "{source}" "{target}" --delete-during --transfers={transfers}'
|
|
61
61
|
else:
|
|
62
|
-
rclone_cmd = f
|
|
62
|
+
rclone_cmd = f'rclone sync -P "{source}" "{target}" --transfers={transfers}'
|
|
63
63
|
|
|
64
64
|
rclone_cmd += f" --progress --transfers={transfers} --verbose"
|
|
65
65
|
# rclone_cmd += f" --vfs-cache-mode full"
|
|
@@ -78,5 +78,5 @@ def args_parser():
|
|
|
78
78
|
PROGRAM_PATH.write_text(txt, encoding="utf-8")
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
if __name__ ==
|
|
81
|
+
if __name__ == "__main__":
|
|
82
82
|
args_parser()
|
|
@@ -7,12 +7,13 @@ croshell
|
|
|
7
7
|
import argparse
|
|
8
8
|
from machineconfig.utils.path_reduced import PathExtended as PathExtended
|
|
9
9
|
from machineconfig.utils.utils2 import randstr
|
|
10
|
-
from machineconfig.utils.
|
|
11
|
-
from machineconfig.utils.
|
|
10
|
+
from machineconfig.utils.source_of_truth import PROGRAM_PATH
|
|
11
|
+
from machineconfig.utils.options import display_options
|
|
12
|
+
from machineconfig.utils.ve import get_ve_activate_line
|
|
12
13
|
from typing import Optional
|
|
13
14
|
from rich.console import Console
|
|
14
15
|
from rich.panel import Panel
|
|
15
|
-
from rich.text import Text
|
|
16
|
+
from rich.text import Text # Added import for rich.text
|
|
16
17
|
# from machineconfig.utils.utils2 import pprint
|
|
17
18
|
|
|
18
19
|
console = Console()
|
|
@@ -61,14 +62,16 @@ except Exception as e:
|
|
|
61
62
|
"""
|
|
62
63
|
|
|
63
64
|
|
|
64
|
-
def get_read_pyfile_pycode(path: PathExtended, as_module: bool, cmd: str=""):
|
|
65
|
-
if as_module:
|
|
65
|
+
def get_read_pyfile_pycode(path: PathExtended, as_module: bool, cmd: str = ""):
|
|
66
|
+
if as_module:
|
|
67
|
+
pycode = rf"""
|
|
66
68
|
import sys
|
|
67
69
|
sys.path.append(r'{path.parent}')
|
|
68
70
|
from {path.stem} import *
|
|
69
71
|
{cmd}
|
|
70
72
|
"""
|
|
71
|
-
else:
|
|
73
|
+
else:
|
|
74
|
+
pycode = f"""
|
|
72
75
|
__file__ = PathExtended(r'{path}')
|
|
73
76
|
{path.read_text(encoding="utf-8")}
|
|
74
77
|
"""
|
|
@@ -78,7 +81,7 @@ __file__ = PathExtended(r'{path}')
|
|
|
78
81
|
def build_parser():
|
|
79
82
|
parser = argparse.ArgumentParser(description="Generic Parser to launch crocodile shell.")
|
|
80
83
|
# A FLAG:
|
|
81
|
-
parser.add_argument("--module",
|
|
84
|
+
parser.add_argument("--module", "-m", help="flag to run the file as a module as opposed to main.", action="store_true", default=False) # default is running as main, unless indicated by --module flag.
|
|
82
85
|
parser.add_argument("--newWindow", "-w", help="flag for running in new window.", action="store_true", default=False)
|
|
83
86
|
parser.add_argument("--nonInteratctive", "-N", help="flag for a non-interactive session.", action="store_true", default=False)
|
|
84
87
|
parser.add_argument("--python", "-p", help="flag to use python over IPython.", action="store_true", default=False)
|
|
@@ -100,8 +103,8 @@ def build_parser():
|
|
|
100
103
|
|
|
101
104
|
# ==================================================================================
|
|
102
105
|
# flags processing
|
|
103
|
-
interactivity =
|
|
104
|
-
interpreter =
|
|
106
|
+
interactivity = "" if args.nonInteratctive else "-i"
|
|
107
|
+
interpreter = "python" if args.python else "ipython"
|
|
105
108
|
ipython_profile: Optional[str] = args.profile
|
|
106
109
|
file = PathExtended.cwd() # initialization value, could be modified according to args.
|
|
107
110
|
|
|
@@ -109,15 +112,16 @@ def build_parser():
|
|
|
109
112
|
text = "š„ļø Executing command from CLI argument"
|
|
110
113
|
console.print(Panel(text, title="[bold blue]Info[/bold blue]"))
|
|
111
114
|
import textwrap
|
|
115
|
+
|
|
112
116
|
program = textwrap.dedent(args.cmd)
|
|
113
117
|
|
|
114
118
|
elif args.fzf:
|
|
115
119
|
text = "š Searching for Python files..."
|
|
116
120
|
console.print(Panel(text, title="[bold blue]Info[/bold blue]"))
|
|
117
121
|
options = [str(item) for item in PathExtended.cwd().search("*.py", r=True)]
|
|
118
|
-
file = display_options(msg="Choose a python file to run", options=options, fzf=True, multi=False
|
|
122
|
+
file = display_options(msg="Choose a python file to run", options=options, fzf=True, multi=False)
|
|
119
123
|
assert isinstance(file, str)
|
|
120
|
-
program = PathExtended(file).read_text(encoding=
|
|
124
|
+
program = PathExtended(file).read_text(encoding="utf-8")
|
|
121
125
|
text = f"š Selected file: {PathExtended(file).name}"
|
|
122
126
|
console.print(Panel(text, title="[bold blue]Info[/bold blue]"))
|
|
123
127
|
|
|
@@ -130,16 +134,16 @@ def build_parser():
|
|
|
130
134
|
|
|
131
135
|
elif args.read != "":
|
|
132
136
|
if args.streamlit_viewer:
|
|
133
|
-
# text = "š STARTING STREAMLIT VIEWER"
|
|
134
|
-
# console.print(Panel(text, title="[bold blue]Info[/bold blue]"))
|
|
135
|
-
# from machineconfig.scripts.python.viewer import run
|
|
136
|
-
# py_file_path = run(data_path=args.read, data=None, get_figure=None)
|
|
137
|
-
# final_program = f"""
|
|
138
|
-
# #!/bin/bash
|
|
139
|
-
# . $HOME/scripts/activate_ve '.venv'
|
|
140
|
-
# streamlit run {py_file_path}
|
|
141
|
-
# """
|
|
142
|
-
# PROGRAM_PATH.write_text(data=final_program, encoding="utf-8")
|
|
137
|
+
# text = "š STARTING STREAMLIT VIEWER"
|
|
138
|
+
# console.print(Panel(text, title="[bold blue]Info[/bold blue]"))
|
|
139
|
+
# from machineconfig.scripts.python.viewer import run
|
|
140
|
+
# py_file_path = run(data_path=args.read, data=None, get_figure=None)
|
|
141
|
+
# final_program = f"""
|
|
142
|
+
# #!/bin/bash
|
|
143
|
+
# . $HOME/scripts/activate_ve '.venv'
|
|
144
|
+
# streamlit run {py_file_path}
|
|
145
|
+
# """
|
|
146
|
+
# PROGRAM_PATH.write_text(data=final_program, encoding="utf-8")
|
|
143
147
|
return None
|
|
144
148
|
file = PathExtended(str(args.read).lstrip()).expanduser().absolute()
|
|
145
149
|
program = get_read_data_pycode(str(file))
|
|
@@ -158,24 +162,29 @@ def build_parser():
|
|
|
158
162
|
|
|
159
163
|
#%%
|
|
160
164
|
from crocodile.croshell import *
|
|
165
|
+
from pathlib import Path
|
|
161
166
|
print_header()
|
|
162
167
|
print_logo(logo="crocodile")
|
|
168
|
+
print(f"š Crocodile Shell | Running @ {Path.cwd()}")
|
|
163
169
|
"""
|
|
164
170
|
|
|
165
171
|
pyfile = PathExtended.tmp().joinpath(f"tmp_scripts/python/croshell/{randstr()}.py")
|
|
166
172
|
pyfile.parent.mkdir(parents=True, exist_ok=True)
|
|
167
173
|
|
|
168
|
-
if args.read != "":
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
if args.read != "":
|
|
175
|
+
title = "Reading Data"
|
|
176
|
+
elif args.file != "":
|
|
177
|
+
title = "Running Python File"
|
|
178
|
+
else:
|
|
179
|
+
title = "Executed code"
|
|
171
180
|
total_program = preprogram + add_print_header_pycode(str(pyfile), title=title) + program
|
|
172
181
|
|
|
173
|
-
pyfile.write_text(total_program, encoding=
|
|
182
|
+
pyfile.write_text(total_program, encoding="utf-8")
|
|
174
183
|
|
|
175
|
-
ve_root_from_file, ipython_profile = get_ve_path_and_ipython_profile(PathExtended(file))
|
|
184
|
+
# ve_root_from_file, ipython_profile = get_ve_path_and_ipython_profile(PathExtended(file))
|
|
176
185
|
ipython_profile = ipython_profile if ipython_profile is not None else "default"
|
|
177
186
|
# ve_activateion_line = get_ve_activate_line(ve_name=args.ve or ve_profile_suggested, a_path=str(PathExtended.cwd()))
|
|
178
|
-
activate_ve_line
|
|
187
|
+
activate_ve_line = get_ve_activate_line(ve_root="$HOME/code/machineconfig/.venv")
|
|
179
188
|
final_program = f"""
|
|
180
189
|
#!/bin/bash
|
|
181
190
|
|
|
@@ -202,7 +211,7 @@ print_logo(logo="crocodile")
|
|
|
202
211
|
# (PROGRAM_PATH + ".py").write_text(str(pyfile), encoding='utf-8')
|
|
203
212
|
|
|
204
213
|
# if platform.system() == "Windows":
|
|
205
|
-
|
|
214
|
+
# return subprocess.run([f"powershell", "-Command", res], shell=True, capture_output=False, text=True, check=True)
|
|
206
215
|
# else: return subprocess.run([res], shell=True, capture_output=False, text=True, check=True)
|
|
207
216
|
|
|
208
217
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
"""devops with emojis
|
|
2
|
-
"""
|
|
1
|
+
"""devops with emojis"""
|
|
3
2
|
|
|
4
|
-
from machineconfig.utils.
|
|
3
|
+
from machineconfig.utils.options import display_options
|
|
4
|
+
from machineconfig.utils.source_of_truth import PROGRAM_PATH
|
|
5
|
+
from machineconfig.utils.code import write_shell_script_to_default_program_path
|
|
5
6
|
from platform import system
|
|
6
7
|
from enum import Enum
|
|
7
8
|
from typing import Optional
|
|
8
9
|
from rich.console import Console
|
|
9
10
|
from rich.panel import Panel
|
|
10
|
-
from rich import box
|
|
11
|
+
from rich import box # Import box
|
|
11
12
|
|
|
12
13
|
console = Console()
|
|
13
14
|
|
|
@@ -15,19 +16,19 @@ BOX_WIDTH = 150 # width for box drawing
|
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
class Options(Enum):
|
|
18
|
-
update
|
|
19
|
-
cli_install
|
|
20
|
-
sym_path_shell =
|
|
21
|
-
sym_new
|
|
22
|
-
ssh_add_pubkey =
|
|
23
|
-
ssh_add_id
|
|
24
|
-
ssh_use_pair
|
|
25
|
-
ssh_setup
|
|
26
|
-
ssh_setup_wsl
|
|
27
|
-
dot_files_sync =
|
|
28
|
-
backup
|
|
29
|
-
retreive
|
|
30
|
-
scheduler
|
|
19
|
+
update = "š UPDATE essential repos"
|
|
20
|
+
cli_install = "āļø DEVAPPS install"
|
|
21
|
+
sym_path_shell = "š SYMLINKS, PATH & SHELL PROFILE"
|
|
22
|
+
sym_new = "š SYMLINKS new"
|
|
23
|
+
ssh_add_pubkey = "š SSH add pub key to this machine"
|
|
24
|
+
ssh_add_id = "šļø SSH add identity (private key) to this machine"
|
|
25
|
+
ssh_use_pair = "š SSH use key pair to connect two machines"
|
|
26
|
+
ssh_setup = "š” SSH setup"
|
|
27
|
+
ssh_setup_wsl = "š§ SSH setup wsl"
|
|
28
|
+
dot_files_sync = "š DOTFILES sync"
|
|
29
|
+
backup = "š¾ BACKUP"
|
|
30
|
+
retreive = "š„ RETRIEVE"
|
|
31
|
+
scheduler = "ā° SCHEDULER"
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
def args_parser():
|
|
@@ -35,6 +36,7 @@ def args_parser():
|
|
|
35
36
|
console.print(Panel("š ļø DevOps Tool Suite", title_align="left", border_style="blue", width=BOX_WIDTH))
|
|
36
37
|
|
|
37
38
|
import argparse
|
|
39
|
+
|
|
38
40
|
parser = argparse.ArgumentParser()
|
|
39
41
|
new_line = "\n\n"
|
|
40
42
|
parser.add_argument("-w", "--which", help=f"""which option to run\nChoose one of those:\n{new_line.join([f"{item.name}: {item.value}" for item in list(Options)])}""", type=str, default=None) # , choices=[op.value for op in Options]
|
|
@@ -43,29 +45,37 @@ def args_parser():
|
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
def display_title(title: str) -> None:
|
|
46
|
-
console.print(Panel(title, box=box.DOUBLE_EDGE, title_align="left"))
|
|
48
|
+
console.print(Panel(title, box=box.DOUBLE_EDGE, title_align="left")) # Replace print with Panel
|
|
49
|
+
|
|
47
50
|
|
|
48
51
|
def display_task_title(title: str) -> None:
|
|
49
|
-
console.print(Panel(title, box=box.ROUNDED, title_align="left"))
|
|
52
|
+
console.print(Panel(title, box=box.ROUNDED, title_align="left")) # Replace print with Panel
|
|
53
|
+
|
|
50
54
|
|
|
51
55
|
def display_task_status(status: str) -> None:
|
|
52
|
-
console.print(Panel(status, box=box.ROUNDED, title_align="left"))
|
|
56
|
+
console.print(Panel(status, box=box.ROUNDED, title_align="left")) # Replace print with Panel
|
|
57
|
+
|
|
53
58
|
|
|
54
59
|
def display_task_result(result: str) -> None:
|
|
55
|
-
console.print(Panel(result, box=box.ROUNDED, title_align="left"))
|
|
60
|
+
console.print(Panel(result, box=box.ROUNDED, title_align="left")) # Replace print with Panel
|
|
61
|
+
|
|
56
62
|
|
|
57
63
|
def display_task_error(error: str) -> None:
|
|
58
|
-
console.print(Panel(error, box=box.ROUNDED, border_style="red", title_align="left"))
|
|
64
|
+
console.print(Panel(error, box=box.ROUNDED, border_style="red", title_align="left")) # Replace print with Panel
|
|
65
|
+
|
|
59
66
|
|
|
60
67
|
def display_task_warning(warning: str) -> None:
|
|
61
|
-
console.print(Panel(warning, box=box.ROUNDED, border_style="yellow", title_align="left"))
|
|
68
|
+
console.print(Panel(warning, box=box.ROUNDED, border_style="yellow", title_align="left")) # Replace print with Panel
|
|
69
|
+
|
|
62
70
|
|
|
63
71
|
def display_task_success(success: str) -> None:
|
|
64
|
-
console.print(Panel(success, box=box.ROUNDED, border_style="green", title_align="left"))
|
|
72
|
+
console.print(Panel(success, box=box.ROUNDED, border_style="green", title_align="left")) # Replace print with Panel
|
|
65
73
|
|
|
66
74
|
|
|
67
75
|
def main(which: Optional[str] = None):
|
|
68
|
-
|
|
76
|
+
from machineconfig.utils.path_reduced import PathExtended
|
|
77
|
+
|
|
78
|
+
PathExtended(PROGRAM_PATH).delete(sure=True, verbose=False)
|
|
69
79
|
console.print(Panel("š Initializing DevOps operation...", width=BOX_WIDTH, border_style="blue"))
|
|
70
80
|
|
|
71
81
|
options = [op.value for op in Options]
|
|
@@ -75,34 +85,40 @@ def main(which: Optional[str] = None):
|
|
|
75
85
|
except KeyboardInterrupt:
|
|
76
86
|
console.print(Panel("ā Operation cancelled by user", title_align="left", border_style="red", width=BOX_WIDTH))
|
|
77
87
|
return
|
|
78
|
-
else:
|
|
88
|
+
else:
|
|
89
|
+
choice_key = Options[which].value
|
|
79
90
|
|
|
80
91
|
console.print(Panel(f"š§ SELECTED OPERATION\n{choice_key}", title_align="left", border_style="green", width=BOX_WIDTH))
|
|
81
92
|
|
|
82
93
|
if choice_key == Options.update.value:
|
|
83
94
|
console.print(Panel("š Updating essential repositories...", width=BOX_WIDTH, border_style="blue"))
|
|
84
95
|
import machineconfig.scripts.python.devops_update_repos as helper
|
|
96
|
+
|
|
85
97
|
program = helper.main()
|
|
86
98
|
|
|
87
99
|
elif choice_key == Options.cli_install.value:
|
|
88
100
|
console.print(Panel("āļø Installing development applications...", width=BOX_WIDTH, border_style="blue"))
|
|
89
101
|
import machineconfig.scripts.python.devops_devapps_install as helper
|
|
102
|
+
|
|
90
103
|
program = helper.main()
|
|
91
104
|
|
|
92
105
|
elif choice_key == Options.sym_new.value:
|
|
93
106
|
console.print(Panel("š Creating new symlinks...", width=BOX_WIDTH, border_style="blue"))
|
|
94
107
|
import machineconfig.jobs.python.python_ve_symlink as helper
|
|
108
|
+
|
|
95
109
|
program = helper.main()
|
|
96
110
|
|
|
97
111
|
elif choice_key == Options.sym_path_shell.value:
|
|
98
112
|
console.print(Panel("š Setting up symlinks, PATH, and shell profile...", width=BOX_WIDTH, border_style="blue"))
|
|
99
113
|
import machineconfig.profile.create as helper
|
|
114
|
+
|
|
100
115
|
helper.main()
|
|
101
116
|
program = "echo 'ā
done with symlinks'"
|
|
102
117
|
|
|
103
118
|
elif choice_key == Options.ssh_add_pubkey.value:
|
|
104
119
|
console.print(Panel("š Adding public SSH key to this machine...", width=BOX_WIDTH, border_style="blue"))
|
|
105
120
|
import machineconfig.scripts.python.devops_add_ssh_key as helper
|
|
121
|
+
|
|
106
122
|
program = helper.main()
|
|
107
123
|
|
|
108
124
|
elif choice_key == Options.ssh_use_pair.value:
|
|
@@ -112,6 +128,7 @@ def main(which: Optional[str] = None):
|
|
|
112
128
|
elif choice_key == Options.ssh_add_id.value: # so that you can SSH directly withuot pointing to identity key.
|
|
113
129
|
console.print(Panel("šļø Adding SSH identity (private key) to this machine...", width=BOX_WIDTH, border_style="blue"))
|
|
114
130
|
import machineconfig.scripts.python.devops_add_identity as helper
|
|
131
|
+
|
|
115
132
|
program = helper.main()
|
|
116
133
|
|
|
117
134
|
elif choice_key == Options.ssh_setup.value:
|
|
@@ -127,11 +144,13 @@ def main(which: Optional[str] = None):
|
|
|
127
144
|
elif choice_key == Options.backup.value:
|
|
128
145
|
console.print(Panel("š¾ Creating backup...", width=BOX_WIDTH, border_style="blue"))
|
|
129
146
|
from machineconfig.scripts.python.devops_backup_retrieve import main_backup_retrieve as helper
|
|
147
|
+
|
|
130
148
|
program = helper(direction="BACKUP")
|
|
131
149
|
|
|
132
150
|
elif choice_key == Options.retreive.value:
|
|
133
151
|
console.print(Panel("š„ Retrieving backup...", width=BOX_WIDTH, border_style="blue"))
|
|
134
152
|
from machineconfig.scripts.python.devops_backup_retrieve import main_backup_retrieve as helper
|
|
153
|
+
|
|
135
154
|
program = helper(direction="RETRIEVE")
|
|
136
155
|
|
|
137
156
|
elif choice_key == Options.scheduler.value:
|
|
@@ -143,6 +162,7 @@ def main(which: Optional[str] = None):
|
|
|
143
162
|
elif choice_key == Options.dot_files_sync.value:
|
|
144
163
|
console.print(Panel("š Synchronizing dotfiles...", width=BOX_WIDTH, border_style="blue"))
|
|
145
164
|
from machineconfig.scripts.python.cloud_repo_sync import main as helper, PathExtended
|
|
165
|
+
|
|
146
166
|
program = helper(cloud=None, path=str(PathExtended.home() / "dotfiles"), pwd=None, action="ask")
|
|
147
167
|
|
|
148
168
|
else:
|
|
@@ -156,6 +176,5 @@ def main(which: Optional[str] = None):
|
|
|
156
176
|
write_shell_script_to_default_program_path(program="echo '⨠Done.'", display=False, desc="š§ Shell script prepared by Python.", preserve_cwd=True, execute=False)
|
|
157
177
|
|
|
158
178
|
|
|
159
|
-
|
|
160
179
|
if __name__ == "__main__":
|
|
161
180
|
args_parser()
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
"""ID
|
|
2
|
-
"""
|
|
3
|
-
|
|
1
|
+
"""ID"""
|
|
4
2
|
|
|
5
3
|
# from platform import system
|
|
6
|
-
from machineconfig.utils.path_reduced import PathExtended as PathExtended
|
|
4
|
+
from machineconfig.utils.path_reduced import PathExtended as PathExtended
|
|
7
5
|
from machineconfig.utils.options import display_options
|
|
8
6
|
from rich.panel import Panel
|
|
9
7
|
from rich.text import Text
|
|
@@ -53,35 +51,27 @@ def main():
|
|
|
53
51
|
|
|
54
52
|
print(Panel("š Updating SSH configuration...", expand=False))
|
|
55
53
|
|
|
56
|
-
# Inline the previous
|
|
54
|
+
# Inline the previous modify_text behavior (now deprecated):
|
|
57
55
|
# - If file doesn't exist, seed content with txt_search
|
|
58
|
-
# -
|
|
56
|
+
# - Otherwise, replace a matching line or append if not found
|
|
59
57
|
if config_path.exists():
|
|
60
58
|
current = config_path.read_text(encoding="utf-8")
|
|
61
59
|
print(Panel("āļø Updated existing SSH config file", expand=False))
|
|
62
60
|
else:
|
|
63
61
|
current = txt
|
|
64
62
|
print(Panel("š Created new SSH config file", expand=False))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
lines = current.split("\n")
|
|
64
|
+
found = False
|
|
65
|
+
for i, line in enumerate(lines):
|
|
66
|
+
if txt in line:
|
|
67
|
+
lines[i] = txt
|
|
68
|
+
found = True
|
|
69
|
+
if not found:
|
|
70
|
+
lines.insert(0, txt)
|
|
71
|
+
new_content = "\n".join(lines)
|
|
73
72
|
config_path.write_text(new_content, encoding="utf-8")
|
|
74
73
|
|
|
75
|
-
panel_complete = Panel(
|
|
76
|
-
Text(
|
|
77
|
-
"ā
SSH IDENTITY CONFIGURATION COMPLETE\n"
|
|
78
|
-
"Identity added to SSH config file\n"
|
|
79
|
-
"Consider reloading the SSH config to apply changes",
|
|
80
|
-
justify="center"
|
|
81
|
-
),
|
|
82
|
-
expand=False,
|
|
83
|
-
border_style="green"
|
|
84
|
-
)
|
|
74
|
+
panel_complete = Panel(Text("ā
SSH IDENTITY CONFIGURATION COMPLETE\nIdentity added to SSH config file\nConsider reloading the SSH config to apply changes", justify="center"), expand=False, border_style="green")
|
|
85
75
|
program = f"echo '{panel_complete}'"
|
|
86
76
|
|
|
87
77
|
success_message = f"š CONFIGURATION SUCCESSFUL\nIdentity added: {path_to_key.name}\nConfig file: {config_path}"
|
|
@@ -90,5 +80,5 @@ def main():
|
|
|
90
80
|
return program
|
|
91
81
|
|
|
92
82
|
|
|
93
|
-
if __name__ ==
|
|
83
|
+
if __name__ == "__main__":
|
|
94
84
|
pass
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
"""SSH
|
|
2
|
-
"""
|
|
3
|
-
|
|
1
|
+
"""SSH"""
|
|
4
2
|
|
|
5
3
|
from platform import system
|
|
6
|
-
from machineconfig.utils.
|
|
4
|
+
from machineconfig.utils.source_of_truth import LIBRARY_ROOT
|
|
5
|
+
from machineconfig.utils.options import display_options
|
|
7
6
|
from machineconfig.utils.path_reduced import PathExtended as PathExtended
|
|
8
7
|
from rich.console import Console
|
|
9
8
|
from rich.panel import Panel
|
|
10
|
-
from rich import box
|
|
9
|
+
from rich import box # Import box
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
console = Console()
|
|
@@ -46,7 +45,8 @@ def get_add_ssh_key_script(path_to_key: PathExtended):
|
|
|
46
45
|
assert place_holder in program, f"This section performs string manipulation on the script {program_path} to add the key to the authorized_keys file. The script has changed and the string {place_holder} is not found."
|
|
47
46
|
program = program.replace(place_holder, f'$sshfile = "{path_to_key}"')
|
|
48
47
|
console.print(Panel("š§ Configured PowerShell script for Windows\nš Replaced placeholder with actual key path", title="[bold blue]Configuration[/bold blue]"))
|
|
49
|
-
else:
|
|
48
|
+
else:
|
|
49
|
+
raise NotImplementedError
|
|
50
50
|
else:
|
|
51
51
|
console.print(Panel(f"š Creating new authorized_keys file\nš Using key: {path_to_key.name}", title="[bold blue]Action[/bold blue]"))
|
|
52
52
|
if system() == "Linux":
|
|
@@ -114,5 +114,5 @@ def main():
|
|
|
114
114
|
return program
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
if __name__ ==
|
|
117
|
+
if __name__ == "__main__":
|
|
118
118
|
pass
|