atomicshop 3.3.8__py3-none-any.whl → 3.10.0__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 atomicshop might be problematic. Click here for more details.

Files changed (120) hide show
  1. atomicshop/__init__.py +1 -1
  2. atomicshop/a_mains/get_local_tcp_ports.py +85 -0
  3. atomicshop/a_mains/install_ca_certificate.py +172 -0
  4. atomicshop/a_mains/process_from_port.py +119 -0
  5. atomicshop/a_mains/set_default_dns_gateway.py +90 -0
  6. atomicshop/basics/strings.py +1 -1
  7. atomicshop/certificates.py +2 -2
  8. atomicshop/dns.py +26 -28
  9. atomicshop/etws/traces/trace_tcp.py +1 -2
  10. atomicshop/mitm/centered_settings.py +133 -0
  11. atomicshop/mitm/config_static.py +22 -44
  12. atomicshop/mitm/connection_thread_worker.py +383 -165
  13. atomicshop/mitm/engines/__parent/recorder___parent.py +1 -1
  14. atomicshop/mitm/engines/__parent/requester___parent.py +1 -1
  15. atomicshop/mitm/engines/__parent/responder___parent.py +15 -2
  16. atomicshop/mitm/engines/create_module_template.py +1 -2
  17. atomicshop/mitm/import_config.py +91 -89
  18. atomicshop/mitm/initialize_engines.py +1 -2
  19. atomicshop/mitm/message.py +5 -4
  20. atomicshop/mitm/mitm_main.py +238 -122
  21. atomicshop/mitm/recs_files.py +61 -5
  22. atomicshop/mitm/ssh_tester.py +82 -0
  23. atomicshop/mitm/statistic_analyzer.py +33 -12
  24. atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +104 -31
  25. atomicshop/networks.py +160 -92
  26. atomicshop/package_mains_processor.py +84 -0
  27. atomicshop/permissions/ubuntu_permissions.py +47 -0
  28. atomicshop/print_api.py +3 -5
  29. atomicshop/process.py +11 -4
  30. atomicshop/python_functions.py +23 -108
  31. atomicshop/speech_recognize.py +8 -0
  32. atomicshop/ssh_remote.py +140 -164
  33. atomicshop/web.py +63 -22
  34. atomicshop/web_apis/google_llm.py +22 -14
  35. atomicshop/wrappers/ctyping/msi_windows_installer/cabs.py +2 -1
  36. atomicshop/wrappers/ctyping/msi_windows_installer/extract_msi_main.py +2 -1
  37. atomicshop/wrappers/dockerw/dockerw.py +2 -2
  38. atomicshop/wrappers/elasticsearchw/config_basic.py +0 -12
  39. atomicshop/wrappers/elasticsearchw/elastic_infra.py +0 -190
  40. atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +5 -5
  41. atomicshop/wrappers/githubw.py +180 -68
  42. atomicshop/wrappers/loggingw/consts.py +1 -1
  43. atomicshop/wrappers/loggingw/handlers.py +1 -1
  44. atomicshop/wrappers/loggingw/loggingw.py +20 -4
  45. atomicshop/wrappers/loggingw/reading.py +18 -0
  46. atomicshop/wrappers/mongodbw/mongo_infra.py +0 -38
  47. atomicshop/wrappers/netshw.py +124 -3
  48. atomicshop/wrappers/playwrightw/scenarios.py +1 -1
  49. atomicshop/wrappers/powershell_networking.py +80 -0
  50. atomicshop/wrappers/psutilw/psutil_networks.py +9 -0
  51. atomicshop/wrappers/pywin32w/win_event_log/fetch.py +174 -0
  52. atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_create.py +3 -105
  53. atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_terminate.py +3 -57
  54. atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +12 -27
  55. atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +15 -9
  56. atomicshop/wrappers/socketw/certificator.py +19 -9
  57. atomicshop/wrappers/socketw/creator.py +101 -14
  58. atomicshop/wrappers/socketw/dns_server.py +17 -5
  59. atomicshop/wrappers/socketw/exception_wrapper.py +21 -16
  60. atomicshop/wrappers/socketw/process_getter.py +86 -0
  61. atomicshop/wrappers/socketw/receiver.py +29 -9
  62. atomicshop/wrappers/socketw/sender.py +10 -9
  63. atomicshop/wrappers/socketw/sni.py +31 -10
  64. atomicshop/wrappers/socketw/{base.py → socket_base.py} +33 -1
  65. atomicshop/wrappers/socketw/socket_client.py +11 -10
  66. atomicshop/wrappers/socketw/socket_wrapper.py +125 -32
  67. atomicshop/wrappers/socketw/ssl_base.py +6 -2
  68. atomicshop/wrappers/ubuntu_terminal.py +21 -18
  69. atomicshop/wrappers/win_auditw.py +189 -0
  70. {atomicshop-3.3.8.dist-info → atomicshop-3.10.0.dist-info}/METADATA +25 -30
  71. {atomicshop-3.3.8.dist-info → atomicshop-3.10.0.dist-info}/RECORD +83 -109
  72. atomicshop/_basics_temp.py +0 -101
  73. atomicshop/a_installs/ubuntu/docker_rootless.py +0 -11
  74. atomicshop/a_installs/ubuntu/docker_sudo.py +0 -11
  75. atomicshop/a_installs/ubuntu/elastic_search_and_kibana.py +0 -10
  76. atomicshop/a_installs/ubuntu/mongodb.py +0 -12
  77. atomicshop/a_installs/win/fibratus.py +0 -9
  78. atomicshop/a_installs/win/mongodb.py +0 -9
  79. atomicshop/a_installs/win/wsl_ubuntu_lts.py +0 -10
  80. atomicshop/addons/a_setup_scripts/install_psycopg2_ubuntu.sh +0 -3
  81. atomicshop/addons/package_setup/CreateWheel.cmd +0 -7
  82. atomicshop/addons/package_setup/Setup in Edit mode.cmd +0 -6
  83. atomicshop/addons/package_setup/Setup.cmd +0 -7
  84. atomicshop/archiver/__init__.py +0 -0
  85. atomicshop/archiver/_search_in_zip.py +0 -189
  86. atomicshop/archiver/search_in_archive.py +0 -284
  87. atomicshop/archiver/sevenz_app_w.py +0 -86
  88. atomicshop/archiver/sevenzs.py +0 -73
  89. atomicshop/archiver/shutils.py +0 -34
  90. atomicshop/archiver/zips.py +0 -353
  91. atomicshop/file_types.py +0 -24
  92. atomicshop/pbtkmultifile_argparse.py +0 -88
  93. atomicshop/script_as_string_processor.py +0 -42
  94. atomicshop/ssh_scripts/process_from_ipv4.py +0 -37
  95. atomicshop/ssh_scripts/process_from_port.py +0 -27
  96. atomicshop/wrappers/_process_wrapper_curl.py +0 -27
  97. atomicshop/wrappers/_process_wrapper_tar.py +0 -21
  98. atomicshop/wrappers/dockerw/install_docker.py +0 -449
  99. atomicshop/wrappers/elasticsearchw/install_elastic.py +0 -233
  100. atomicshop/wrappers/ffmpegw.py +0 -125
  101. atomicshop/wrappers/fibratusw/__init__.py +0 -0
  102. atomicshop/wrappers/fibratusw/install.py +0 -80
  103. atomicshop/wrappers/mongodbw/install_mongodb_ubuntu.py +0 -100
  104. atomicshop/wrappers/mongodbw/install_mongodb_win.py +0 -244
  105. atomicshop/wrappers/process_wrapper_pbtk.py +0 -16
  106. atomicshop/wrappers/socketw/get_process.py +0 -123
  107. atomicshop/wrappers/wslw.py +0 -192
  108. atomicshop-3.3.8.dist-info/entry_points.txt +0 -2
  109. /atomicshop/{addons → a_mains/addons}/PlayWrightCodegen.cmd +0 -0
  110. /atomicshop/{addons → a_mains/addons}/ScriptExecution.cmd +0 -0
  111. /atomicshop/{addons → a_mains/addons}/inits/init_to_import_all_modules.py +0 -0
  112. /atomicshop/{addons → a_mains/addons}/process_list/ReadMe.txt +0 -0
  113. /atomicshop/{addons → a_mains/addons}/process_list/compile.cmd +0 -0
  114. /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.dll +0 -0
  115. /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.exp +0 -0
  116. /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.lib +0 -0
  117. /atomicshop/{addons → a_mains/addons}/process_list/process_list.cpp +0 -0
  118. {atomicshop-3.3.8.dist-info → atomicshop-3.10.0.dist-info}/WHEEL +0 -0
  119. {atomicshop-3.3.8.dist-info → atomicshop-3.10.0.dist-info}/licenses/LICENSE.txt +0 -0
  120. {atomicshop-3.3.8.dist-info → atomicshop-3.10.0.dist-info}/top_level.txt +0 -0
