machineconfig 1.5__py3-none-any.whl → 1.8__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/__init__.py +8 -5
- machineconfig/jobs/python/check_installations.py +173 -163
- machineconfig/jobs/python/checkout_version.py +117 -0
- machineconfig/jobs/python/create_bootable_media.py +14 -14
- machineconfig/jobs/python/create_zellij_template.py +59 -56
- machineconfig/jobs/python/python_cargo_build_share.py +50 -45
- machineconfig/jobs/python/python_ve_symlink.py +20 -18
- machineconfig/jobs/python/tasks.py +4 -0
- machineconfig/jobs/script_installer/azure_data_studio.py +22 -0
- machineconfig/jobs/script_installer/bypass_paywall.py +23 -0
- machineconfig/jobs/script_installer/code.py +34 -0
- machineconfig/jobs/script_installer/docker_desktop.py +41 -0
- machineconfig/jobs/script_installer/ngrok.py +29 -0
- machineconfig/jobs/{python_linux_installers → script_installer}/skim.py +21 -19
- machineconfig/jobs/script_installer/wezterm.py +34 -0
- machineconfig/profile/create.py +107 -200
- machineconfig/profile/shell.py +127 -0
- machineconfig/scripts/__init__.py +6 -6
- machineconfig/scripts/python/cloud_copy.py +93 -0
- machineconfig/scripts/python/cloud_manager.py +38 -0
- machineconfig/scripts/python/cloud_mount.py +115 -52
- machineconfig/scripts/python/cloud_repo_sync.py +154 -114
- machineconfig/scripts/python/cloud_sync.py +261 -79
- machineconfig/scripts/python/croshell.py +151 -0
- machineconfig/scripts/python/devops.py +119 -87
- machineconfig/scripts/python/devops_add_identity.py +27 -23
- machineconfig/scripts/python/devops_add_ssh_key.py +70 -55
- machineconfig/scripts/python/devops_backup_retrieve.py +52 -46
- machineconfig/scripts/python/devops_devapps_install.py +120 -91
- machineconfig/scripts/python/devops_update_repos.py +82 -68
- machineconfig/scripts/python/dotfile.py +42 -38
- machineconfig/scripts/python/fire_jobs.py +351 -98
- machineconfig/scripts/python/ftpx.py +82 -0
- machineconfig/scripts/python/mount_nfs.py +54 -3
- machineconfig/scripts/python/mount_nw_drive.py +31 -0
- machineconfig/scripts/python/mount_ssh.py +44 -20
- machineconfig/scripts/python/onetimeshare.py +60 -51
- machineconfig/scripts/python/pomodoro.py +41 -37
- machineconfig/scripts/python/repos.py +195 -128
- machineconfig/scripts/python/scheduler.py +52 -0
- machineconfig/scripts/python/snapshot.py +21 -21
- machineconfig/scripts/python/start_slidev.py +104 -0
- machineconfig/scripts/python/start_terminals.py +97 -0
- machineconfig/scripts/python/wifi_conn.py +90 -71
- machineconfig/scripts/python/{transfer_wsl_win.py → wsl_windows_transfer.py} +47 -39
- machineconfig/setup_windows/wt_and_pwsh/set_pwsh_theme.py +44 -48
- machineconfig/setup_windows/wt_and_pwsh/set_wt_settings.py +136 -130
- machineconfig/utils/installer.py +251 -0
- machineconfig/utils/procs.py +114 -64
- machineconfig/utils/scheduling.py +188 -0
- machineconfig/utils/utils.py +353 -249
- machineconfig/utils/ve.py +222 -0
- {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/METADATA +140 -110
- machineconfig-1.8.dist-info/RECORD +70 -0
- {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/WHEEL +1 -1
- machineconfig/jobs/python/python_linux_installers_all.py +0 -73
- machineconfig/jobs/python/python_ve_installer.py +0 -73
- machineconfig/jobs/python/python_windows_installers_all.py +0 -23
- machineconfig/jobs/python_generic_installers/archive/nvim.py +0 -15
- machineconfig/jobs/python_generic_installers/archive/strongbox.py +0 -32
- machineconfig/jobs/python_generic_installers/archive/vtm.py +0 -25
- machineconfig/jobs/python_generic_installers/broot.py +0 -39
- machineconfig/jobs/python_generic_installers/browsh.py +0 -25
- machineconfig/jobs/python_generic_installers/bw.py +0 -26
- machineconfig/jobs/python_generic_installers/chatgpt.py +0 -24
- machineconfig/jobs/python_generic_installers/cpufetch.py +0 -23
- machineconfig/jobs/python_generic_installers/delta.py +0 -59
- machineconfig/jobs/python_generic_installers/dev/__init__.py +0 -0
- machineconfig/jobs/python_generic_installers/dev/autogpt.py +0 -28
- machineconfig/jobs/python_generic_installers/dev/bw.py +0 -29
- machineconfig/jobs/python_generic_installers/dev/evcxr.py +0 -22
- machineconfig/jobs/python_generic_installers/dev/kondo.py +0 -21
- machineconfig/jobs/python_generic_installers/dev/lvim.py +0 -60
- machineconfig/jobs/python_generic_installers/dev/ngrok.py +0 -35
- machineconfig/jobs/python_generic_installers/dev/opencommit.py +0 -21
- machineconfig/jobs/python_generic_installers/dev/qrcp.py +0 -25
- machineconfig/jobs/python_generic_installers/dev/qrscan.py +0 -16
- machineconfig/jobs/python_generic_installers/dev/rust-analyzer.py +0 -24
- machineconfig/jobs/python_generic_installers/dev/termscp.py +0 -23
- machineconfig/jobs/python_generic_installers/dev/tldr.py +0 -25
- machineconfig/jobs/python_generic_installers/dev/tokei.py +0 -24
- machineconfig/jobs/python_generic_installers/diskonaut.py +0 -26
- machineconfig/jobs/python_generic_installers/dua.py +0 -21
- machineconfig/jobs/python_generic_installers/evcxr.py +0 -21
- machineconfig/jobs/python_generic_installers/gitui.py +0 -23
- machineconfig/jobs/python_generic_installers/gopass.py +0 -19
- machineconfig/jobs/python_generic_installers/helix.py +0 -45
- machineconfig/jobs/python_generic_installers/kondo.py +0 -20
- machineconfig/jobs/python_generic_installers/lf.py +0 -25
- machineconfig/jobs/python_generic_installers/lvim.py +0 -34
- machineconfig/jobs/python_generic_installers/mprocs.py +0 -20
- machineconfig/jobs/python_generic_installers/navi.py +0 -20
- machineconfig/jobs/python_generic_installers/ots.py +0 -26
- machineconfig/jobs/python_generic_installers/ouch.py +0 -25
- machineconfig/jobs/python_generic_installers/pomodoro.py +0 -19
- machineconfig/jobs/python_generic_installers/procs.py +0 -20
- machineconfig/jobs/python_generic_installers/qrcp.py +0 -22
- machineconfig/jobs/python_generic_installers/qrscan.py +0 -14
- machineconfig/jobs/python_generic_installers/rclone.py +0 -21
- machineconfig/jobs/python_generic_installers/rust-analyzer.py +0 -24
- machineconfig/jobs/python_generic_installers/tere.py +0 -26
- machineconfig/jobs/python_generic_installers/termscp.py +0 -23
- machineconfig/jobs/python_generic_installers/tldr.py +0 -24
- machineconfig/jobs/python_generic_installers/tokei.py +0 -21
- machineconfig/jobs/python_generic_installers/vtm.py +0 -26
- machineconfig/jobs/python_generic_installers/watchexec.py +0 -21
- machineconfig/jobs/python_linux_installers/archive/__init__.py +0 -0
- machineconfig/jobs/python_linux_installers/archive/ranger.py +0 -18
- machineconfig/jobs/python_linux_installers/bandwhich.py +0 -11
- machineconfig/jobs/python_linux_installers/bottom.py +0 -17
- machineconfig/jobs/python_linux_installers/btop.py +0 -17
- machineconfig/jobs/python_linux_installers/dev/bandwhich.py +0 -13
- machineconfig/jobs/python_linux_installers/dev/bytehound.py +0 -20
- machineconfig/jobs/python_linux_installers/dev/nnn.py +0 -21
- machineconfig/jobs/python_linux_installers/gotty.py +0 -16
- machineconfig/jobs/python_linux_installers/joshuto.py +0 -28
- machineconfig/jobs/python_linux_installers/mcfly.py +0 -12
- machineconfig/jobs/python_linux_installers/nnn.py +0 -18
- machineconfig/jobs/python_linux_installers/topgrade.py +0 -15
- machineconfig/jobs/python_linux_installers/viu.py +0 -19
- machineconfig/jobs/python_linux_installers/xplr.py +0 -22
- machineconfig/jobs/python_linux_installers/zellij.py +0 -31
- machineconfig/jobs/python_windows_installers/archive/ntop.py +0 -20
- machineconfig/jobs/python_windows_installers/bat.py +0 -16
- machineconfig/jobs/python_windows_installers/boxes.py +0 -19
- machineconfig/jobs/python_windows_installers/bypass_paywall.py +0 -18
- machineconfig/jobs/python_windows_installers/dev/bypass_paywall.py +0 -21
- machineconfig/jobs/python_windows_installers/dev/obs_background_removal_plugin.py +0 -20
- machineconfig/jobs/python_windows_installers/fd.py +0 -17
- machineconfig/jobs/python_windows_installers/fzf.py +0 -19
- machineconfig/jobs/python_windows_installers/obs_background_removal_plugin.py +0 -19
- machineconfig/jobs/python_windows_installers/rg.py +0 -15
- machineconfig/jobs/python_windows_installers/ugrep.py +0 -14
- machineconfig/jobs/python_windows_installers/zoomit.py +0 -20
- machineconfig/jobs/python_windows_installers/zoxide.py +0 -20
- machineconfig/profile/fix_shell_profiles.py +0 -8
- machineconfig/scripts/python/archive/__init__.py +0 -0
- machineconfig/scripts/python/archive/bu_gdrive_rx.py +0 -41
- machineconfig/scripts/python/archive/bu_gdrive_sx.py +0 -40
- machineconfig/scripts/python/archive/bu_onedrive_rx.py +0 -59
- machineconfig/scripts/python/archive/bu_onedrive_sx.py +0 -45
- machineconfig/scripts/python/chatgpt.py +0 -28
- machineconfig/scripts/python/choose_ohmybash_theme.py +0 -25
- machineconfig/scripts/python/choose_ohmyposh_theme.py +0 -40
- machineconfig/scripts/python/cloud_rx.py +0 -42
- machineconfig/scripts/python/cloud_sx.py +0 -40
- machineconfig/scripts/python/ftprx.py +0 -37
- machineconfig/scripts/python/ftpsx.py +0 -36
- machineconfig/scripts/python/im2text.py +0 -15
- machineconfig/scripts/python/tmate_conn.py +0 -28
- machineconfig/scripts/python/tmate_start.py +0 -31
- machineconfig/utils/to_exe.py +0 -7
- machineconfig-1.5.dist-info/RECORD +0 -147
- /machineconfig/jobs/{python_generic_installers/archive → script_installer}/__init__.py +0 -0
- {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/top_level.txt +0 -0
|
@@ -1,52 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
""")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
""
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
|
|
2
|
+
"""Cloud mount script
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from machineconfig.utils.utils import PROGRAM_PATH, choose_one_option
|
|
7
|
+
from crocodile.file_management import P, Read
|
|
8
|
+
|
|
9
|
+
import platform
|
|
10
|
+
import argparse
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
DEFAULT_MOUNT = "~/data/rclone"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_rclone_config():
|
|
18
|
+
if platform.system() == "Windows": config = Read.ini(P.home().joinpath("AppData/Roaming/rclone/rclone.conf"))
|
|
19
|
+
elif platform.system() == "Linux": config = Read.ini(P.home().joinpath(".config/rclone/rclone.conf"))
|
|
20
|
+
else: raise ValueError("unsupported platform")
|
|
21
|
+
return config
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_mprocs_mount_txt(cloud: str, rclone_cmd: str, cloud_brand: str): # cloud_brand = config[cloud]["type"]
|
|
25
|
+
# config = Read.ini(P.home().joinpath(".config/rclone/rclone.conf"))
|
|
26
|
+
header = f"{' ' + cloud + ' | ' + cloud_brand + ' '}".center(50, "=")
|
|
27
|
+
if platform.system() == "Windows":
|
|
28
|
+
sub_text_path = P.tmpfile(suffix=".ps1").write_text(f"""
|
|
29
|
+
echo "{header}"
|
|
30
|
+
iex 'rclone about {cloud}:'
|
|
31
|
+
echo 'See {DEFAULT_MOUNT}/{cloud} for the mounted cloud'
|
|
32
|
+
|
|
33
|
+
echo ''
|
|
34
|
+
""")
|
|
35
|
+
txt = f"""
|
|
36
|
+
cd ~
|
|
37
|
+
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"
|
|
38
|
+
"""
|
|
39
|
+
else: txt = f"""
|
|
40
|
+
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"
|
|
41
|
+
"""
|
|
42
|
+
return txt
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def mount(cloud: Optional[str], network: Optional[str], destination: Optional[str]) -> None:
|
|
46
|
+
|
|
47
|
+
config = get_rclone_config()
|
|
48
|
+
if cloud is None:
|
|
49
|
+
res = choose_one_option(msg="which cloud", options=config.sections(), header="CLOUD MOUNT", default=None)
|
|
50
|
+
if type(res) is str: cloud = res
|
|
51
|
+
else: raise ValueError("no cloud selected")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if network is None:
|
|
55
|
+
if destination is None: mount_loc = P(DEFAULT_MOUNT).expanduser().joinpath(cloud)
|
|
56
|
+
else: mount_loc = P(destination)
|
|
57
|
+
|
|
58
|
+
if platform.system() == "Windows": mount_loc.parent.create()
|
|
59
|
+
elif platform.system() == "Linux": mount_loc.create()
|
|
60
|
+
else: raise ValueError("unsupported platform")
|
|
61
|
+
|
|
62
|
+
elif network and platform.system() == "Windows": mount_loc = "X: --network-mode"
|
|
63
|
+
else: raise ValueError("network mount only supported on windows")
|
|
64
|
+
|
|
65
|
+
mount_cmd = f"rclone mount {cloud}: {mount_loc} --vfs-cache-mode full --file-perms=0777"
|
|
66
|
+
|
|
67
|
+
# txt = get_mprocs_mount_txt(cloud, mount_cmd)
|
|
68
|
+
if platform.system() == "Windows": txt = f"""
|
|
69
|
+
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
|
|
70
|
+
"""
|
|
71
|
+
elif platform.system() == "Linux": txt = f"""
|
|
72
|
+
|
|
73
|
+
ZJ_SESSIONS=$(zellij list-sessions)
|
|
74
|
+
|
|
75
|
+
if [[ "${{ZJ_SESSIONS}}" != *"(current)"* ]]; then
|
|
76
|
+
echo "Not inside a zellij session ..."
|
|
77
|
+
echo '{mount_cmd}'
|
|
78
|
+
exit 1
|
|
79
|
+
fi
|
|
80
|
+
|
|
81
|
+
zellij run --direction down --name rclone -- {mount_cmd}
|
|
82
|
+
sleep 1; zellij action resize decrease down
|
|
83
|
+
sleep 0.2; zellij action resize decrease up
|
|
84
|
+
sleep 0.2; zellij action resize decrease up
|
|
85
|
+
sleep 0.1; zellij action resize decrease up
|
|
86
|
+
sleep 0.1; zellij action resize decrease up
|
|
87
|
+
sleep 0.1; zellij action resize decrease up
|
|
88
|
+
sleep 0.1; zellij action resize decrease up
|
|
89
|
+
sleep 0.1; zellij action resize decrease up
|
|
90
|
+
sleep 0.1; zellij action resize decrease up
|
|
91
|
+
sleep 0.1; zellij action resize decrease up
|
|
92
|
+
zellij run --direction right --name about -- rclone about {cloud}:
|
|
93
|
+
zellij action move-focus up
|
|
94
|
+
# zellij action write-chars "cd $HOME/data/rclone/{cloud}; sleep 0.1; ls"
|
|
95
|
+
zellij run --direction left --cwd $HOME/data/rclone/{cloud} -- lf
|
|
96
|
+
zellij run --direction up -- btm --default_widget_type net --expanded
|
|
97
|
+
zellij run --in-place --cwd $HOME/data/rclone/{cloud} -- bash
|
|
98
|
+
zellij action move-focus up
|
|
99
|
+
"""
|
|
100
|
+
else: raise ValueError("unsupported platform")
|
|
101
|
+
# print(f"running command: \n{txt}")
|
|
102
|
+
PROGRAM_PATH.write_text(txt)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def main():
|
|
106
|
+
parser = argparse.ArgumentParser(description='mount cloud')
|
|
107
|
+
parser.add_argument('cloud', nargs='?', type=str, default=None, help='cloud to mount')
|
|
108
|
+
parser.add_argument('destination', nargs='?', type=str, default=None, help='destination to mount')
|
|
109
|
+
parser.add_argument('--network', type=str, default=None, help='mount network drive')
|
|
110
|
+
args = parser.parse_args()
|
|
111
|
+
mount(cloud=args.cloud, network=args.network, destination=args.destination)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
if __name__ == '__main__':
|
|
115
|
+
main()
|
|
@@ -1,114 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
from machineconfig.utils.utils import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
1
|
+
|
|
2
|
+
"""utils"""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
from machineconfig.utils.utils import CONFIG_PATH, DEFAULTS_PATH, write_shell_script, get_shell_file_executing_python_script
|
|
6
|
+
from crocodile.file_management import P, Read, install_n_import
|
|
7
|
+
from crocodile.core import randstr
|
|
8
|
+
from crocodile.meta import Terminal
|
|
9
|
+
import argparse
|
|
10
|
+
import platform
|
|
11
|
+
from typing import Optional
|
|
12
|
+
# import sys
|
|
13
|
+
# import subprocess
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_wt_cmd(wd1: P, wd2: P) -> str:
|
|
17
|
+
lines = [
|
|
18
|
+
f"""wt --window 0 new-tab --profile pwsh --title "gitdiff" --tabColor `#3b04d1 --startingDirectory {wd1} ` --colorScheme "Solarized Dark" """,
|
|
19
|
+
f"""split-pane --horizontal --profile pwsh --startingDirectory {wd2} --size 0.5 --colorScheme "Tango Dark" -- pwsh -Interactive """
|
|
20
|
+
]
|
|
21
|
+
return " `; ".join(lines)
|
|
22
|
+
|
|
23
|
+
def get_zellij_cmd(wd1: P, wd2: P) -> str:
|
|
24
|
+
lines = [f""" zellij action new-tab --name gitdiff""",
|
|
25
|
+
f"""zellij action new-pane --direction down --name local --cwd ./data """,
|
|
26
|
+
f"""zellij action write-chars "cd '{wd1}'; git status" """,
|
|
27
|
+
f"""zellij action move-focus up; zellij action close-pane """,
|
|
28
|
+
f"""zellij action new-pane --direction down --name remote --cwd code """,
|
|
29
|
+
f"""zellij action write-chars "cd '{wd2}' """,
|
|
30
|
+
f"""git status" """
|
|
31
|
+
]
|
|
32
|
+
return "; ".join(lines)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def args_parser():
|
|
36
|
+
parser = argparse.ArgumentParser(description="Secure Repo CLI.")
|
|
37
|
+
|
|
38
|
+
# parser.add_argument("cmd", help="command to run", choices=["pull", "push"])
|
|
39
|
+
parser.add_argument("path", nargs='?', type=str, help="Repository path, defaults to cwd.", default=None)
|
|
40
|
+
|
|
41
|
+
# parser.add_argument("--share", help="Repository path, defaults to cwd.", action="store_true", default=False)
|
|
42
|
+
|
|
43
|
+
parser.add_argument("--cloud", "-c", help="rclone cloud profile name.", default=None)
|
|
44
|
+
parser.add_argument("--message", "-m", help="Commit Message", default=f"new message {randstr()}")
|
|
45
|
+
parser.add_argument("--skip_confirmation", "-s", help="Skip confirmation.", action="store_true", default=False)
|
|
46
|
+
# parser.add_argument("--key", "-k", help="Key for encryption", default=None)
|
|
47
|
+
parser.add_argument("--pwd", "-p", help="Password for encryption", default=None)
|
|
48
|
+
parser.add_argument("--no_push", "-u", help="push to reomte.", action="store_true") # default is False
|
|
49
|
+
args = parser.parse_args()
|
|
50
|
+
|
|
51
|
+
# if args.share:
|
|
52
|
+
# from machineconfig.scripts.cloud.dotfiles import put
|
|
53
|
+
# put()
|
|
54
|
+
# return None
|
|
55
|
+
main(cloud=args.cloud, path=args.path, message=args.message, skip_confirmation=args.skip_confirmation, pwd=args.pwd, push=not args.no_push)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def main(cloud: Optional[str] = None, path: Optional[str] = None, message: Optional[str] = None, skip_confirmation: bool = False, pwd: Optional[str] = None, push: bool = True):
|
|
59
|
+
if cloud is None:
|
|
60
|
+
try:
|
|
61
|
+
cloud_resolved = Read.ini(DEFAULTS_PATH)['general']['rclone_config_name']
|
|
62
|
+
print(f"⚠️ Using default cloud: `{cloud_resolved}` from {DEFAULTS_PATH} ⚠️")
|
|
63
|
+
except FileNotFoundError:
|
|
64
|
+
print(f"No cloud profile found @ {DEFAULTS_PATH}, please set one up or provide one via the --cloud flag.")
|
|
65
|
+
return ""
|
|
66
|
+
else: cloud_resolved = cloud
|
|
67
|
+
# repo_root = P(args.repo).expanduser().absolute()
|
|
68
|
+
repo_root = P.cwd() if path is None else P(path).expanduser().absolute()
|
|
69
|
+
repo_obj = install_n_import("git", "gitpython").Repo(repo_root, search_parent_directories=True)
|
|
70
|
+
repo_root = P(repo_obj.working_dir) # cwd might have been in a sub directory of repo_root, so its better to redefine it.
|
|
71
|
+
CONFIG_PATH.joinpath("remote").create()
|
|
72
|
+
repo_sync_root = CONFIG_PATH.joinpath("remote", repo_root.rel2home()) # .delete(sure=True)
|
|
73
|
+
try:
|
|
74
|
+
print("\n", "=============================== Downloading Remote Repo ====================================")
|
|
75
|
+
remote_path = repo_root.get_remote_path(rel2home=True, os_specific=False, root="myhome") + ".zip.enc"
|
|
76
|
+
repo_sync_root.from_cloud(remotepath=remote_path, cloud=cloud_resolved, unzip=True, decrypt=True, rel2home=True, os_specific=False, pwd=pwd)
|
|
77
|
+
except AssertionError:
|
|
78
|
+
print("Remote does not exist, creating it and exiting ... ")
|
|
79
|
+
repo_root.to_cloud(cloud=cloud_resolved, zip=True, encrypt=True, rel2home=True, pwd=pwd, os_specific=False)
|
|
80
|
+
return ""
|
|
81
|
+
repo_sync_obj = install_n_import("git", "gitpython").Repo(repo_sync_root)
|
|
82
|
+
if repo_sync_obj.is_dirty():
|
|
83
|
+
print("=" * 50, '\n', f"WRANING: the remote `{repo_sync_root}` is dirty, please commit or stash changes before proceeding.", '\n', "=" * 50)
|
|
84
|
+
|
|
85
|
+
script = f"""
|
|
86
|
+
echo ""
|
|
87
|
+
echo "=============================== Committing Local Changes ==================================="
|
|
88
|
+
cd {repo_root}
|
|
89
|
+
git status
|
|
90
|
+
git add .
|
|
91
|
+
git commit -am "{message}"
|
|
92
|
+
echo ""
|
|
93
|
+
echo ""
|
|
94
|
+
echo "=============================== Pulling Latest From Remote ================================"
|
|
95
|
+
cd {repo_root}
|
|
96
|
+
echo '-> Trying to removing originEnc remote from local repo if it exists.'
|
|
97
|
+
git remote remove originEnc
|
|
98
|
+
echo '-> Adding originEnc remote to local repo'
|
|
99
|
+
git remote add originEnc {repo_sync_root}
|
|
100
|
+
echo '-> Fetching originEnc remote.'
|
|
101
|
+
git pull originEnc master
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
suffix = '.ps1' if platform.system() == 'Windows' else '.sh'
|
|
105
|
+
res = Terminal().run(f". {P.tmpfile(suffix=suffix).write_text(script)}", shell="powershell").capture().print()
|
|
106
|
+
|
|
107
|
+
if res.is_successful(strict_err=True, strict_returcode=True):
|
|
108
|
+
print("\n", "Pull succeeded, removing originEnc, the local copy of remote & pushing merged repo_root to remote ... ")
|
|
109
|
+
repo_sync_root.delete(sure=True)
|
|
110
|
+
from git.remote import Remote
|
|
111
|
+
Remote.remove(repo_obj, "originEnc")
|
|
112
|
+
if push:
|
|
113
|
+
repo_root.to_cloud(cloud=cloud_resolved, zip=True, encrypt=True, rel2home=True, pwd=pwd, os_specific=False)
|
|
114
|
+
else:
|
|
115
|
+
print(f"Failed to pull, keeping local copy of remote at {repo_sync_root} ... ")
|
|
116
|
+
|
|
117
|
+
if push:
|
|
118
|
+
if skip_confirmation: resp = "y"
|
|
119
|
+
else: resp = input(f"Would you like to proceed syncing `{repo_root}` to `{cloud_resolved}` by pushing local changes to remote and deleting local copy of remote? y/[n] ") or "n"
|
|
120
|
+
else: resp = "n"
|
|
121
|
+
|
|
122
|
+
if resp.lower() == "y":
|
|
123
|
+
delete_remote_repo_copy_and_push_local(remote_repo=repo_sync_root.str, local_repo=repo_root.str, cloud=cloud_resolved)
|
|
124
|
+
else:
|
|
125
|
+
program = f"""
|
|
126
|
+
from machineconfig.scripts.python.cloud_repo_sync import delete_remote_repo_copy_and_push_local as func
|
|
127
|
+
func(remote_repo=r'{repo_sync_root.str}', local_repo=r'{repo_root.str}', cloud=r'{cloud_resolved}')
|
|
128
|
+
"""
|
|
129
|
+
shell_file = get_shell_file_executing_python_script(python_script=program)
|
|
130
|
+
print(f"When ready, use this snippet: \n. {shell_file}")
|
|
131
|
+
if platform.system() == "Windows":
|
|
132
|
+
program = get_wt_cmd(wd1=repo_root, wd2=repo_sync_root)
|
|
133
|
+
write_shell_script(program=program, execute=True)
|
|
134
|
+
return None
|
|
135
|
+
elif platform.system() == "Linux":
|
|
136
|
+
program = get_zellij_cmd(wd1=repo_root, wd2=repo_sync_root)
|
|
137
|
+
write_shell_script(program=program, execute=True)
|
|
138
|
+
return None
|
|
139
|
+
else: raise NotImplementedError(f"Platform {platform.system()} not implemented.")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def delete_remote_repo_copy_and_push_local(remote_repo: str, local_repo: str, cloud: str):
|
|
143
|
+
repo_sync_root = P(remote_repo).expanduser().absolute()
|
|
144
|
+
repo_root_path = P(local_repo).expanduser().absolute()
|
|
145
|
+
repo_sync_root.delete(sure=True)
|
|
146
|
+
from git.remote import Remote
|
|
147
|
+
from git.repo import Repo
|
|
148
|
+
try: Remote.remove(Repo(repo_root_path), "originEnc")
|
|
149
|
+
except Exception: pass # type: ignore
|
|
150
|
+
repo_root_path.to_cloud(cloud=cloud, zip=True, encrypt=True, rel2home=True, os_specific=False)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if __name__ == "__main__":
|
|
154
|
+
args_parser()
|