atomicshop 2.15.1__py3-none-any.whl → 2.15.2__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__ = '2.15.1'
4
+ __version__ = '2.15.2'
@@ -0,0 +1,53 @@
1
+ from typing import Union
2
+
3
+ from pymongo import MongoClient
4
+ import pymongo.errors
5
+
6
+ from ... import get_process_list, filesystem
7
+
8
+
9
+ WHERE_TO_SEARCH_FOR_MONGODB_EXE: str = 'C:\\Program Files\\MongoDB\\Server\\'
10
+ MONGODB_EXE_NAME: str = 'mongod.exe'
11
+ MONGODB_DEFAULT_URI: str = 'mongodb://localhost:27017/'
12
+
13
+
14
+ class MongoDBNoConnectionError(Exception):
15
+ pass
16
+
17
+
18
+ def test_connection(
19
+ uri: str = MONGODB_DEFAULT_URI,
20
+ raise_exception: bool = False
21
+ ) -> bool:
22
+ try:
23
+ client = MongoClient(uri)
24
+ client.admin.command('ping')
25
+ return True
26
+ except pymongo.errors.ServerSelectionTimeoutError:
27
+ if raise_exception:
28
+ raise MongoDBNoConnectionError(f"Could not connect to the MongoDB server on: ")
29
+ return False
30
+
31
+
32
+ def is_service_running() -> bool:
33
+ """
34
+ Check if the MongoDB service is running.
35
+ :return: bool, True if the MongoDB service is running, False otherwise.
36
+ """
37
+ current_processes: dict = (
38
+ get_process_list.GetProcessList(get_method='pywin32', connect_on_init=True).get_processes())
39
+
40
+ for pid, process_info in current_processes.items():
41
+ if MONGODB_EXE_NAME in process_info['name']:
42
+ return True
43
+
44
+ return False
45
+
46
+
47
+ def is_installed() -> Union[str, None]:
48
+ """
49
+ Check if MongoDB is installed.
50
+ :return: string if MongoDB executable is found, None otherwise.
51
+ """
52
+
53
+ return filesystem.find_file(MONGODB_EXE_NAME, WHERE_TO_SEARCH_FOR_MONGODB_EXE)
@@ -1,15 +1,18 @@
1
1
  import os
2
2
  import requests
3
3
  from typing import Union
4
+ import argparse
5
+ import subprocess
4
6
 
5
- from ... import urls, web, permissions, get_process_list, filesystem
7
+ from ... import urls, web, permissions
6
8
  from ...print_api import print_api
7
9
  from .. import msiw
10
+ from . import infrastructure
8
11
 
9
12
 
10
13
  MONGODB_DOWNLOAD_PAGE_URL: str = 'https://www.mongodb.com/try/download/community'
11
- WHERE_TO_SEARCH_FOR_MONGODB_EXE: str = 'C:\\Program Files\\MongoDB\\Server\\'
12
- MONGODB_EXE_NAME: str = 'mongod.exe'
14
+ COMPASS_INSTALLATION_SCRIPT_URL: str = \
15
+ 'https://raw.githubusercontent.com/mongodb/mongo/master/src/mongo/installer/compass/Install-Compass.ps1'
13
16
 
14
17
 
15
18
  class MongoDBWebPageNoSuccessCodeError(Exception):