@@ -1,125 +0,0 @@
1
- import fnmatch
2
- import os
3
- import shlex
4
-
5
- from ..print_api import print_api
6
- from ..tempfiles import TempFile
7
- from .githubw import GitHubWrapper
8
- from ..process import execute_with_live_output
9
- from ..filesystem import create_directory
10
-
11
-
12
- class FFmpegWrapper:
13
- def __init__(self, working_directory: str = str(), ffmpeg_exe_path: str = str()):
14
- self.working_directory: str = working_directory
15
- self.ffmpeg_exe_path: str = ffmpeg_exe_path
16
- self.relative_path: str = 'bin'
17
- self.ffmpeg_exe_name: str = 'ffmpeg.exe'
18
-
19
- # Variables to download the latest release from GitHub in case execution fails.
20
- self.git_user: str = 'GyanD'
21
- self.git_repo: str = 'codexffmpeg'
22
- self.git_latest_release_pattern: str = '*full_build.zip'
23
-
24
- # ffmpeg Release directory name.
25
- self.ffmpeg_release_directory_name: str = \
26
- f"ffmpeg_{self.git_latest_release_pattern.replace('*', '').split('.')[0]}"
27
- self.ffmpeg_release_directory_path: str = str()
28
-
29
- # Execute functions.
30
- self.build_ffmpeg_exe_and_directory_path()
31
-
32
- def build_ffmpeg_exe_and_directory_path(self):
33
- # If working directory was specified, but not the full path to exe.
34
- if self.working_directory and not self.ffmpeg_exe_path:
35
- self.ffmpeg_release_directory_path = self.working_directory + os.sep + self.ffmpeg_release_directory_name
36
- self.ffmpeg_exe_path = \
37
- self.ffmpeg_release_directory_path + os.sep + self.relative_path + os.sep + self.ffmpeg_exe_name
38
- # If no working directory and no path to exe was specified.
39
- elif not self.working_directory and not self.ffmpeg_exe_path:
40
- # Use just 'ffmpeg.exe' as path to exe. Maybe it is already installed and is in environment PATH var.
41
- self.ffmpeg_exe_path = self.ffmpeg_exe_name
42
-
43
- def change_to_temp_directory(self):
44
- temp_file = TempFile()
45
- self.working_directory = temp_file.directory
46
- self.ffmpeg_exe_path = str()
47
- self.build_ffmpeg_exe_and_directory_path()
48
-
49
- def download_ffmpeg_and_extract(self):
50
- github_wrapper = GitHubWrapper(user_name=self.git_user, repo_name=self.git_repo)
51
- github_wrapper.build_links_from_user_and_repo()
52
- github_wrapper.download_and_extract_latest_release(
53
- target_directory=self.ffmpeg_release_directory_path, string_pattern=self.git_latest_release_pattern,
54
- archive_remove_first_directory=True)
55
-
56
- def execute_ffmpeg(self, cmd_list: list):
57
- continue_loop: bool = True
58
- while continue_loop:
59
- # If first entry contains 'ffmpeg.exe' and it is not 'self.ffmpeg_exe_path' already.
60
- if self.ffmpeg_exe_name in cmd_list[0] and cmd_list[0] != self.ffmpeg_exe_path:
61
- # We'll change it to the updated one.
62
- cmd_list[0] = self.ffmpeg_exe_path
63
- # If first entry doesn't contain 'ffmpeg.exe'.
64
- elif self.ffmpeg_exe_name not in cmd_list[0]:
65
- # We'll insert the current path into first entry.
66
- cmd_list.insert(0, self.ffmpeg_exe_path)
67
-
68
- output_strings: list = [
69
- 'Input',
70
- 'Output',
71
- 'video:'
72
- ]
73
-
74
- try:
75
- print(f'FFmpeg processing: {shlex.join(cmd_list)}')
76
- result_lines = execute_with_live_output(
77
- cmd=cmd_list, output_strings=output_strings, raise_exception=True, exit_on_error=False)
78
- # If 'ffmpeg.exe' is non-existent.
79
- except FileNotFoundError:
80
- # Check if full path to 'ffmpeg.exe' is just 'ffmpeg.exe'.
81
- if self.ffmpeg_exe_path == self.ffmpeg_exe_name:
82
- print_api('Will try temp folder...', raise_exception=False)
83
- # Change to temp folder and try executing again.
84
- self.change_to_temp_directory()
85
- continue
86
-
87
- print_api('Trying to download...', raise_exception=False)
88
- create_directory(self.ffmpeg_release_directory_path)
89
- self.download_ffmpeg_and_extract()
90
- continue
91
-
92
- # === At this point python exceptions are finished. ==========================
93
- # If 'Invalid argument' was returned by 'ffmpeg' in the last line.
94
- if 'Invalid argument' in result_lines[-1]:
95
- print_api(result_lines[-1], message_type_error=True, color="red", exit_on_error=True)
96
-
97
- # === Successful execution section ==========================================
98
- string_pattern = 'video:*audio:*subtitle*'
99
- # if 'video:' in result_lines[-1] and 'audio:' in result_lines[-1] and 'subtitle:' in result_lines[-1]:
100
- if fnmatch.fnmatch(result_lines[-1], string_pattern):
101
- print_api(f'FFmpeg finished successfully.', color="green")
102
-
103
- # Since exceptions are finished, we can stop the while loop.
104
- continue_loop = False
105
-
106
- def convert_file(self, source_file_path: str, dest_file_path: str, overwrite: bool = False) -> None:
107
- """
108
- The function converts source file to destination file. The source format is defined by the file extension
109
- as well as destination file format defined by the destination file extension.
110
-
111
- Example convert MP3 file to WAV:
112
- convert_file(source_file_path=some_music.mp3, dest_file_path=converted_file.wav)
113
-
114
- :param source_file_path: string, full file path to source file.
115
- :param dest_file_path: string, full file path to destination file.
116
- :param overwrite: boolean, set if destination file should be overwritten if it exists.
117
- :return: None.
118
- """
119
-
120
- cmd_list = ['-i', source_file_path, dest_file_path]
121
-
122
- if overwrite:
123
- cmd_list.append('-y')
124
-
125
- self.execute_ffmpeg(cmd_list)
File without changes
@@ -1,80 +0,0 @@
1
- import os.path
2
- import subprocess
3
- import time
4
- from typing import Literal
5
-
6
- from .. import githubw, msiw
7
- from ... import filesystem
8
- from ...print_api import print_api
9
-
10
-
11
- DEFAULT_INSTALLATION_EXE_PATH = r"C:\Program Files\Fibratus\Bin\fibratus.exe"
12
- WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION: float = 10
13
-
14
-
15
- def install_fibratus(
16
- installation_file_download_directory: str = None,
17
- place_to_download_file: Literal['working', 'temp', 'script'] = 'temp',
18
- remove_file_after_installation: bool = False
19
- ):
20
- """
21
- Download latest release from GitHub and install Fibratus.
22
- :param installation_file_download_directory: Directory to download the installation file. If None, the download
23
- directory will be automatically determined, by the 'place_to_download_file' parameter.
24
- :param place_to_download_file: Where to download the installation file.
25
- 'working' is the working directory of the script.
26
- 'temp' is the temporary directory.
27
- 'script' is the directory of the script.
28
- :param remove_file_after_installation: Whether to remove the installation file after installation.
29
- :return:
30
- """
31
-
32
- if not installation_file_download_directory:
33
- installation_file_download_directory = filesystem.get_download_directory(
34
- place=place_to_download_file, script_path=__file__)
35
-
36
- github_wrapper = githubw.GitHubWrapper(user_name='rabbitstack', repo_name='fibratus')
37
- fibratus_setup_file_path: str = github_wrapper.download_latest_release(
38
- target_directory=installation_file_download_directory,
39
- string_pattern='*fibratus-*-amd64.msi',
40
- exclude_string='slim')
41
-
42
- # Install the MSI file
43
- msiw.install_msi(msi_path=fibratus_setup_file_path)
44
-
45
- count = 0
46
- while count != WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION:
47
- if os.path.isfile(DEFAULT_INSTALLATION_EXE_PATH):
48
- break
49
- count += 1
50
- time.sleep(1)
51
-
52
- if count == WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION:
53
- message = \
54
- (f"Fibratus installation failed. The executable was not found after "
55
- f"{str(WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION)} seconds.\n"
56
- f"{DEFAULT_INSTALLATION_EXE_PATH}")
57
- print_api(message, color="red")
58
-
59
- result = None
60
- # Check if the installation was successful
61
- try:
62
- result = subprocess.run([DEFAULT_INSTALLATION_EXE_PATH], capture_output=True, text=True)
63
- except FileNotFoundError:
64
- print_api("Fibratus executable not found.", color="red")
65
-
66
- if result:
67
- if result.returncode == 0:
68
- print_api("Fibratus installed successfully. Please restart.", color="green")
69
- else:
70
- print_api("Fibratus installation failed.", color="red")
71
- print_api(result.stderr)
72
- raise Exception("Fibratus installation failed.")
73
- else:
74
- print_api("Fibratus executable not found.", color="red")
75
-
76
- # Wait for the installation to finish before removing the file.
77
- time.sleep(5)
78
-
79
- if remove_file_after_installation:
80
- filesystem.remove_file(fibratus_setup_file_path)
@@ -1,100 +0,0 @@
1
- import subprocess
2
- import sys
3
- import os
4
-
5
-
6
- from ... import print_api, web
7
- from .. import ubuntu_terminal
8
- from ...permissions import ubuntu_permissions
9
-
10
-
11
- COMPASS_INSTALLATION_SCRIPT_URL: str = \
12
- 'https://raw.githubusercontent.com/mongodb/mongo/master/src/mongo/installer/compass/install_compass'
13
-
14
-
15
- def run_command(command):
16
- """Run a system command and exit if the command fails."""
17
- try:
18
- subprocess.run(command, check=True, shell=True)
19
- except subprocess.CalledProcessError as e:
20
- print_api.print_api(f"Error: {e}", color='red')
21
- sys.exit(1)
22
-
23
-
24
- def install_mongodb(version):
25
- """Install the specified major version of MongoDB on Ubuntu."""
26
-
27
- if not version.endswith(".0"):
28
- version = f"{version}.0"
29
-
30
- print_api.print_api(f"Installing MongoDB {version} on Ubuntu...")
31
- print_api.print_api(f"Installing Prerequisites...")
32
- ubuntu_terminal.update_system_packages()
33
- ubuntu_terminal.install_packages(["wget", "curl", "gnupg"])
34
-
35
- # Step 1: Import the MongoDB public GPG key
36
- print_api.print_api("Step 1: Importing the MongoDB public GPG key...")
37
- run_command(f"curl -fsSL https://pgp.mongodb.com/server-{version}.asc | "
38
- f"sudo gpg --dearmor --yes -o /usr/share/keyrings/mongodb-server-{version}.gpg")
39
-
40
- # Step 2: Create the MongoDB list file for APT
41
- print_api.print_api("Step 2: Creating MongoDB APT list file...")
42
- distro_version = subprocess.check_output("lsb_release -sc", shell=True).decode('utf-8').strip()
43
- run_command(
44
- f"echo 'deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-{version}.gpg ] "
45
- f"https://repo.mongodb.org/apt/ubuntu {distro_version}/mongodb-org/{version} multiverse' | "
46
- f"sudo tee /etc/apt/sources.list.d/mongodb-org-{version}.list")
47
-
48
- # Step 3: Update the APT package index
49
- print_api.print_api("Step 3: Updating the APT package index...")
50
- ubuntu_terminal.update_system_packages()
51
-
52
- # Step 4: Install the latest version of MongoDB for the specified major version
53
- print_api.print_api(f"Step 4: Installing MongoDB version {version}...")
54
- ubuntu_terminal.install_packages(["mongodb-org"])
55
-
56
- # Step 5: Start MongoDB service and enable it on startup
57
- print_api.print_api("Step 5: Starting MongoDB service and enabling it on startup...")
58
- ubuntu_terminal.start_enable_service_check_availability("mongod")
59
-
60
- print_api.print_api(f"MongoDB {version} installation complete!", color='green')
61
-
62
-
63
- def install_main(
64
- compass: bool = False,
65
- ):
66
- """
67
- Install the latest minor version of MongoDB Community Server on Ubuntu by providing the major version.
68
- :param compass: bool, if True, MongoDB Compass will be installed.
69
- :return:
70
- """
71
- # Ensure the user provides a MongoDB major version as an argument.
72
- if len(sys.argv) != 2:
73
- message: str = ("Usage: python install_mongodb.py <mongo_major_version>\n"
74
- "Example: python install_mongodb.py 8")
75
- print_api.print_api(message, color='red')
76
- return 1
77
-
78
- mongo_version = sys.argv[1]
79
-
80
- # Call the 'install' function with the major version.
81
- install_mongodb(mongo_version)
82
-
83
- if not compass:
84
- return 0
85
-
86
- # It doesn't matter what you do with the MSI it will not install Compass, only if you run it manually.
87
- # So we will use installation script from their GitHub.
88
- print_api.print_api("Downloading MongoDB Compass installation script...")
89
- compass_script_path: str = web.download(COMPASS_INSTALLATION_SCRIPT_URL)
90
-
91
- print_api.print_api("Installing MongoDB Compass from script...")
92
- ubuntu_permissions.set_executable(compass_script_path)
93
- run_command(f'sudo -E python3 {compass_script_path}')
94
-
95
- # Clean up the installer file
96
- if os.path.exists(compass_script_path):
97
- os.remove(compass_script_path)
98
- print_api.print_api("Cleaned up the Compass installer file.")
99
-
100
- return 0
@@ -1,244 +0,0 @@
1
- import os
2
- import requests
3
- from typing import Union
4
- import argparse
5
- import subprocess
6
-
7
- from ... import urls, web
8
- from ...permissions import permissions
9
- from ...print_api import print_api
10
- from .. import msiw
11
- from . import mongo_infra
12
-
13
-
14
- MONGODB_DOWNLOAD_PAGE_URL: str = 'https://www.mongodb.com/try/download/community'
15
- COMPASS_INSTALLATION_SCRIPT_URL: str = \
16
- 'https://raw.githubusercontent.com/mongodb/mongo/master/src/mongo/installer/compass/Install-Compass.ps1'
17
-
18
-
19
- class MongoDBWebPageNoSuccessCodeError(Exception):
20
- pass
21
-
22
-
23
- class MongoDBNoDownloadLinksError(Exception):
24
- pass
25
-
26
-
27
- class MongoDBNoDownloadLinkForWindowsError(Exception):
28
- pass
29
-
30
-
31
- class MongoDBInstallationError(Exception):
32
- pass
33
-
34
-
35
- def get_latest_mongodb_download_url(
36
- rc_version: bool = True,
37
- major_specific: int = None
38
- ):
39
- response = requests.get(MONGODB_DOWNLOAD_PAGE_URL)
40
-
41
- if response.status_code != 200:
42
- raise MongoDBWebPageNoSuccessCodeError("Failed to load the download page.")
43
-
44
- urls_in_page: list = urls.find_urls_in_text(response.text)
45
- if not urls_in_page:
46
- raise MongoDBNoDownloadLinksError("Could not find the download link for MongoDB Community Server.")
47
-
48
- windows_urls: list = []
49
- for url in urls_in_page:
50
- if 'windows' in url and 'x86_64' in url and url.endswith('.msi'):
51
- if not rc_version and '-rc' in url:
52
- continue
53
- windows_urls.append(url)
54
-
55
- if major_specific:
56
- for url in windows_urls:
57
- if f'-{major_specific}.' in url:
58
- windows_urls = [url]
59
- break
60
-
61
- if not windows_urls:
62
- raise MongoDBNoDownloadLinkForWindowsError(
63
- "Could not find the download link for MongoDB Community Server for Windows x86_64.")
64
-
65
- # Return the latest URL only.
66
- return windows_urls[0]
67
-
68
-
69
- def parse_args():
70
- parser = argparse.ArgumentParser(description='Install MongoDB Community Server.')
71
- # Mutually exclusive group for 'ir' and 'er'
72
- group = parser.add_mutually_exclusive_group()
73
- group.add_argument(
74
- '-er', '--exclude-rc',
75
- action='store_true',
76
- help='Install latest version, but exclude release candidate versions.'
77
- )
78
- group.add_argument(
79
- '-ir', '--include-rc',
80
- action='store_true',
81
- help='Install the latest version of MongoDB including release candidates.'
82
- )
83
-
84
- # Optional arguments
85
- parser.add_argument(
86
- '-c', '--compass',
87
- action='store_true',
88
- help='Install MongoDB Compass.'
89
- )
90
- parser.add_argument(
91
- '-m', '--major',
92
- type=int,
93
- help='Download the latest version of the specified major version.'
94
- )
95
- parser.add_argument(
96
- '-f', '--force',
97
- action='store_true',
98
- help='Force the installation even if MongoDB is already installed.'
99
- )
100
-
101
- args = parser.parse_args()
102
-
103
- # Validation logic: At least one of '-nr', '-ir', or '-c' must be provided
104
- if not (args.no_rc or args.include_rc or args.compass):
105
- parser.error("At least one of '-nr', '-ir', or '-c' must be specified.")
106
-
107
- return args
108
-
109
-
110
- def download_install_process(
111
- rc_version: bool = False,
112
- no_rc_version: bool = True,
113
- major_specific: int = None,
114
- compass: bool = False,
115
- force: bool = False
116
- ) -> int:
117
- """
118
- Download and install the latest version of MongoDB Community Server.
119
-
120
- :param rc_version: bool, if True, the latest RC version will be downloaded.
121
- :param no_rc_version: bool, if True, the latest non-RC version will be downloaded.
122
- :param major_specific: int, if set, the latest version of the specified major version will be downloaded.
123
- :param compass: bool, if True, MongoDB Compass will be installed.
124
- :param force: bool, if True, MongoDB will be installed even if it is already installed.
125
- :return: int, 0 if successful, 1 if failed.
126
- """
127
-
128
- if not permissions.is_admin():
129
- print_api("This function requires administrator privileges.", color='red')
130
- return 1
131
-
132
- if rc_version and no_rc_version:
133
- print_api("Both 'rc_version' and 'no_rc_version' cannot be True at the same time.", color='red')
134
- return 1
135
-
136
- if not (rc_version or no_rc_version) and not compass:
137
- print_api("At least one of 'rc_version', 'no_rc_version', or 'compass' must be True.", color='red')
138
- return 1
139
-
140
- # If we need to install mongo db.
141
- if rc_version or no_rc_version:
142
- if rc_version:
143
- download_rc_version: bool = True
144
- elif no_rc_version:
145
- download_rc_version: bool = False
146
- else:
147
- raise ValueError("Invalid value for 'rc_version' and 'no_rc_version'.")
148
-
149
- if mongo_infra.is_service_running():
150
- print_api("MongoDB service is running - already installed. Use [-f] to reinstall.", color='blue')
151
-
152
- if not force:
153
- return 0
154
- else:
155
- print_api("MongoDB is service is not running.")
156
-
157
- mongo_is_installed: Union[str, None] = mongo_infra.is_installed()
158
- if mongo_infra.is_installed():
159
- message = f"MongoDB is installed in: {mongo_is_installed}\n" \
160
- f"The service is not running. Fix the service or use the 'force' parameter to reinstall."
161
- print_api(message, color='yellow')
162
-
163
- if not force:
164
- return 0
165
-
166
- print_api("Fetching the latest MongoDB download URL...")
167
- mongo_installer_url = get_latest_mongodb_download_url(rc_version=download_rc_version, major_specific=major_specific)
168
-
169
- print_api(f"Downloading MongoDB installer from: {mongo_installer_url}")
170
- installer_file_path: str = web.download(mongo_installer_url)
171
-
172
- print_api("Installing MongoDB...")
173
- try:
174
- msiw.install_msi(
175
- installer_file_path,
176
- silent_no_gui=True,
177
- no_restart=True,
178
- terminate_required_processes=True,
179
- create_log_near_msi=True,
180
- scan_log_for_errors=True,
181
- additional_args='ADDLOCAL="ServerService"'
182
- )
183
- except msiw.MsiInstallationError as e:
184
- print_api(f'{e} Exiting...', color='red')
185
- return 1
186
-
187
- # Check if MongoDB is installed.
188
- message: str = ''
189
- mongo_is_installed = mongo_infra.is_installed()
190
- if not mongo_is_installed:
191
- message += "MongoDB Executable not found.\n"
192
-
193
- if not mongo_infra.is_service_running():
194
- message += "MongoDB service is not running.\n"
195
-
196
- if message:
197
- message += f"MSI Path: {installer_file_path}"
198
- print_api(message, color='red')
199
- return 1
200
- else:
201
- success_message: str = f"MongoDB installed successfully to: {mongo_is_installed}\n" \
202
- f"Service is running."
203
- print_api(success_message, color='green')
204
-
205
- # Clean up the installer file
206
- if os.path.exists(installer_file_path):
207
- os.remove(installer_file_path)
208
- print_api("Cleaned up the installer file.")
209
-
210
- if not compass:
211
- return 0
212
-
213
- # It doesn't matter what you do with the MSI it will not install Compass, only if you run it manually.
214
- # So we will use installation script from their GitHub.
215
- print_api("Downloading MongoDB Compass installation script...")
216
- compass_script_path: str = web.download(COMPASS_INSTALLATION_SCRIPT_URL)
217
-
218
- print_api("Installing MongoDB Compass from script...")
219
- subprocess.run(["powershell", "-ExecutionPolicy", "Bypass", "-File", compass_script_path])
220
-
221
- # Clean up the installer file
222
- if os.path.exists(compass_script_path):
223
- os.remove(compass_script_path)
224
- print_api("Cleaned up the Compass installer file.")
225
-
226
- return 0
227
-
228
-
229
- def download_install_latest_main() -> int:
230
- """
231
- Download and install the latest version of MongoDB Community Server.
232
-
233
- :return: int, 0 if successful, 1 if failed.
234
- """
235
-
236
- args = parse_args()
237
-
238
- return download_install_process(
239
- rc_version=args.include_rc,
240
- no_rc_version=args.exclude_rc,
241
- major_specific=args.major,
242
- compass=args.compass,
243
- force=args.force
244
- )
@@ -1,16 +0,0 @@
1
- from atomicshop.process import execute_with_live_output
2
-
3
-
4
- def execute_pbtk(pbtk_path: str, file_path: str, target_directory: str) -> None:
5
- """
6
- The function receives file path and target filesystem directory to extract the files.
7
-
8
- :param pbtk_path: full path to pbtk file.
9
- :param file_path: full path to binary file.
10
- :param target_directory: The directory on the filesystem to extract files.
11
- """
12
-
13
- cmd: str = f'python "{pbtk_path}" "{file_path}" "{target_directory}"'
14
- print(f'Scanning: {file_path}')
15
-
16
- output_list = execute_with_live_output(cmd=cmd)