atomicshop 3.3.12__py3-none-any.whl → 3.3.13__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.

atomicshop/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  """Atomic Basic functions and classes to make developer life easier"""
2
2
 
3
3
  __author__ = "Den Kras"
4
- __version__ = '3.3.12'
4
+ __version__ = '3.3.13'
@@ -140,9 +140,10 @@ class Certificates:
140
140
  sni_server_certificate_from_server_socket_download_directory: str
141
141
 
142
142
  domains_all_times: list[str]
143
- enable_sslkeylogfile_env_to_client_ssl_context: bool = True
144
- sslkeylog_file_path: str = None
143
+ sslkeylog_file_path: str
144
+
145
145
  sslkeylog_file_name: str = "sslkeylog.txt"
146
+ enable_sslkeylogfile_env_to_client_ssl_context: bool = True
146
147
 
147
148
 
148
149
  @dataclass
@@ -1,17 +1,7 @@
1
- import os
2
- from typing import Union
3
-
4
1
  from pymongo import MongoClient
5
2
  import pymongo.errors
6
3
 
7
- from ... import filesystem
8
-
9
- if os.name == 'nt':
10
- from ... import get_process_list
11
4
 
12
-
13
- WHERE_TO_SEARCH_FOR_MONGODB_EXE: str = 'C:\\Program Files\\MongoDB\\Server\\'
14
- MONGODB_EXE_NAME: str = 'mongod.exe'
15
5
  MONGODB_DEFAULT_URI: str = 'mongodb://localhost:27017/'
16
6
 
17
7
 
