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.

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