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
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
"""cli for scheduler
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from machineconfig.utils.scheduling import P, Report, DEFAULT_CONFIG, read_task_from_dir, main
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main_parse():
|
|
9
|
+
import argparse
|
|
10
|
+
parser = argparse.ArgumentParser(description='Run tasks.')
|
|
11
|
+
parser.add_argument('root', type=str, default=None, help='Root directory of tasks.')
|
|
12
|
+
parser.add_argument('--ignore_conditions', "-i", action='store_true', help='Ignore conditions for running tasks.', default=False)
|
|
13
|
+
parser.add_argument('--report', "-R", action='store_true', help='Print report.', default=False)
|
|
14
|
+
parser.add_argument('--create_task', "-c", action='store_true', help='Add default config.', default=False)
|
|
15
|
+
# print(parser)
|
|
16
|
+
args = parser.parse_args()
|
|
17
|
+
|
|
18
|
+
tmp = P(args.root).expanduser().absolute()
|
|
19
|
+
if P(args.root).joinpath(".scheduler").exists(): # .search(files=False, folders=True)[0].joinpath("task.py").exists():
|
|
20
|
+
root = P(args.root).joinpath(".scheduler")
|
|
21
|
+
if tmp.name == ".scheduler":
|
|
22
|
+
root = tmp
|
|
23
|
+
else:
|
|
24
|
+
root = tmp.joinpath(".scheduler").create()
|
|
25
|
+
# raise ValueError(f"Could not find a task.py in {args.root} or {P(args.root).joinpath('.scheduler')}")
|
|
26
|
+
print(f"✅ Running tasks in {root}")
|
|
27
|
+
|
|
28
|
+
if args.report:
|
|
29
|
+
reports: list[Report] = [Report.from_path(read_task_from_dir(x).report_path) for x in P(root).search("*").filter(lambda path: path.joinpath("task.py").exists())]
|
|
30
|
+
import pandas as pd
|
|
31
|
+
df_res = pd.DataFrame([r.__dict__ for r in reports])
|
|
32
|
+
# root.joinpath("task_report.md").write_text(df_res.to_markdown(), encoding="utf-8")
|
|
33
|
+
print(df_res.to_markdown())
|
|
34
|
+
# df_res.to_
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
if args.create_task:
|
|
38
|
+
task_name = input("Enter task name: ")
|
|
39
|
+
task_root = root.joinpath(task_name).create(exist_ok=False)
|
|
40
|
+
# assert not root.joinpath("config.ini").exists(), f"Config file already exists in {root}"
|
|
41
|
+
task_root.joinpath("config.ini").write_text(DEFAULT_CONFIG, encoding="utf-8")
|
|
42
|
+
task_root.joinpath("task.py").write_text(f"""
|
|
43
|
+
# Scheduler Task.
|
|
44
|
+
""")
|
|
45
|
+
print(f"✅ Task {task_name} created in {task_root}. Head there and edit the config.ini file & task.py file.")
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
main(root=root.str, ignore_conditions=args.ignore_conditions)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
main_parse()
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
from crocodile.msc.odds import capture_from_webcam
|
|
3
|
-
|
|
4
|
-
import argparse
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def main():
|
|
8
|
-
parser = argparse.ArgumentParser(description='FTP client')
|
|
9
|
-
parser.add_argument("--to_text", "-t", help="Send recursively.", action="store_true") # default is False
|
|
10
|
-
args = parser.parse_args()
|
|
11
|
-
|
|
12
|
-
img_path = capture_from_webcam(show=False, wait=False, save=True)
|
|
13
|
-
if args.to_text:
|
|
14
|
-
q =
|
|
15
|
-
print(q)
|
|
16
|
-
else:
|
|
17
|
-
print(img_path)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if __name__ == '__main__':
|
|
21
|
-
main()
|
|
1
|
+
|
|
2
|
+
from crocodile.msc.odds import capture_from_webcam
|
|
3
|
+
from crocodile.meta import Terminal
|
|
4
|
+
import argparse
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
parser = argparse.ArgumentParser(description='FTP client')
|
|
9
|
+
parser.add_argument("--to_text", "-t", help="Send recursively.", action="store_true") # default is False
|
|
10
|
+
args = parser.parse_args()
|
|
11
|
+
|
|
12
|
+
img_path = capture_from_webcam(show=False, wait=False, save=True)
|
|
13
|
+
if args.to_text:
|
|
14
|
+
q = Terminal().run(f"cd ~/AppData/Local/Tesseract-OCR; pytesseract '{img_path}'", shell="pwsh").capture().op
|
|
15
|
+
print(q)
|
|
16
|
+
else:
|
|
17
|
+
print(img_path)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == '__main__':
|
|
21
|
+
main()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
slidev
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from machineconfig.utils.utils import CONFIG_PATH, PROGRAM_PATH, print_code
|
|
7
|
+
from crocodile.meta import Terminal, P
|
|
8
|
+
# from crocodile.environment import get_network_addresses
|
|
9
|
+
import subprocess
|
|
10
|
+
import platform
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
PORT_DEFAULT = 3030
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
SLIDEV_REPO = CONFIG_PATH.joinpath(".cache/slidev")
|
|
17
|
+
if not SLIDEV_REPO.joinpath("components").exists():
|
|
18
|
+
# assert slidev is installed first
|
|
19
|
+
Terminal(stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE).run(f"cd {SLIDEV_REPO.parent};npm init slidev")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def jupyter_to_markdown(file: P):
|
|
23
|
+
op_dir = file.parent.joinpath("presentation")
|
|
24
|
+
|
|
25
|
+
# https://nbconvert.readthedocs.io/en/latest/nbconvert_library.html
|
|
26
|
+
# from nbconvert.exporters.markdown import MarkdownExporter
|
|
27
|
+
# import nbformat
|
|
28
|
+
# nb = nbformat.read(file, as_version=4)
|
|
29
|
+
# assert isinstance(nb, nbformat.notebooknode.NotebookNode), f"{file} is not a notebook"
|
|
30
|
+
# e = MarkdownExporter(exclude_input=True, exclude_input_prompt=True, exclude_output_prompt=True)
|
|
31
|
+
# body, resources = e.from_notebook_node(nb=nb)
|
|
32
|
+
# op_dir.joinpath("slides_raw.md").write_text(body)
|
|
33
|
+
# for key, value in resources['outputs'].items():
|
|
34
|
+
|
|
35
|
+
cmd = f"jupyter nbconvert --to markdown --no-prompt --no-input --output-dir {op_dir} --output slides_raw.md {file}"
|
|
36
|
+
Terminal().run(cmd, shell="powershell").print()
|
|
37
|
+
cmd = f"jupyter nbconvert --to html --no-prompt --no-input --output-dir {op_dir} {file}"
|
|
38
|
+
Terminal().run(cmd, shell="powershell").print()
|
|
39
|
+
# cmd = f"jupyter nbconvert --to pdf --no-prompt --no-input --output-dir {op_dir} {file}"
|
|
40
|
+
# Terminal().run(cmd, shell="powershell").print()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
op_file = op_dir.joinpath("slides_raw.md")
|
|
44
|
+
slide_separator = '\n\n---\n\n'
|
|
45
|
+
md = op_file.read_text().replace('\n\n\n\n', slide_separator)
|
|
46
|
+
md = slide_separator.join([item for item in md.split(slide_separator) if bool(item.strip())]) # remove empty slides.
|
|
47
|
+
op_file.with_name("slides.md").write_text(md)
|
|
48
|
+
return op_dir
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def main() -> None:
|
|
52
|
+
import argparse
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
parser = argparse.ArgumentParser()
|
|
56
|
+
parser.add_argument("-d", "--directory", default=None, help="Directory of the report")
|
|
57
|
+
parser.add_argument("-j", "--jupyter-file", default=None, help="Jupyter notebook file to convert to slides. If not provided, slides.md is used.")
|
|
58
|
+
parser.add_argument("--port", default=PORT_DEFAULT, help=f"Port to serve the report, default to {PORT_DEFAULT}")
|
|
59
|
+
args = parser.parse_args()
|
|
60
|
+
|
|
61
|
+
port = args.port
|
|
62
|
+
|
|
63
|
+
if args.jupyter_file is not None:
|
|
64
|
+
report_dir = jupyter_to_markdown(P(args.jupyter_file))
|
|
65
|
+
else:
|
|
66
|
+
if args.directory is None:
|
|
67
|
+
report_dir = P.cwd()
|
|
68
|
+
else:
|
|
69
|
+
report_dir = P(args.directory)
|
|
70
|
+
|
|
71
|
+
assert report_dir.exists(), f"{report_dir} does not exist"
|
|
72
|
+
assert report_dir.is_dir(), f"{report_dir} is not a directory"
|
|
73
|
+
|
|
74
|
+
md_file = report_dir.joinpath("slides.md")
|
|
75
|
+
if not md_file.exists():
|
|
76
|
+
res = report_dir.search("*.md")
|
|
77
|
+
if len(res) == 1:
|
|
78
|
+
md_file = res.list[0]
|
|
79
|
+
else:
|
|
80
|
+
raise FileNotFoundError(f"slides.md not found in {report_dir}")
|
|
81
|
+
|
|
82
|
+
report_dir.search().apply(lambda x: x.copy(folder=SLIDEV_REPO, overwrite=True))
|
|
83
|
+
if md_file.name != "slides.md":
|
|
84
|
+
SLIDEV_REPO.joinpath(md_file.name).with_name(name="slides.md", inplace=True, overwrite=True)
|
|
85
|
+
|
|
86
|
+
# from machineconfig.utils.utils import check_tool_exists
|
|
87
|
+
# check_tool_exists(tool_name="slidev", install_script="npm i -g @slidev/cli")
|
|
88
|
+
|
|
89
|
+
import socket
|
|
90
|
+
try: local_ip_v4 = socket.gethostbyname(socket.gethostname() + ".local") # without .local, in linux machines, '/etc/hosts' file content, you have an IP address mapping with '127.0.1.1' to your hostname
|
|
91
|
+
except Exception:
|
|
92
|
+
print(f"Warning: Could not get local_ip_v4. This is probably because you are running a WSL instance") # TODO find a way to get the local_ip_v4 in WSL
|
|
93
|
+
local_ip_v4 = socket.gethostbyname(socket.gethostname())
|
|
94
|
+
|
|
95
|
+
print(f"Presentation is served at http://{platform.node()}:{port}")
|
|
96
|
+
print(f"Presentation is served at http://localhost:{port}")
|
|
97
|
+
print(f"Presentation is served at http://{local_ip_v4}:{port}")
|
|
98
|
+
program: str = f"cd {SLIDEV_REPO}; slidev --port {port} --remote 0.0.0.0; cd {P.cwd()}"
|
|
99
|
+
PROGRAM_PATH.write_text(program)
|
|
100
|
+
print_code(program, lexer="bash")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if __name__ == '__main__':
|
|
104
|
+
main()
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
|
|
2
|
+
"""Script to start terminals on windows and wsl
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from machineconfig.utils.utils import PROGRAM_PATH, display_options, install_n_import, get_ssh_hosts, platform
|
|
6
|
+
from itertools import cycle
|
|
7
|
+
from typing import Literal
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
COLOR_SCHEMES = ["Campbell", "Campbell Powershell", "Solarized Dark", "Ubuntu-ColorScheme", "Retro"]
|
|
11
|
+
THEMES_ITER = cycle(COLOR_SCHEMES)
|
|
12
|
+
INIT_COMMANDS = ["ls", "lf", "cpufetch", "neofetch", "btm"]
|
|
13
|
+
INIT_COMMANDS_ITER = cycle(INIT_COMMANDS)
|
|
14
|
+
SIZE_ITER = cycle([0.6, 0.4, 0.3])
|
|
15
|
+
ORIENTATION = ["vertical", "horizontal"]
|
|
16
|
+
ORIENTATION_ITER = cycle(ORIENTATION)
|
|
17
|
+
ORIENTATION_TYPE = Literal["vertical", "horizontal"]
|
|
18
|
+
|
|
19
|
+
THIS_MACHINE = "this"
|
|
20
|
+
THIS_MACHINE_WSL = "thiswsl"
|
|
21
|
+
THIS_MACHINE_HOSTNAME = platform.node()
|
|
22
|
+
THIS_MACHINE_HOSTNAME_WSL = f"{THIS_MACHINE_HOSTNAME}wsl"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def main_windows_and_wsl(window: int, hosts: list[str], orientation: ORIENTATION_TYPE = "vertical", mprocs: bool = False):
|
|
26
|
+
orientation_oposite = "horizontal" if orientation == "vertical" else "vertical"
|
|
27
|
+
orientation_swap = "up" if orientation == "horizontal" else "left"
|
|
28
|
+
orientation_opposite_move_focus = "up" if orientation_oposite == "horizontal" else "left"
|
|
29
|
+
orientation_opposite_move_focus_other = "down" if orientation_oposite == "horizontal" else "right"
|
|
30
|
+
sleep = 3
|
|
31
|
+
sep = f"\nsleep {sleep}; wt --window {window}" # or '`;'
|
|
32
|
+
ssh_cmd = f"-t 'mprocs'" if mprocs else '' # 'wsl_ssh_windows_port_forwarding.ps1'
|
|
33
|
+
split_per_machine = 1 / len(hosts)
|
|
34
|
+
size = 0.3
|
|
35
|
+
known_hosts = get_ssh_hosts()
|
|
36
|
+
if len(hosts) == 1:
|
|
37
|
+
if "wsl" in hosts[0] or f"{hosts[0]}wsl" in known_hosts: # its a windows machine with wsl
|
|
38
|
+
host_wind = hosts[0] if "wsl" not in hosts[0] else hosts[0].split("wsl")[0]
|
|
39
|
+
host_linux = f"{host_wind}wsl"
|
|
40
|
+
cmd = f"""
|
|
41
|
+
wt --window {window} --title {hosts[0]} powershell -Command "ssh {host_linux} {ssh_cmd}" `; split-pane --{orientation} --title {hosts[0]}wsl --size 0.5 powershell -Command "ssh {host_wind} `; split-pane --{orientation_oposite} --size 0.5 powershell "
|
|
42
|
+
"""
|
|
43
|
+
else: # its a windows machine without wsl
|
|
44
|
+
cmd = f"""wt --window {window} --title {hosts[0]} powershell -Command "ssh {hosts[0]} {ssh_cmd}" `; split-pane --{orientation} --title {hosts[0]}wsl --size 0.1 powershell """
|
|
45
|
+
|
|
46
|
+
elif len(hosts) > 1:
|
|
47
|
+
pane_cmd = f'powershell -Command "ssh {hosts[0]} {ssh_cmd}" ' if hosts[0] != THIS_MACHINE else ''
|
|
48
|
+
cmd = f"""wt --window {window} --title {hosts[0]} {pane_cmd} """
|
|
49
|
+
for a_host in hosts[1:]:
|
|
50
|
+
if a_host != THIS_MACHINE: pane_cmd = f'powershell -Command "ssh {a_host} {ssh_cmd}" '
|
|
51
|
+
else: pane_cmd = 'powershell'
|
|
52
|
+
cmd += f"""{sep} split-pane --{orientation_oposite} --title {a_host}Windows --size {split_per_machine} {pane_cmd} """
|
|
53
|
+
for idx, a_host in enumerate(hosts[::-1]):
|
|
54
|
+
if f"{a_host}wsl" not in known_hosts and a_host != THIS_MACHINE: continue
|
|
55
|
+
pane_cmd = f'powershell -Command "ssh {a_host}wsl"' if a_host != THIS_MACHINE else 'wsl'
|
|
56
|
+
if idx == 0: tmp = ''
|
|
57
|
+
else: tmp = f"move-focus {orientation_opposite_move_focus}" if idx % 2 == 1 else f"move-focus {orientation_opposite_move_focus_other}"
|
|
58
|
+
cmd += f"""{sep} {tmp} split-pane --{orientation} --title {a_host}wsl --size {size} {pane_cmd} """
|
|
59
|
+
cmd += f"""{sep} swap-pane {orientation_swap} """
|
|
60
|
+
else: raise NotImplementedError(f"len(hosts) = {len(hosts)}. Only 1 or 2 hosts are supported.")
|
|
61
|
+
return cmd
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def main():
|
|
65
|
+
import argparse
|
|
66
|
+
parser = argparse.ArgumentParser()
|
|
67
|
+
parser.add_argument("--panes", "-p", type=int, help="The number of panes to open", default=4)
|
|
68
|
+
parser.add_argument("--vertical", "-V", action="store_true", help="Switch orientation to vertical from default horizontal")
|
|
69
|
+
parser.add_argument("--window", "-w", type=int, help="The window id to use", default=0) # 0 refers to this window.
|
|
70
|
+
parser.add_argument("--hosts", "-H", type=str, nargs="*", help="The hosts to connect to", default=None)
|
|
71
|
+
args = parser.parse_args()
|
|
72
|
+
|
|
73
|
+
if args.panes:
|
|
74
|
+
cmd = f"wt --window {args.window} --colorScheme '{next(THEMES_ITER)}' pwsh -NoExit -Command '{next(INIT_COMMANDS_ITER)}' "
|
|
75
|
+
cmd += f" `; new-tab --colorScheme '{next(THEMES_ITER)}' --profile pwsh --title 't2' --tabColor '#f59218' "
|
|
76
|
+
cmd += f" `; new-tab --colorScheme '{next(THEMES_ITER)}' --profile pwsh --title 't3' --tabColor '#009999' "
|
|
77
|
+
for idx in range(args.panes):
|
|
78
|
+
if idx % 2 == 0:
|
|
79
|
+
cmd += f" `; move-focus down split-pane --horizontal --size {next(SIZE_ITER)} --colorScheme '{next(THEMES_ITER)}' pwsh -NoExit -Command '{next(INIT_COMMANDS_ITER)}' "
|
|
80
|
+
else:
|
|
81
|
+
cmd += f" `; move-focus up split-pane --vertical --size {next(SIZE_ITER)} --colorScheme '{next(THEMES_ITER)}' pwsh -NoExit -Command '{next(INIT_COMMANDS_ITER)}' "
|
|
82
|
+
|
|
83
|
+
else:
|
|
84
|
+
if args.hosts is None: hosts = display_options(msg="", options=get_ssh_hosts() + [THIS_MACHINE], multi=True, fzf=True)
|
|
85
|
+
else:
|
|
86
|
+
print("Using provided hosts", args.hosts)
|
|
87
|
+
hosts = args.hosts
|
|
88
|
+
assert isinstance(hosts, list)
|
|
89
|
+
cmd = main_windows_and_wsl(window=args.window, hosts=hosts, orientation="vertical" if args.vertical else "horizontal")
|
|
90
|
+
|
|
91
|
+
print(cmd)
|
|
92
|
+
install_n_import("clipboard").copy(cmd)
|
|
93
|
+
PROGRAM_PATH.write_text(cmd)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == '__main__':
|
|
97
|
+
main()
|
|
@@ -1,71 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
|
|
2
|
+
"""Wifi connect
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import configparser
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
# import random
|
|
9
|
+
# import string
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def create_new_connection(name: str, ssid: str, password: str):
|
|
14
|
+
config = """<?xml version=\"1.0\"?>
|
|
15
|
+
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
|
|
16
|
+
<name>""" + name + """</name>
|
|
17
|
+
<SSIDConfig>
|
|
18
|
+
<SSID>
|
|
19
|
+
<name>""" + ssid + """</name>
|
|
20
|
+
</SSID>
|
|
21
|
+
</SSIDConfig>
|
|
22
|
+
<connectionType>ESS</connectionType>
|
|
23
|
+
<connectionMode>auto</connectionMode>
|
|
24
|
+
<MSM>
|
|
25
|
+
<security>
|
|
26
|
+
<authEncryption>
|
|
27
|
+
<authentication>WPA2PSK</authentication>
|
|
28
|
+
<encryption>AES</encryption>
|
|
29
|
+
<useOneX>false</useOneX>
|
|
30
|
+
</authEncryption>
|
|
31
|
+
<sharedKey>
|
|
32
|
+
<keyType>passPhrase</keyType>
|
|
33
|
+
<protected>false</protected>
|
|
34
|
+
<keyMaterial>""" + password + """</keyMaterial>
|
|
35
|
+
</sharedKey>
|
|
36
|
+
</security>
|
|
37
|
+
</MSM>
|
|
38
|
+
</WLANProfile>"""
|
|
39
|
+
command = "netsh wlan add profile filename=\"" + name + ".xml\"" + " interface=Wi-Fi"
|
|
40
|
+
with open(name + ".xml", mode='w', encoding="utf-8") as file: file.write(config)
|
|
41
|
+
os.system(command)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def connect(name: str, ssid: str):
|
|
45
|
+
command = "netsh wlan connect name=\"" + name + "\" ssid=\"" + ssid + "\" interface=Wi-Fi"
|
|
46
|
+
os.system(command)
|
|
47
|
+
def display_available_networks(): os.system("netsh wlan show networks interface=Wi-Fi") #
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def main():
|
|
51
|
+
creds = configparser.ConfigParser()
|
|
52
|
+
creds.read(Path.home().joinpath('dotfiles/machineconfig/setup/wifi.ini'))
|
|
53
|
+
|
|
54
|
+
parser = argparse.ArgumentParser(description='Wifi Connector')
|
|
55
|
+
parser.add_argument('-n', "--ssid", help=f"SSID of Wifi", default='MyPhoneHotSpot')
|
|
56
|
+
|
|
57
|
+
args = parser.parse_args()
|
|
58
|
+
ssid = creds[args.ssid]['SSID']
|
|
59
|
+
# pwd = creds[args.ssid]['pwd']
|
|
60
|
+
|
|
61
|
+
# displayAvailableNetworks()
|
|
62
|
+
# createNewConnection(name, name, password)
|
|
63
|
+
connect(ssid, ssid)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get_current_wifi_name() -> str:
|
|
67
|
+
import subprocess
|
|
68
|
+
import platform
|
|
69
|
+
if platform.system() == "Windows":
|
|
70
|
+
try:
|
|
71
|
+
cmd_output = subprocess.check_output(["netsh", "wlan", "show", "interface"], shell=True).decode("utf-8")
|
|
72
|
+
wifi_name_line = [line for line in cmd_output.split("\n") if "SSID" in line][0]
|
|
73
|
+
wifi_name = wifi_name_line.split(":")[1].strip()
|
|
74
|
+
return wifi_name
|
|
75
|
+
except Exception as e:
|
|
76
|
+
print(e)
|
|
77
|
+
return "Not connected to WiFi"
|
|
78
|
+
elif platform.system() == "Linux":
|
|
79
|
+
try:
|
|
80
|
+
cmd_output = subprocess.check_output(["iwgetid", "-r"], universal_newlines=True)
|
|
81
|
+
wifi_name = cmd_output.strip()
|
|
82
|
+
return wifi_name
|
|
83
|
+
except Exception as e:
|
|
84
|
+
print(e)
|
|
85
|
+
return "Not connected to WiFi"
|
|
86
|
+
else: raise NotImplementedError(f"System {platform.system()} not supported.")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == '__main__':
|
|
90
|
+
main()
|
|
@@ -1,39 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
#
|
|
16
|
-
parser.add_argument("
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
parser.add_argument("--
|
|
20
|
-
|
|
21
|
-
parser.add_argument("--
|
|
22
|
-
parser.add_argument("--
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
|
|
2
|
+
"""TWSL
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from crocodile.file_management import P
|
|
6
|
+
from crocodile.environment import WIN_FROM_WSL, system, WSL_FROM_WIN, UserName
|
|
7
|
+
import argparse
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
parser = argparse.ArgumentParser(description="""Move and copy files across between WSL & Windows."
|
|
12
|
+
The direction is automatically determined by sensing the execution environment.
|
|
13
|
+
Otherwise, a flag must be raised to indicate the direction.""")
|
|
14
|
+
|
|
15
|
+
# positional argument
|
|
16
|
+
parser.add_argument("path", help="path of file/folder to transfer over.")
|
|
17
|
+
# FLAGS
|
|
18
|
+
# this is dangerous and no gaurantee on no corruption.
|
|
19
|
+
parser.add_argument("--same_file_system", "-s", help="Move file.", action="store_true") # default is False
|
|
20
|
+
# optional argument
|
|
21
|
+
parser.add_argument("--destination", "-d", help="New path.", default="")
|
|
22
|
+
parser.add_argument("--pwd", "-P", help="Password for encryption", default=None)
|
|
23
|
+
parser.add_argument("--sshkey", "-i", help="path to ssh private key", default=None)
|
|
24
|
+
parser.add_argument("--port", "-p", help="port number", default=None)
|
|
25
|
+
parser.add_argument("--zip_first", "-z", help="Zip before transferring.", action="store_true") # default is False
|
|
26
|
+
|
|
27
|
+
args = parser.parse_args()
|
|
28
|
+
path = P(args.path).expanduser().absolute()
|
|
29
|
+
|
|
30
|
+
if args.same_file_system:
|
|
31
|
+
print(f"💥 Using a not recommended transfer method! Copying same files across different file systems.")
|
|
32
|
+
if system == "Windows": # move files over to WSL
|
|
33
|
+
path.copy(folder=WSL_FROM_WIN.joinpath(UserName).joinpath(path.rel2home().parent), overwrite=True) # the following works for files and folders alike.
|
|
34
|
+
else: # move files from WSL to win
|
|
35
|
+
path.copy(folder=WIN_FROM_WSL.joinpath(UserName).joinpath(path.rel2home().parent), overwrite=True)
|
|
36
|
+
else:
|
|
37
|
+
from crocodile.meta import SSH
|
|
38
|
+
import platform
|
|
39
|
+
port = int(args.port) if args.port else (2222 if system == "Windows" else 22)
|
|
40
|
+
username = UserName
|
|
41
|
+
hostname = platform.node()
|
|
42
|
+
ssh = SSH(hostname=hostname, username=username, port=port, sshkey=args.sshkey)
|
|
43
|
+
ssh.copy_from_here(source=path, target=args.destination, z=args.zip_first)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == '__main__':
|
|
47
|
+
main()
|
|
@@ -1,48 +1,44 @@
|
|
|
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
|
-
if __name__ == '__main__':
|
|
48
|
-
pass
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
setup file for each shell can be found in $profile. The settings.json is the config file for Terminal.
|
|
4
|
+
https://glitchbone.github.io/vscode-base16-term/#/3024
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# # import crocodile.environment as env
|
|
10
|
+
from crocodile.file_management import P
|
|
11
|
+
# from crocodile.meta import Terminal
|
|
12
|
+
from machineconfig.utils.utils import LIBRARY_ROOT
|
|
13
|
+
from machineconfig.utils.installer import Installer
|
|
14
|
+
# import os
|
|
15
|
+
import subprocess
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
nerd_fonts = {
|
|
19
|
+
"repo_url": "https://github.com/ryanoasis/nerd-fonts",
|
|
20
|
+
"doc": "Nerd Fonts is a project that patches developer targeted fonts with a high number of glyphs (icons)",
|
|
21
|
+
"filename_template_windows_amd_64": "CascadiaCode.zip",
|
|
22
|
+
"filename_template_linux_amd_64": "CascadiaCode.zip",
|
|
23
|
+
"strip_v": False,
|
|
24
|
+
"exe_name": "nerd_fonts"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def install_nerd_fonts():
|
|
29
|
+
# Step 1: download the required fonts that has all the glyphs and install them.
|
|
30
|
+
folder, _version_to_be_installed = Installer.from_dict(d=nerd_fonts, name="nerd_fonts").download(version=None)
|
|
31
|
+
folder.search("*Windows*").apply(lambda p: p.delete(sure=True))
|
|
32
|
+
folder.search("*readme*").apply(lambda p: p.delete(sure=True))
|
|
33
|
+
folder.search("*LICENSE*").apply(lambda p: p.delete(sure=True))
|
|
34
|
+
file = P.tmpfile(suffix=".ps1").write_text(LIBRARY_ROOT.joinpath("setup_windows/wt_and_pwsh/install_fonts.ps1").read_text().replace(r".\fonts-to-be-installed", str(folder)))
|
|
35
|
+
subprocess.run(rf"powershell.exe -executionpolicy Bypass -nologo -noninteractive -File {file.str}", check=True)
|
|
36
|
+
folder.delete(sure=True)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main():
|
|
40
|
+
install_nerd_fonts()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == '__main__':
|
|
44
|
+
pass
|