@@ -39,31 +29,3 @@ def test_connection(
39
29
  if raise_exception:
40
30
  raise MongoDBNoConnectionError(f"Could not connect to the MongoDB server on: ")
41
31
  return False
42
-
43
-
44
- def is_service_running() -> bool:
45
- """
46
- Check if the MongoDB service is running.
47
- :return: bool, True if the MongoDB service is running, False otherwise.
48
- """
49
-
50
- if os.name == 'nt':
51
- current_processes: dict = (
52
- get_process_list.GetProcessList(get_method='pywin32', connect_on_init=True).get_processes())
53
-
54
- for pid, process_info in current_processes.items():
55
- if MONGODB_EXE_NAME in process_info['name']:
56
- return True
57
- else:
58
- raise NotImplementedError("This function is not implemented for this OS.")
59
-
60
- return False
61
-
62
-
63
- def is_installed() -> Union[str, None]:
64
- """
65
- Check if MongoDB is installed.
66
- :return: string if MongoDB executable is found, None otherwise.
67
- """
68
-
69
- return filesystem.find_file(MONGODB_EXE_NAME, WHERE_TO_SEARCH_FOR_MONGODB_EXE)
@@ -4,10 +4,15 @@ import subprocess
4
4
  import shutil
5
5
  import time
6
6
 
7
+ from rich.console import Console
8
+
7
9
  from ..print_api import print_api
8
10
  from ..permissions import ubuntu_permissions
9
11
 
10
12
 
13
+ console = Console()
14
+
15
+
11
16
  def install_packages(
12
17
  package_list: list[str],
13
18
  timeout_seconds: int = 0,
@@ -216,8 +221,7 @@ def start_enable_service_check_availability(
216
221
  enable_service_bool: bool = True,
217
222
  check_service_running: bool = True,
218
223
  user_mode: bool = False,
219
- sudo: bool = True,
220
- print_kwargs: dict = None
224
+ sudo: bool = True
221
225
  ):
222
226
  """
223
227
  Function starts and enables a service and checks its availability.
@@ -231,7 +235,6 @@ def start_enable_service_check_availability(
231
235
  :param check_service_running: bool, if True, the function will check if the service is running.
232
236
  :param user_mode: bool, if True, the service will be started and enabled in user mode.
233
237
  :param sudo: bool, if True, the command will be executed with sudo.
234
- :param print_kwargs: dict, the print arguments.
235
238
  :return:
236
239
  """
237
240
 
@@ -245,18 +248,18 @@ def start_enable_service_check_availability(
245
248
  enable_service(service_name, user_mode=user_mode,sudo=sudo)
246
249
 
247
250
  if check_service_running:
248
- print_api(
249
- f"Waiting {str(wait_time_seconds)} seconds for the program to start before availability check...",
250
- **(print_kwargs or {}))
251
- time.sleep(wait_time_seconds)
251
+ print(f"Waiting up to {str(wait_time_seconds)} seconds for the program to start.")
252
+ count: int = 0
253
+ while not is_service_running(service_name, user_mode=user_mode) and count < wait_time_seconds:
254
+ count += 1
255
+ time.sleep(1)
252
256
 
253
257
  if not is_service_running(service_name, user_mode=user_mode):
254
- print_api(
255
- f"[{service_name}] service failed to start.", color='red', error_type=True, **(print_kwargs or {}))
258
+ console.print(f"[{service_name}] service failed to start.", style='red', markup=False)
256
259
  if exit_on_error:
257
260
  sys.exit(1)
258
261
  else:
259
- print_api(f"[{service_name}] service is running.", color='green', **(print_kwargs or {}))
262
+ console.print(f"[{service_name}] service is running.", style='green', markup=False)
260
263
 
261
264
 
262
265
  def add_path_to_bashrc(as_regular_user: bool = False):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atomicshop
3
- Version: 3.3.12
3
+ Version: 3.3.13
4
4
  Summary: Atomic functions and classes to make developer life easier
5
5
  Author: Denis Kras
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- atomicshop/__init__.py,sha256=TBMr-8fSW7-pm2urzQlk8alPCT-9WMhHJRs5SESDf_M,123
1
+ atomicshop/__init__.py,sha256=MGjnRWFGJfLj9k_F5wy-o3STJj-zwtz-OfK8-ZufwXQ,123
2
2
  atomicshop/_basics_temp.py,sha256=6cu2dd6r2dLrd1BRNcVDKTHlsHs_26Gpw8QS6v32lQ0,3699
3
3
  atomicshop/_create_pdf_demo.py,sha256=Yi-PGZuMg0RKvQmLqVeLIZYadqEZwUm-4A9JxBl_vYA,3713
4
4
  atomicshop/_patch_import.py,sha256=ENp55sKVJ0e6-4lBvZnpz9PQCt3Otbur7F6aXDlyje4,6334
@@ -53,9 +53,6 @@ atomicshop/websocket_parse.py,sha256=aLHWyKqaYqEn_MRBWm2L6rIl6QPmqbVrjEXE_rBzwCw
53
53
  atomicshop/a_installs/ubuntu/docker_rootless.py,sha256=9IPNtGZYjfy1_n6ZRt7gWz9KZgR6XCgevjqq02xk-o0,281
54
54
  atomicshop/a_installs/ubuntu/docker_sudo.py,sha256=JzayxeyKDtiuT4Icp2L2LyFRbx4wvpyN_bHLfZ-yX5E,281
55
55
  atomicshop/a_installs/ubuntu/elastic_search_and_kibana.py,sha256=yRB-l1zBxdiN6av-FwNkhcBlaeu4zrDPjQ0uPGgpK2I,244
56
- atomicshop/a_installs/ubuntu/mongodb.py,sha256=xuRJS1qqOZ0EZp7of5R3tTjSu6CwBIxYg8-NaM7othE,230
57
- atomicshop/a_installs/win/fibratus.py,sha256=TU4e9gdZ_zI73C40uueJ59pD3qmN-UFGdX5GFoVf6cM,179
58
- atomicshop/a_installs/win/mongodb.py,sha256=AqyItXu19aaoe49pppDxtEkXey6PMy0PoT2Y_RmPpPE,179
59
56
  atomicshop/a_installs/win/wsl_ubuntu_lts.py,sha256=dZbPRLNKFeMd6MotjkE6UDY9cOiIaaclIdR1kGYWI50,139
60
57
  atomicshop/a_mains/dns_gateway_setting.py,sha256=ncc2rFQCChxlNP59UshwmTonLqC6MWblrVAzbbz-13M,149
61
58
  atomicshop/a_mains/github_wrapper.py,sha256=F-PoZknVCxWPN0PTO6l7ZNiaYvo7OVFKFI_zlPt56ps,169
@@ -129,7 +126,7 @@ atomicshop/file_io/tomls.py,sha256=vZ_Wng5alLf8z6HSEZj7PS0XKDA-Iies9ihVWOkTcKo,1
129
126
  atomicshop/file_io/xlsxs.py,sha256=v_dyg9GD4LqgWi6wA1QuWRZ8zG4ZwB6Dz52ytdcmmmI,2184
130
127
  atomicshop/file_io/xmls.py,sha256=zh3SuK-dNaFq2NDNhx6ivcf4GYCfGM8M10PcEwDSpxk,2104
131
128
  atomicshop/mitm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
132
- atomicshop/mitm/config_static.py,sha256=4_lsZVVHCKMK8KZJeY3sXOiIJGRTUwoyckVo4EVa1FY,8931
129
+ atomicshop/mitm/config_static.py,sha256=KzO8DjZjRHfkQMYSIGTkW4jLNPzMR8visTqs1H6ZQ-U,8926
133
130
  atomicshop/mitm/config_toml_editor.py,sha256=2p1CMcktWRR_NW-SmyDwylu63ad5e0-w1QPMa8ZLDBw,1635
134
131
  atomicshop/mitm/connection_thread_worker.py,sha256=p-93_zdq3HzWpR7NF-gIq0JvvX0L8jz3_TSD3tBhV4o,33255
135
132
  atomicshop/mitm/import_config.py,sha256=6fPiV_3v2ym1LgiLlbGoiIPaB6pfRNM9UBXmRnP-pMQ,18560
@@ -200,7 +197,7 @@ atomicshop/wrappers/pipw.py,sha256=mu4jnHkSaYNfpBiLZKMZxEX_E2LqW5BVthMZkblPB_c,1
200
197
  atomicshop/wrappers/process_wrapper_pbtk.py,sha256=ycPmBRnv627RWks6N8OhxJQe8Gu3h3Vwj-4HswPOw0k,599
201
198
  atomicshop/wrappers/pyopensslw.py,sha256=pklvXEbi0fHu5n1eRKKHEDLN_nsIqCTXv5Lv0bzReTo,7071
202
199
  atomicshop/wrappers/sysmonw.py,sha256=CdawuWuy_uUi3ALCm6lKP7pSyKeTk1MXyzOaTMbBSO8,5346
203
- atomicshop/wrappers/ubuntu_terminal.py,sha256=vGEBznz_EKzjhsFAXzefep3SwdP2toYPxWkagOjME3I,12328
200
+ atomicshop/wrappers/ubuntu_terminal.py,sha256=hHXsr_jEHU4frCwgo1XWS5Gb5nmg-Q06tiem4N8RYeE,12316
204
201
  atomicshop/wrappers/wslw.py,sha256=2Z7X0j5M2hoRZjbHfm_vqwNXZeptsdkNCdhdcM_S9vo,6998
205
202
  atomicshop/wrappers/certauthw/certauth.py,sha256=qLo593_MLU8VfbhYoNQ3J5BvtZuE71aFQROysEt6_dk,12225
206
203
  atomicshop/wrappers/certauthw/certauthw.py,sha256=4WvhjANI7Kzqrr_nKmtA8Kf7B6rute_5wfP65gwQrjw,8082
@@ -257,8 +254,6 @@ atomicshop/wrappers/factw/rest/firmware.py,sha256=FezneouU1lUO9uZ6_8ZQNxr4MDlFIo
257
254
  atomicshop/wrappers/factw/rest/router.py,sha256=fdGok5ESBxcZHIBgM93l4yTPRGoeooQNsrPWIETieGk,710
258
255
  atomicshop/wrappers/factw/rest/statistics.py,sha256=vznwzKP1gEF7uXz3HsuV66BU9wrp73N_eFqpFpye9Qw,653
259
256
  atomicshop/wrappers/factw/rest/status.py,sha256=4O3xS1poafwyUiLDkhyx4oMMe4PBwABuRPpOMnMKgIU,641
260
- atomicshop/wrappers/fibratusw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
261
- atomicshop/wrappers/fibratusw/install.py,sha256=GnaAAqcXRhovxZ3x5uB9RAXTMCh5xd5k1niCKTzh4Z0,3242
262
257
  atomicshop/wrappers/loggingw/consts.py,sha256=JWiUJEydjhwatBxtIJsGTmDUSTLbmIRidtR6qRLMaIY,1608
263
258
  atomicshop/wrappers/loggingw/filters.py,sha256=48UVhJHemCS0agXmQP8dHvAHM8r9DFphJ1TNEBP3Dlg,3545
264
259
  atomicshop/wrappers/loggingw/formatters.py,sha256=ZY12IokVY1G_Wzn2Zlv9qjK-e8CtIK6yUgUfPHvH2BU,5802
@@ -267,9 +262,7 @@ atomicshop/wrappers/loggingw/loggers.py,sha256=mmM__XR3W4QC82wbsDRG_M4_0JYGGEP0Q
267
262
  atomicshop/wrappers/loggingw/loggingw.py,sha256=Cp_9IsiloPYpp9uzEQtUX-jCfcgGe4B2nFBle8x4wqQ,43582
268
263
  atomicshop/wrappers/loggingw/reading.py,sha256=sCNlgqLNH5XdKqOOjjEox7CvViMHzs6h7-hwCnx4NKk,17566
269
264
  atomicshop/wrappers/mongodbw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
270
- atomicshop/wrappers/mongodbw/install_mongodb_ubuntu.py,sha256=2eEOb35T259lhn5koynfTIm1hanxD02zN97ExGSBM2o,4021
271
- atomicshop/wrappers/mongodbw/install_mongodb_win.py,sha256=64EUQYx7VuMC3ndO2x3nSErh5NZ_BsqMwGvPcybfC-Q,8499
272
- atomicshop/wrappers/mongodbw/mongo_infra.py,sha256=IjEF0jPzQz866MpTm7rnksnyyWQeUT_B2h2DA9ryAio,2034
265
+ atomicshop/wrappers/mongodbw/mongo_infra.py,sha256=vEXKy1Mi6LZ7QNEtRb8d-5xT5PYFhXbeEfFsXfsgpYo,918
273
266
  atomicshop/wrappers/mongodbw/mongodbw.py,sha256=CHbDfW9CXzXUs3V97DYQpt-dYlt_gB60JhwqG2tVFQY,56049
274
267
  atomicshop/wrappers/playwrightw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
275
268
  atomicshop/wrappers/playwrightw/_tryouts.py,sha256=l1BLkFsiIMNlgv7nfZd1XGEvXQkIQkIcg48__9OaC00,4920
@@ -325,9 +318,9 @@ atomicshop/wrappers/socketw/statistics_csv.py,sha256=_gA8bMX6Sw_UCXKi2y9wNAwlqif
325
318
  atomicshop/wrappers/winregw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
326
319
  atomicshop/wrappers/winregw/winreg_installed_software.py,sha256=Qzmyktvob1qp6Tjk2DjLfAqr_yXV0sgWzdMW_9kwNjY,2345
327
320
  atomicshop/wrappers/winregw/winreg_network.py,sha256=ih0BVNwByLvf9F_Lac4EdmDYYJA3PzMvmG0PieDZrsE,9905
328
- atomicshop-3.3.12.dist-info/licenses/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
329
- atomicshop-3.3.12.dist-info/METADATA,sha256=UT8jiyOESmyvNu499k17z5YofzY-uq_a_XLS2E6kknw,9312
330
- atomicshop-3.3.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
331
- atomicshop-3.3.12.dist-info/entry_points.txt,sha256=SJEgEP0KoFtfxuGwe5tOzKfXkjR9Dv6YYug33KNYxyY,69
332
- atomicshop-3.3.12.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
333
- atomicshop-3.3.12.dist-info/RECORD,,
321
+ atomicshop-3.3.13.dist-info/licenses/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
322
+ atomicshop-3.3.13.dist-info/METADATA,sha256=OXcv3FuM8llsBWRC4ms6FaYLM_g3gUXQPvpCuMPoS3U,9312
323
+ atomicshop-3.3.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
324
+ atomicshop-3.3.13.dist-info/entry_points.txt,sha256=SJEgEP0KoFtfxuGwe5tOzKfXkjR9Dv6YYug33KNYxyY,69
325
+ atomicshop-3.3.13.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
326
+ atomicshop-3.3.13.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- #! /usr/bin/env python3
2
- import sys
3
-
4
- from atomicshop.wrappers.mongodbw import install_mongodb_ubuntu
5
-
6
-
7
- def main():
8
- install_mongodb_ubuntu.install_main(compass=True)
9
-
10
-
11
- if __name__ == "__main__":
12
- sys.exit(main())
@@ -1,9 +0,0 @@
1
- from atomicshop.wrappers.fibratusw import install
2
-
3
-
4
- def main():
5
- install.install_fibratus(remove_file_after_installation=True)
6
-
7
-
8
- if __name__ == '__main__':
9
- main()
@@ -1,9 +0,0 @@
1
- from atomicshop.wrappers.mongodbw import install_mongodb_win
2
-
3
-
4
- def main():
5
- install_mongodb_win.download_install_latest_main()
6
-
7
-
8
- if __name__ == "__main__":
9
- main()
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
- )