machineconfig 2.1__py3-none-any.whl → 2.2__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/archive/create_zellij_template.py +2 -1
- 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 +10 -5
- machineconfig/profile/create_hardlinks.py +3 -1
- machineconfig/profile/shell.py +8 -7
- machineconfig/scripts/__init__.py +0 -2
- machineconfig/scripts/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/scripts/linux/devops +6 -4
- 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_agents.cpython-313.pyc +0 -0
- 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 +45 -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 +25 -20
- machineconfig/scripts/python/devops_update_repos.py +142 -57
- machineconfig/scripts/python/dotfile.py +16 -14
- machineconfig/scripts/python/fire_agents.py +24 -17
- machineconfig/scripts/python/fire_jobs.py +91 -55
- 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 -30
- 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 -75
- 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 +3 -3
- machineconfig/utils/installer.py +2 -2
- machineconfig/utils/installer_utils/installer_abc.py +3 -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 +16 -23
- machineconfig/utils/path_reduced.py +239 -205
- machineconfig/utils/procs.py +1 -1
- machineconfig/utils/source_of_truth.py +27 -0
- machineconfig/utils/ssh.py +9 -29
- 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.2.dist-info}/METADATA +13 -13
- {machineconfig-2.1.dist-info → machineconfig-2.2.dist-info}/RECORD +78 -86
- machineconfig/jobs/python_custom_installers/__pycache__/__init__.cpython-313.pyc +0 -0
- machineconfig/scripts/python/__pycache__/croshell.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/setup_linux/web_shortcuts/{tmp.sh → android.sh} +0 -0
- {machineconfig-2.1.dist-info → machineconfig-2.2.dist-info}/WHEEL +0 -0
- {machineconfig-2.1.dist-info → machineconfig-2.2.dist-info}/top_level.txt +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
"""Cloud mount script
|
|
2
|
-
"""
|
|
3
|
-
|
|
1
|
+
"""Cloud mount script"""
|
|
4
2
|
|
|
5
|
-
from machineconfig.utils.
|
|
3
|
+
from machineconfig.utils.source_of_truth import PROGRAM_PATH
|
|
4
|
+
from machineconfig.utils.options import choose_one_option
|
|
6
5
|
from machineconfig.utils.utils2 import read_ini
|
|
7
6
|
from machineconfig.utils.path_reduced import PathExtended as PathExtended
|
|
8
7
|
|
|
@@ -19,9 +18,12 @@ DEFAULT_MOUNT = "~/data/rclone"
|
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
def get_rclone_config():
|
|
22
|
-
if platform.system() == "Windows":
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
if platform.system() == "Windows":
|
|
22
|
+
config = read_ini(PathExtended.home().joinpath("AppData/Roaming/rclone/rclone.conf"))
|
|
23
|
+
elif platform.system() in ["Linux", "Darwin"]:
|
|
24
|
+
config = read_ini(PathExtended.home().joinpath(".config/rclone/rclone.conf"))
|
|
25
|
+
else:
|
|
26
|
+
raise ValueError("unsupported platform")
|
|
25
27
|
return config
|
|
26
28
|
|
|
27
29
|
|
|
@@ -30,18 +32,22 @@ def get_mprocs_mount_txt(cloud: str, rclone_cmd: str, cloud_brand: str): # clou
|
|
|
30
32
|
if platform.system() == "Windows":
|
|
31
33
|
sub_text_path = PathExtended.tmpfile(suffix=".ps1")
|
|
32
34
|
sub_text_path.parent.mkdir(parents=True, exist_ok=True)
|
|
33
|
-
sub_text_path.write_text(
|
|
35
|
+
sub_text_path.write_text(
|
|
36
|
+
f"""
|
|
34
37
|
echo "{header}"
|
|
35
38
|
iex 'rclone about {cloud}:'
|
|
36
39
|
echo 'See {DEFAULT_MOUNT}/{cloud} for the mounted cloud'
|
|
37
40
|
|
|
38
41
|
echo ''
|
|
39
|
-
""",
|
|
42
|
+
""",
|
|
43
|
+
encoding="utf-8",
|
|
44
|
+
)
|
|
40
45
|
txt = f"""
|
|
41
46
|
cd ~
|
|
42
47
|
mprocs "powershell {sub_text_path}" "{rclone_cmd}" "btm" "timeout 2 & cd {DEFAULT_MOUNT} & lf" "timeout 2 & cd {DEFAULT_MOUNT} & pwsh" "pwsh" --names "info,service,monitor,explorer,main,terminal"
|
|
43
48
|
"""
|
|
44
|
-
else:
|
|
49
|
+
else:
|
|
50
|
+
txt = f"""
|
|
45
51
|
mprocs "echo 'see {DEFAULT_MOUNT}/{cloud} for the mounted cloud'; rclone about {cloud}:" "{rclone_cmd}" "btm" "cd {DEFAULT_MOUNT}; lf" "bash" "bash" --names "about,service,monitor,explorer,main,shell"
|
|
46
52
|
"""
|
|
47
53
|
return txt
|
|
@@ -55,8 +61,10 @@ def mount(cloud: Optional[str], network: Optional[str], destination: Optional[st
|
|
|
55
61
|
config = get_rclone_config()
|
|
56
62
|
if cloud is None:
|
|
57
63
|
res = choose_one_option(msg="which cloud", options=config.sections(), header="CLOUD MOUNT", default=None)
|
|
58
|
-
if type(res) is str:
|
|
59
|
-
|
|
64
|
+
if type(res) is str:
|
|
65
|
+
cloud = res
|
|
66
|
+
else:
|
|
67
|
+
raise ValueError("no cloud selected")
|
|
60
68
|
print(f"🌩️ Selected cloud: {cloud}")
|
|
61
69
|
|
|
62
70
|
if network is None:
|
|
@@ -74,30 +82,33 @@ def mount(cloud: Optional[str], network: Optional[str], destination: Optional[st
|
|
|
74
82
|
elif platform.system() in ["Linux", "Darwin"]:
|
|
75
83
|
system_name = "Linux" if platform.system() == "Linux" else "macOS"
|
|
76
84
|
print(f"🐧 Creating mount directory on {system_name}...")
|
|
77
|
-
try:
|
|
85
|
+
try:
|
|
86
|
+
mount_loc.mkdir(parents=True, exist_ok=True)
|
|
78
87
|
except (FileExistsError, OSError) as err:
|
|
79
88
|
# We need a umount command here.
|
|
80
89
|
warning_line = "⚠️ WARNING: Mount directory issue"
|
|
81
90
|
err_line = f"{err}"
|
|
82
91
|
console.print(Panel(f"{warning_line}\n{err_line}", title="Warning", border_style="yellow"))
|
|
83
92
|
pass
|
|
84
|
-
else:
|
|
93
|
+
else:
|
|
94
|
+
raise ValueError("unsupported platform")
|
|
85
95
|
|
|
86
96
|
elif network and platform.system() == "Windows":
|
|
87
97
|
mount_loc = "X: --network-mode"
|
|
88
98
|
print(f"🔌 Setting up network mount at {mount_loc}")
|
|
89
|
-
else:
|
|
99
|
+
else:
|
|
100
|
+
raise ValueError("network mount only supported on windows")
|
|
90
101
|
|
|
91
102
|
mount_cmd = f"rclone mount {cloud}: {mount_loc} --vfs-cache-mode full --file-perms=0777"
|
|
92
103
|
console.print(Panel(f"🚀 Preparing mount command:\n{mount_cmd}", border_style="blue"))
|
|
93
104
|
|
|
94
105
|
# txt = get_mprocs_mount_txt(cloud, mount_cmd)
|
|
95
106
|
if platform.system() == "Windows":
|
|
96
|
-
|
|
97
107
|
txt = f"""
|
|
98
108
|
wt --window 0 --profile "Windows PowerShell" --startingDirectory "$HOME/data/rclone" `; split-pane --horizontal --profile "Command Prompt" --size 0.2 powershell -Command "{mount_cmd}" `; split-pane --vertical --profile "Windows PowerShell" --size 0.2 powershell -NoExit -Command "rclone about {cloud}:" `; move-focus up
|
|
99
109
|
"""
|
|
100
|
-
elif platform.system() in ["Linux", "Darwin"]:
|
|
110
|
+
elif platform.system() in ["Linux", "Darwin"]:
|
|
111
|
+
txt = f"""
|
|
101
112
|
|
|
102
113
|
ZJ_SESSIONS=$(zellij list-sessions)
|
|
103
114
|
|
|
@@ -130,7 +141,8 @@ zellij run --direction up -- btm --default_widget_type net --expanded
|
|
|
130
141
|
zellij run --in-place --cwd $HOME/data/rclone/{cloud} -- bash
|
|
131
142
|
zellij action move-focus up
|
|
132
143
|
"""
|
|
133
|
-
else:
|
|
144
|
+
else:
|
|
145
|
+
raise ValueError("unsupported platform")
|
|
134
146
|
# print(f"running command: \n{txt}")
|
|
135
147
|
PROGRAM_PATH.write_text(txt, encoding="utf-8")
|
|
136
148
|
# draw success box dynamically
|
|
@@ -144,13 +156,13 @@ def main():
|
|
|
144
156
|
main_title = "☁️ RCLONE CLOUD MOUNT"
|
|
145
157
|
console.print(Panel(main_title, title_align="left", border_style="blue"))
|
|
146
158
|
|
|
147
|
-
parser = argparse.ArgumentParser(description=
|
|
148
|
-
parser.add_argument(
|
|
149
|
-
parser.add_argument(
|
|
150
|
-
parser.add_argument(
|
|
159
|
+
parser = argparse.ArgumentParser(description="mount cloud")
|
|
160
|
+
parser.add_argument("cloud", nargs="?", type=str, default=None, help="cloud to mount")
|
|
161
|
+
parser.add_argument("destination", nargs="?", type=str, default=None, help="destination to mount")
|
|
162
|
+
parser.add_argument("--network", type=str, default=None, help="mount network drive")
|
|
151
163
|
args = parser.parse_args()
|
|
152
164
|
mount(cloud=args.cloud, network=args.network, destination=args.destination)
|
|
153
165
|
|
|
154
166
|
|
|
155
|
-
if __name__ ==
|
|
167
|
+
if __name__ == "__main__":
|
|
156
168
|
main()
|
|
@@ -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,36 @@ 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
|
+
PathExtended(PROGRAM_PATH).delete(sure=True, verbose=False)
|
|
69
78
|
console.print(Panel("🚀 Initializing DevOps operation...", width=BOX_WIDTH, border_style="blue"))
|
|
70
79
|
|
|
71
80
|
options = [op.value for op in Options]
|
|
@@ -75,34 +84,40 @@ def main(which: Optional[str] = None):
|
|
|
75
84
|
except KeyboardInterrupt:
|
|
76
85
|
console.print(Panel("❌ Operation cancelled by user", title_align="left", border_style="red", width=BOX_WIDTH))
|
|
77
86
|
return
|
|
78
|
-
else:
|
|
87
|
+
else:
|
|
88
|
+
choice_key = Options[which].value
|
|
79
89
|
|
|
80
90
|
console.print(Panel(f"🔧 SELECTED OPERATION\n{choice_key}", title_align="left", border_style="green", width=BOX_WIDTH))
|
|
81
91
|
|
|
82
92
|
if choice_key == Options.update.value:
|
|
83
93
|
console.print(Panel("🔄 Updating essential repositories...", width=BOX_WIDTH, border_style="blue"))
|
|
84
94
|
import machineconfig.scripts.python.devops_update_repos as helper
|
|
95
|
+
|
|
85
96
|
program = helper.main()
|
|
86
97
|
|
|
87
98
|
elif choice_key == Options.cli_install.value:
|
|
88
99
|
console.print(Panel("⚙️ Installing development applications...", width=BOX_WIDTH, border_style="blue"))
|
|
89
100
|
import machineconfig.scripts.python.devops_devapps_install as helper
|
|
101
|
+
|
|
90
102
|
program = helper.main()
|
|
91
103
|
|
|
92
104
|
elif choice_key == Options.sym_new.value:
|
|
93
105
|
console.print(Panel("🔄 Creating new symlinks...", width=BOX_WIDTH, border_style="blue"))
|
|
94
106
|
import machineconfig.jobs.python.python_ve_symlink as helper
|
|
107
|
+
|
|
95
108
|
program = helper.main()
|
|
96
109
|
|
|
97
110
|
elif choice_key == Options.sym_path_shell.value:
|
|
98
111
|
console.print(Panel("🔗 Setting up symlinks, PATH, and shell profile...", width=BOX_WIDTH, border_style="blue"))
|
|
99
112
|
import machineconfig.profile.create as helper
|
|
113
|
+
|
|
100
114
|
helper.main()
|
|
101
115
|
program = "echo '✅ done with symlinks'"
|
|
102
116
|
|
|
103
117
|
elif choice_key == Options.ssh_add_pubkey.value:
|
|
104
118
|
console.print(Panel("🔑 Adding public SSH key to this machine...", width=BOX_WIDTH, border_style="blue"))
|
|
105
119
|
import machineconfig.scripts.python.devops_add_ssh_key as helper
|
|
120
|
+
|
|
106
121
|
program = helper.main()
|
|
107
122
|
|
|
108
123
|
elif choice_key == Options.ssh_use_pair.value:
|
|
@@ -112,6 +127,7 @@ def main(which: Optional[str] = None):
|
|
|
112
127
|
elif choice_key == Options.ssh_add_id.value: # so that you can SSH directly withuot pointing to identity key.
|
|
113
128
|
console.print(Panel("🗝️ Adding SSH identity (private key) to this machine...", width=BOX_WIDTH, border_style="blue"))
|
|
114
129
|
import machineconfig.scripts.python.devops_add_identity as helper
|
|
130
|
+
|
|
115
131
|
program = helper.main()
|
|
116
132
|
|
|
117
133
|
elif choice_key == Options.ssh_setup.value:
|
|
@@ -127,11 +143,13 @@ def main(which: Optional[str] = None):
|
|
|
127
143
|
elif choice_key == Options.backup.value:
|
|
128
144
|
console.print(Panel("💾 Creating backup...", width=BOX_WIDTH, border_style="blue"))
|
|
129
145
|
from machineconfig.scripts.python.devops_backup_retrieve import main_backup_retrieve as helper
|
|
146
|
+
|
|
130
147
|
program = helper(direction="BACKUP")
|
|
131
148
|
|
|
132
149
|
elif choice_key == Options.retreive.value:
|
|
133
150
|
console.print(Panel("📥 Retrieving backup...", width=BOX_WIDTH, border_style="blue"))
|
|
134
151
|
from machineconfig.scripts.python.devops_backup_retrieve import main_backup_retrieve as helper
|
|
152
|
+
|
|
135
153
|
program = helper(direction="RETRIEVE")
|
|
136
154
|
|
|
137
155
|
elif choice_key == Options.scheduler.value:
|
|
@@ -143,6 +161,7 @@ def main(which: Optional[str] = None):
|
|
|
143
161
|
elif choice_key == Options.dot_files_sync.value:
|
|
144
162
|
console.print(Panel("🔗 Synchronizing dotfiles...", width=BOX_WIDTH, border_style="blue"))
|
|
145
163
|
from machineconfig.scripts.python.cloud_repo_sync import main as helper, PathExtended
|
|
164
|
+
|
|
146
165
|
program = helper(cloud=None, path=str(PathExtended.home() / "dotfiles"), pwd=None, action="ask")
|
|
147
166
|
|
|
148
167
|
else:
|
|
@@ -156,6 +175,5 @@ def main(which: Optional[str] = None):
|
|
|
156
175
|
write_shell_script_to_default_program_path(program="echo '✨ Done.'", display=False, desc="🔧 Shell script prepared by Python.", preserve_cwd=True, execute=False)
|
|
157
176
|
|
|
158
177
|
|
|
159
|
-
|
|
160
178
|
if __name__ == "__main__":
|
|
161
179
|
args_parser()
|