@@ -62,48 +65,52 @@ def get_latest_mongodb_download_url(
62
65
  return windows_urls[0]
63
66
 
64
67
 
65
- def is_service_running() -> bool:
66
- """
67
- Check if the MongoDB service is running.
68
- :return: bool, True if the MongoDB service is running, False otherwise.
69
- """
70
- current_processes: dict = (
71
- get_process_list.GetProcessList(get_method='pywin32', connect_on_init=True).get_processes())
72
-
73
- for pid, process_info in current_processes.items():
74
- if MONGODB_EXE_NAME in process_info['name']:
75
- return True
76
-
77
- return False
78
-
79
-
80
- def is_installed() -> Union[str, None]:
81
- """
82
- Check if MongoDB is installed.
83
- :return: string if MongoDB executable is found, None otherwise.
84
- """
68
+ def parse_args():
69
+ parser = argparse.ArgumentParser(description='Install MongoDB Community Server.')
70
+ parser.add_argument(
71
+ '-nr', '--no-rc', action='store_true', help='Do not download release candidate versions.')
72
+ parser.add_argument(
73
+ '-m', '--major', type=int, help='Download the latest version of the specified major version.')
74
+ parser.add_argument(
75
+ '-c', '--compass', action='store_true', help='Install MongoDB Compass.')
76
+ parser.add_argument(
77
+ '-f', '--force', action='store_true', help='Force the installation even if MongoDB is already installed.')
85
78
 
86
- return filesystem.find_file(MONGODB_EXE_NAME, WHERE_TO_SEARCH_FOR_MONGODB_EXE)
79
+ return parser.parse_args()
87
80
 
88
81
 
89
82
  def download_install_latest_main(
90
- no_rc_version: bool = True,
83
+ no_rc_version: bool = False,
91
84
  major_specific: int = None,
85
+ compass: bool = False,
92
86
  force: bool = False
93
87
  ):
94
88
  """
95
89
  Download and install the latest version of MongoDB Community Server.
96
90
  :param no_rc_version: bool, if True, the latest non-RC version will be downloaded.
97
91
  :param major_specific: int, if set, the latest version of the specified major version will be downloaded.
92
+ :param compass: bool, if True, MongoDB Compass will be installed.
98
93
  :param force: bool, if True, MongoDB will be installed even if it is already installed.
99
94
  :return:
100
95
  """
101
96
 
97
+ args = parse_args()
98
+
99
+ # Set the args only if they were used.
100
+ if args.no_rc:
101
+ no_rc_version = args.no_rc
102
+ if args.major:
103
+ major_specific = args.major
104
+ if args.compass:
105
+ compass = args.compass
106
+ if args.force:
107
+ force = args.force
108
+
102
109
  if not permissions.is_admin():
103
110
  print_api("This function requires administrator privileges.", color='red')
104
111
  return 1
105
112
 
106
- if is_service_running():
113
+ if infrastructure.is_service_running():
107
114
  print_api("MongoDB service is running - already installed.", color='blue')
108
115
 
109
116
  if not force:
@@ -111,8 +118,8 @@ def download_install_latest_main(
111
118
  else:
112
119
  print_api("MongoDB is service is not running.")
113
120
 
114
- mongo_is_installed: Union[str, None] = is_installed()
115
- if is_installed():
121
+ mongo_is_installed: Union[str, None] = infrastructure.is_installed()
122
+ if infrastructure.is_installed():
116
123
  message = f"MongoDB is installed in: {mongo_is_installed}\n" \
117
124
  f"The service is not running. Fix the service or use the 'force' parameter to reinstall."
118
125
  print_api(message, color='yellow')
@@ -143,11 +150,11 @@ def download_install_latest_main(
143
150
 
144
151
  # Check if MongoDB is installed.
145
152
  message: str = ''
146
- mongo_is_installed = is_installed()
153
+ mongo_is_installed = infrastructure.is_installed()
147
154
  if not mongo_is_installed:
148
155
  message += "MongoDB Executable not found.\n"
149
156
 
150
- if not is_service_running():
157
+ if not infrastructure.is_service_running():
151
158
  message += "MongoDB service is not running.\n"
152
159
 
153
160
  if message:
@@ -164,4 +171,20 @@ def download_install_latest_main(
164
171
  os.remove(installer_file_path)
165
172
  print_api("Cleaned up the installer file.")
166
173
 
174
+ if not compass:
175
+ return 0
176
+
177
+ # It doesn't matter what you do with the MSI it will not install Compass, only if you run it manually.
178
+ # So we will use installation script from their GitHub.
179
+ print_api("Downloading MongoDB Compass installation script...")
180
+ compass_script_path: str = web.download(COMPASS_INSTALLATION_SCRIPT_URL)
181
+
182
+ print_api("Installing MongoDB Compass from script...")
183
+ subprocess.run(["powershell", "-ExecutionPolicy", "Bypass", "-File", compass_script_path])
184
+
185
+ # Clean up the installer file
186
+ if os.path.exists(compass_script_path):
187
+ os.remove(compass_script_path)
188
+ print_api("Cleaned up the Compass installer file.")
189
+
167
190
  return 0
@@ -0,0 +1,144 @@
1
+ import pymongo
2
+
3
+ from . import infrastructure
4
+
5
+
6
+ """
7
+ DISCLAIMER: you should use the pymongo library directly instead of using the atomicshop/wrappers/mongodbw/mongodbw.py.
8
+ These are good examples to get you started, but can't really cover all the use cases you might have.
9
+ """
10
+
11
+
12
+ def connect(uri: str = infrastructure.MONGODB_DEFAULT_URI):
13
+ """
14
+ Connect to a MongoDB database.
15
+ :param uri: str, the URI of the MongoDB database.
16
+ :return: pymongo.MongoClient, the client object.
17
+ """
18
+ return pymongo.MongoClient(uri)
19
+
20
+
21
+ def add_list_of_dicts_to_mongo(
22
+ list_of_dicts: list,
23
+ database_name: str,
24
+ collection_name: str,
25
+ mongo_client: pymongo.MongoClient = None,
26
+ close_client: bool = False
27
+ ):
28
+ """
29
+ Add a list of dictionaries to a MongoDB collection.
30
+ :param list_of_dicts: list of dictionaries, the list of dictionaries to add to the collection.
31
+ :param database_name: str, the name of the database.
32
+ :param collection_name: str, the name of the collection.
33
+ :param mongo_client: pymongo.MongoClient, the connection object.
34
+ If None, a new connection will be created to default URI.
35
+ :param close_client: bool, if True, the connection will be closed after the operation.
36
+
37
+ :return: None
38
+ """
39
+
40
+ if not mongo_client:
41
+ mongo_client = connect()
42
+
43
+ db = mongo_client[database_name]
44
+ collection = db[collection_name]
45
+
46
+ collection.insert_many(list_of_dicts)
47
+
48
+ if close_client:
49
+ mongo_client.close()
50
+
51
+
52
+ def remove_list_of_dicts(
53
+ list_of_dicts: list,
54
+ database_name: str,
55
+ collection_name: str,
56
+ mongo_client: pymongo.MongoClient = None,
57
+ close_client: bool = False
58
+ ):
59
+ """
60
+ Remove a list of dictionaries from a MongoDB collection.
61
+ :param list_of_dicts: list of dictionaries, the list of dictionaries to remove from the collection.
62
+ :param database_name: str, the name of the database.
63
+ :param collection_name: str, the name of the collection.
64
+ :param mongo_client: pymongo.MongoClient, the connection object.
65
+ If None, a new connection will be created to default URI.
66
+ :param close_client: bool, if True, the connection will be closed after the operation.
67
+
68
+ :return: None
69
+ """
70
+
71
+ if not mongo_client:
72
+ mongo_client = connect()
73
+
74
+ db = mongo_client[database_name]
75
+ collection = db[collection_name]
76
+
77
+ for doc in list_of_dicts:
78
+ collection.delete_one(doc)
79
+
80
+ if close_client:
81
+ mongo_client.close()
82
+
83
+
84
+ def overwrite_list_of_dicts(
85
+ list_of_dicts: list,
86
+ database_name: str,
87
+ collection_name: str,
88
+ mongo_client: pymongo.MongoClient = None,
89
+ close_client: bool = False
90
+ ):
91
+ """
92
+ Overwrite a list of dictionaries in a MongoDB collection.
93
+ :param list_of_dicts: list of dictionaries, the list of dictionaries to overwrite in the collection.
94
+ :param database_name: str, the name of the database.
95
+ :param collection_name: str, the name of the collection.
96
+ :param mongo_client: pymongo.MongoClient, the connection object.
97
+ If None, a new connection will be created to default URI.
98
+ :param close_client: bool, if True, the connection will be closed after the operation.
99
+
100
+ :return: None
101
+ """
102
+
103
+ if not mongo_client:
104
+ mongo_client = connect()
105
+
106
+ db = mongo_client[database_name]
107
+ collection = db[collection_name]
108
+
109
+ collection.delete_many({})
110
+ collection.insert_many(list_of_dicts)
111
+
112
+ if close_client:
113
+ mongo_client.close()
114
+
115
+
116
+ def get_all_entries_from_collection(
117
+ database_name: str,
118
+ collection_name: str,
119
+ mongo_client: pymongo.MongoClient = None,
120
+ close_client: bool = False
121
+ ):
122
+ """
123
+ Get all entries from a MongoDB collection.
124
+ :param database_name: str, the name of the database.
125
+ :param collection_name: str, the name of the collection.
126
+ :param mongo_client: pymongo.MongoClient, the connection object.
127
+ If None, a new connection will be created to default URI.
128
+ :param close_client: bool, if True, the connection will be closed after the operation.
129
+
130
+ :return: list of dictionaries, the list of entries from the collection.
131
+ """
132
+
133
+ if not mongo_client:
134
+ mongo_client = connect()
135
+
136
+ db = mongo_client[database_name]
137
+ collection = db[collection_name]
138
+
139
+ entries = list(collection.find())
140
+
141
+ if close_client:
142
+ mongo_client.close()
143
+
144
+ return entries
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atomicshop
3
- Version: 2.15.1
3
+ Version: 2.15.2
4
4
  Summary: Atomic functions and classes to make developer life easier
5
5
  Author: Denis Kras
6
6
  License: MIT License
@@ -1,4 +1,4 @@
1
- atomicshop/__init__.py,sha256=d6t5Ql0zc3dSUJNAyTjHj6blBObI-unNn2kZw5eOlhs,123
1
+ atomicshop/__init__.py,sha256=YjtioQo2yCdlVopAxK5ML-3qjCBp2BtnyqJLsu5hSYI,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
@@ -246,7 +246,9 @@ atomicshop/wrappers/loggingw/loggers.py,sha256=DHOOTAtqkwn1xgvLHSkOiBm6yFGNuQy1k
246
246
  atomicshop/wrappers/loggingw/loggingw.py,sha256=lo4OZPXCbYZi3GqpaaJSs9SOGFfqD2EgHzzTK7f5IR4,11275
247
247
  atomicshop/wrappers/loggingw/reading.py,sha256=b4-ibM5WwjEOanvHY3hIsu9-4b2RAdPYiCxvl7745fk,17521
248
248
  atomicshop/wrappers/mongodbw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
249
- atomicshop/wrappers/mongodbw/install_mongodb.py,sha256=cuisakPkuIsMfleyARyuOTgbcXWvfSWKqoYaMdOnPuw,5456
249
+ atomicshop/wrappers/mongodbw/infrastructure.py,sha256=tHqtt__yKGtj24CT5AIk0V0k9t1p_PjezFExXRmmmcA,1517
250
+ atomicshop/wrappers/mongodbw/install_mongodb.py,sha256=dik6tpXws4FaQN_-u8s-yn5Z1InHROV7k1WhFA8eu4M,6617
251
+ atomicshop/wrappers/mongodbw/mongodbw.py,sha256=eDwI3sePLGWhl-neBRQM955KZOl8jaO7U0n_AzXM3es,4568
250
252
  atomicshop/wrappers/nodejsw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
251
253
  atomicshop/wrappers/nodejsw/install_nodejs.py,sha256=QZg-R2iTQt7kFb8wNtnTmwraSGwvUs34JIasdbNa7ZU,5154
252
254
  atomicshop/wrappers/playwrightw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -292,8 +294,8 @@ atomicshop/wrappers/socketw/socket_server_tester.py,sha256=AhpurHJmP2kgzHaUbq5ey
292
294
  atomicshop/wrappers/socketw/socket_wrapper.py,sha256=aXBwlEIJhFT0-c4i8iNlFx2It9VpCEpsv--5Oqcpxao,11624
293
295
  atomicshop/wrappers/socketw/ssl_base.py,sha256=k4V3gwkbq10MvOH4btU4onLX2GNOsSfUAdcHmL1rpVE,2274
294
296
  atomicshop/wrappers/socketw/statistics_csv.py,sha256=t3dtDEfN47CfYVi0CW6Kc2QHTEeZVyYhc57IYYh5nmA,826
295
- atomicshop-2.15.1.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
296
- atomicshop-2.15.1.dist-info/METADATA,sha256=uIXlm-6-iPV6AdPBYI4b8Y9LnSZmj2qU6yKOWK1V13E,10502
297
- atomicshop-2.15.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
298
- atomicshop-2.15.1.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
299
- atomicshop-2.15.1.dist-info/RECORD,,
297
+ atomicshop-2.15.2.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
298
+ atomicshop-2.15.2.dist-info/METADATA,sha256=mAbT1nfgZ4Tj46GcfHsaEw8vnvZnt3ygZxipKe9aUco,10502
299
+ atomicshop-2.15.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
300
+ atomicshop-2.15.2.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
301
+ atomicshop-2.15.2.dist-info/RECORD,,