atomicshop 2.5.5__py3-none-any.whl → 2.5.6__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.5.5'
4
+ __version__ = '2.5.6'
@@ -0,0 +1,14 @@
1
+ import sys
2
+ from atomicshop.wrappers import wslw
3
+
4
+
5
+ def main():
6
+ if len(sys.argv) < 2:
7
+ print("Usage: python main.py <directory_path_to_save_Ubuntu_package>")
8
+ sys.exit(1)
9
+
10
+ wslw.install_wsl(directory_path=sys.argv[1])
11
+
12
+
13
+ if __name__ == '__main__':
14
+ main()
atomicshop/filesystem.py CHANGED
@@ -3,6 +3,7 @@ import pathlib
3
3
  from pathlib import Path, PurePath, PureWindowsPath, PurePosixPath
4
4
  import glob
5
5
  import shutil
6
+ from contextlib import contextmanager
6
7
 
7
8
  from .print_api import print_api, print_status_of_list
8
9
  from .basics import strings, list_of_dicts
@@ -11,6 +12,51 @@ from . import hashing
11
12
 
12
13
 
13
14
  WINDOWS_DIRECTORY_SPECIAL_CHARACTERS = ['<', '>', ':', '"', '/', '\\', '|', '?', '*']
15
+ FILE_NAME_REPLACEMENT_DICT: dict = {
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
+ }
14
60
 
15
61
 
16
62
  def get_working_directory() -> str:
@@ -217,6 +263,52 @@ def create_directory(directory_fullpath: str):
217
263
  pathlib.Path(directory_fullpath).mkdir(parents=True, exist_ok=True)
218
264
 
219
265
 
266
+ def rename_file(source_file_path: str, target_file_path: str) -> None:
267
+ """
268
+ The function renames file from source to target.
269
+
270
+ :param source_file_path: string, full path to source file.
271
+ :param target_file_path: string, full path to target file.
272
+
273
+ :return: None
274
+ """
275
+
276
+ # Rename file.
277
+ os.rename(source_file_path, target_file_path)
278
+
279
+
280
+ @contextmanager
281
+ def temporary_rename(file_path: str, temp_file_path) -> None:
282
+ """
283
+ The function will rename the file to temporary name and then rename it back to original name.
284
+
285
+ :param file_path: string, full path to file.
286
+ :param temp_file_path: string, temporary name to rename the file to.
287
+ :return: None.
288
+
289
+ Usage:
290
+ original_file = 'example.txt'
291
+ temporary_file = 'temp_example.txt'
292
+
293
+ with temporary_rename(original_file, temporary_file):
294
+ # Inside this block, the file exists as 'temp_example.txt'
295
+ print(f"File is temporarily renamed to {temporary_file}")
296
+ # Perform operations with the temporarily named file here
297
+
298
+ # Outside the block, it's back to 'example.txt'
299
+ print(f"File is renamed back to {original_file}")
300
+ """
301
+
302
+ original_name = file_path
303
+ try:
304
+ # Rename the file to the temporary name
305
+ os.rename(original_name, temp_file_path)
306
+ yield
307
+ finally:
308
+ # Rename the file back to its original name
309
+ os.rename(temp_file_path, original_name)
310
+
311
+
220
312
  def move_file(source_file_path: str, target_file_path: str, no_overwrite: bool = False) -> None:
221
313
  """
222
314
  The function moves file from source to target.
atomicshop/process.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import sys
2
3
  import functools
3
4
  from typing import Union
4
5
  import shlex
@@ -238,6 +239,16 @@ def match_pattern_against_running_processes_cmdlines(pattern: str, first: bool =
238
239
  return matched_cmdlines
239
240
 
240
241
 
242
+ def run_powershell_command(command):
243
+ try:
244
+ result = subprocess.run(["powershell", "-Command", command], capture_output=True, text=True, check=True)
245
+ print_api(result.stdout)
246
+ return result.stdout
247
+ except subprocess.CalledProcessError as e:
248
+ print_api(f"An error occurred: {e}", color='red', error_type=True)
249
+ return e
250
+
251
+
241
252
  """
242
253
  subprocess.Popen and subprocess.run are both functions in Python's subprocess module used for executing shell commands,
243
254
  but they serve different purposes and offer different levels of control over command execution.
@@ -70,11 +70,12 @@ def install_docker_ubuntu():
70
70
  # Verify the installation.
71
71
  result: list = process.execute_with_live_output('sudo docker run hello-world')
72
72
 
73
+ print_api('\n'.join(result))
74
+
73
75
  if 'Hello from Docker!' in '\n'.join(result):
74
76
  print_api('Docker installed successfully.', color='green')
75
77
  return True
76
78
  else:
77
79
  print_api('Docker installation failed.', color='red')
78
- print_api(result, color='red')
79
80
  print_api('Please check the logs above for more information.', color='red')
80
81
  return False
@@ -0,0 +1,112 @@
1
+ import os
2
+ import sys
3
+ from pathlib import Path
4
+
5
+ from ..import process, permissions
6
+ from ..print_api import print_api
7
+
8
+
9
+ def is_installed():
10
+ # Command to check the status of the WSL feature
11
+ command = "Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux"
12
+
13
+ # Check if WSL is enabled
14
+ if "Enabled" in process.run_powershell_command(command):
15
+ return True
16
+ else:
17
+ return False
18
+
19
+
20
+ def is_ubuntu_installed() -> bool:
21
+ """
22
+ Check if Ubuntu is installed on WSL.
23
+ :return: bool, True if Ubuntu is installed, False otherwise.
24
+ """
25
+
26
+ # Command to list installed WSL distributions
27
+ command = "wsl --list --quiet"
28
+
29
+ is_ubuntu_exists: bool = False
30
+ # Check each distribution for being Ubuntu 22.04
31
+ for distro in process.run_powershell_command(command).splitlines():
32
+ if "ubuntu" in distro.lower():
33
+ is_ubuntu_exists = True
34
+ break
35
+
36
+ return is_ubuntu_exists
37
+
38
+
39
+ def is_ubuntu_version_installed(version: str = "22.04") -> bool:
40
+ """
41
+ Check if specific version of Ubuntu is installed on WSL.
42
+ :param version: string, Ubuntu version to check for. Default is 22.04.
43
+ :return: bool, True if Ubuntu is installed, False otherwise.
44
+ """
45
+
46
+ # Command to get Ubuntu version
47
+ command = f"wsl -d Ubuntu lsb_release -a"
48
+
49
+ # Execute the command
50
+ result = process.run_powershell_command(command)
51
+
52
+ is_version_installed: bool = False
53
+ # Parse the output for the version number
54
+ for line in result.splitlines():
55
+ if "Release" in line and version in line:
56
+ is_version_installed = True
57
+ break
58
+
59
+ return is_version_installed
60
+
61
+
62
+ def install_wsl(directory_path: str, enable_virtual_machine_platform: bool = False):
63
+ """
64
+ Install WSL on Windows 10.
65
+ :param directory_path: string, directory path to save Ubuntu package.
66
+ :param enable_virtual_machine_platform: bool, True to enable Virtual Machine Platform feature.
67
+ """
68
+
69
+ # Check for admin privileges
70
+ if not permissions.is_admin():
71
+ sys.exit("Script must be run as administrator")
72
+
73
+ # Check if WSL is already installed
74
+ if is_installed():
75
+ print_api("WSL is already installed", color='green')
76
+ else:
77
+ # Enable WSL
78
+ print_api("Enabling Windows Subsystem for Linux...")
79
+ process.run_powershell_command(
80
+ "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux")
81
+
82
+ # Check if the system needs a reboot
83
+ if "You must restart your computer" in process.run_powershell_command(
84
+ "Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux"):
85
+ print_api("Please restart your computer to complete the installation of WSL and rerun the script.")
86
+ sys.exit(0)
87
+
88
+ if enable_virtual_machine_platform:
89
+ # Check if Hyper-V is enabled
90
+ if "Enabled" in process.run_powershell_command(
91
+ "Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V"):
92
+ print_api("Hyper-V is enabled")
93
+ else:
94
+ # Command to enable Virtual Machine Platform
95
+ command = "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All"
96
+
97
+ print_api("Enabling Virtual Machine Platform...")
98
+ process.run_powershell_command(command)
99
+
100
+ # Check if Ubuntu is already installed. If so, exit with a message.
101
+ if is_ubuntu_version_installed():
102
+ print_api("Ubuntu is already installed", color='green')
103
+ sys.exit(0)
104
+
105
+ # Download and Install Ubuntu
106
+ print_api("Installing Ubuntu for WSL...")
107
+ package_file_path: str = str(Path(directory_path, "Ubuntu.appx"))
108
+ process.run_powershell_command(
109
+ f"Invoke-WebRequest -Uri https://aka.ms/wslubuntu2204 -OutFile {package_file_path} -UseBasicParsing")
110
+ process.run_powershell_command(f"Add-AppxPackage {package_file_path}")
111
+
112
+ print_api("Ubuntu installation is complete. You can now launch Ubuntu from the Start Menu.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atomicshop
3
- Version: 2.5.5
3
+ Version: 2.5.6
4
4
  Summary: Atomic functions and classes to make developer life easier
5
5
  Author: Denis Kras
6
6
  License: MIT License
@@ -170,6 +170,7 @@ To get a local copy up and running follow these simple steps.
170
170
  ## Usage
171
171
 
172
172
  To follow. For now, check the files in the library. I tried my best with understandable naming and grouping convention.
173
+ There are some ready to use scripts in the 'addons/mains' folder. You can use them as a reference.
173
174
 
174
175
 
175
176
 
@@ -1,4 +1,4 @@
1
- atomicshop/__init__.py,sha256=xmtfFZeXXUAxvAj0CHGUrttT5dq6j-uH7vNaNZjugMA,122
1
+ atomicshop/__init__.py,sha256=tCeFenBN36rswxpsPeUGcOeOeSmu5wl3QX2WWwVdrHk,122
2
2
  atomicshop/_basics_temp.py,sha256=6cu2dd6r2dLrd1BRNcVDKTHlsHs_26Gpw8QS6v32lQ0,3699
3
3
  atomicshop/appointment_management.py,sha256=N3wVGJgrqJfsj_lqiRfaL3FxMEe57by5Stzanh189mk,7263
4
4
  atomicshop/archiver.py,sha256=E4dgAuh6ARtAWRW6Q0RdnMRMzsE_S1NjMiajHRIVG9s,5537
@@ -12,7 +12,7 @@ atomicshop/diff_check.py,sha256=RON9cSTgy3jAnwUmAUkOyfF6bgrBKOq9Sbgyl3RYodw,1235
12
12
  atomicshop/dns.py,sha256=bNZOo5jVPzq7OT2qCPukXoK3zb1oOsyaelUwQEyK1SA,2500
13
13
  atomicshop/domains.py,sha256=Rxu6JhhMqFZRcoFs69IoEd1PtYca0lMCG6F1AomP7z4,3197
14
14
  atomicshop/emails.py,sha256=I0KyODQpIMEsNRi9YWSOL8EUPBiWyon3HRdIuSj3AEU,1410
15
- atomicshop/filesystem.py,sha256=j2Up11t5VCxHAC7uT54AkRqnqL9WFAdpnBlJc8o2dPk,25854
15
+ atomicshop/filesystem.py,sha256=nVun_XRMynayrvudsr2B47keFFCcjXf8VagotH8YwKI,28085
16
16
  atomicshop/functions.py,sha256=VqLjxAxhaxUr-Ad8P1cw9bZGdZpbtqfCaXQyHf3CM9g,509
17
17
  atomicshop/github_wrapper.py,sha256=7pZkhliP4vdcdeVtbgTDEzBS3lUw3-mp5PMWUDA19V0,4347
18
18
  atomicshop/hashing.py,sha256=k_HXR7FnPUzLUKk8EiewJ_gLFBlWncZluiBwzplFMWs,3548
@@ -23,7 +23,7 @@ atomicshop/keyboard_press.py,sha256=1W5kRtOB75fulVx-uF2yarBhW0_IzdI1k73AnvXstk0,
23
23
  atomicshop/pbtkmultifile_argparse.py,sha256=aEk8nhvoQVu-xyfZosK3ma17CwIgOjzO1erXXdjwtS4,4574
24
24
  atomicshop/permissions.py,sha256=CYTDVOI0jh9ks0ZLnnOuPzppgCszFEc9-92DTkVTYi4,522
25
25
  atomicshop/print_api.py,sha256=3n1CoiXvDcDGg00n5gEmQYInHryIhWbcpNjVobO1Gao,11468
26
- atomicshop/process.py,sha256=RRcbTXwDg00eDRsZjUQwcTkVKybn9PKtOf6X7EVIOmU,13809
26
+ atomicshop/process.py,sha256=i_25PrSqSBbTcstCi_8rWVXAEYco81l6b9x1l_egTOY,14193
27
27
  atomicshop/process_name_cmd.py,sha256=TNAK6kQZm5JKWzEW6QLqVHEG98ZLNDQiSS4YwDk8V8c,3830
28
28
  atomicshop/process_poller.py,sha256=t79SwTX_4scH2WIH_ziw27aodG1ibhEFWbsVsmTyOVA,10846
29
29
  atomicshop/python_functions.py,sha256=onZ272J1IiSQToqdzEvvWAFHe0EAJnNkAVv0mYkeNNw,4464
@@ -45,6 +45,7 @@ atomicshop/addons/a_setup_scripts/install_psycopg2_ubuntu.sh,sha256=lM7LkXQ2AxfF
45
45
  atomicshop/addons/a_setup_scripts/install_pywintrace_0.3.cmd,sha256=lEP_o6rWcBFUyup6_c-LTL3Q2LRMqryLuG3mJw080Zc,115
46
46
  atomicshop/addons/mains/factw_fact_extractor_docker_image_main_sudo.py,sha256=DDKX3Wp2SmzMCEtCIEOUbEKMob2ZQ7VEQGLEf9uYXrs,320
47
47
  atomicshop/addons/mains/install_docker_ubuntu_main_sudo.py,sha256=3VDGDO41Vubzf64DaBapLlFYX52dEdyPBNfolSsbGcM,161
48
+ atomicshop/addons/mains/install_wsl_ubuntu_lts_admin.py,sha256=3RjHoCEg6BCfONEKeH6vGDd9ZLun5dOp-jiDSlFbmKU,291
48
49
  atomicshop/addons/package_setup/CreateWheel.cmd,sha256=hq9aWBSH6iffYlZyaCNrFlA0vxMh3j1k8DQE8IARQuA,189
49
50
  atomicshop/addons/package_setup/Setup in Edit mode.cmd,sha256=299RsExjR8Mup6YyC6rW0qF8lnwa3uIzwk_gYg_R_Ss,176
50
51
  atomicshop/addons/package_setup/Setup.cmd,sha256=IMm0PfdARH7CG7h9mbWwmWD9X47l7tddwQ2U4MUxy3A,213
@@ -128,11 +129,12 @@ atomicshop/wrappers/numpyw.py,sha256=sBV4gSKyr23kXTalqAb1oqttzE_2XxBooCui66jbAqc
128
129
  atomicshop/wrappers/process_wrapper_pbtk.py,sha256=ycPmBRnv627RWks6N8OhxJQe8Gu3h3Vwj-4HswPOw0k,599
129
130
  atomicshop/wrappers/psutilw.py,sha256=W9PSEZmrm_Ct_-6oKqAcbgbyF21CwcIbbHOkVqgMiow,20866
130
131
  atomicshop/wrappers/pyopensslw.py,sha256=OBWxA6EJ2vU_Qlf4M8m6ilcG3hyYB4yB0EsXUf7NhEU,6804
132
+ atomicshop/wrappers/wslw.py,sha256=I6Im5unWniiXXK4TDonK3a9N9DrotdJCtHxmtRv-z6o,4149
131
133
  atomicshop/wrappers/certauthw/certauth.py,sha256=hKedW0DOWlEigSNm8wu4SqHkCQsGJ1tJfH7s4nr3Bk0,12223
132
134
  atomicshop/wrappers/certauthw/certauthw.py,sha256=4WvhjANI7Kzqrr_nKmtA8Kf7B6rute_5wfP65gwQrjw,8082
133
135
  atomicshop/wrappers/ctyping/process_winapi.py,sha256=QcXL-ETtlSSkoT8F7pYle97ubGWsjYp8cx8HxkVMgAc,2762
134
136
  atomicshop/wrappers/dockerw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
135
- atomicshop/wrappers/dockerw/install_docker.py,sha256=DIItfa3FhLCSYS8_8twXusIprG__Gs4qbwnYMsr8N0s,2769
137
+ atomicshop/wrappers/dockerw/install_docker.py,sha256=dpSOmD690oLukoLCo0u6Pzh5fRyCWBuSQEtG8VwC3jk,2765
136
138
  atomicshop/wrappers/factw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
137
139
  atomicshop/wrappers/factw/fact_config.py,sha256=J-K9Zn50WcDC7ubb-boraSZExfBk7a6M52NhRJVlsjk,895
138
140
  atomicshop/wrappers/factw/get_file_data.py,sha256=ChKC0OjgjFlNubZQBwcGhRO3L2pccc27RLRlAMIUix4,1641
@@ -186,8 +188,8 @@ atomicshop/wrappers/socketw/socket_server_tester.py,sha256=VfNthyBvgI5tL9v3Qprh4
186
188
  atomicshop/wrappers/socketw/socket_wrapper.py,sha256=aXBwlEIJhFT0-c4i8iNlFx2It9VpCEpsv--5Oqcpxao,11624
187
189
  atomicshop/wrappers/socketw/ssl_base.py,sha256=k4V3gwkbq10MvOH4btU4onLX2GNOsSfUAdcHmL1rpVE,2274
188
190
  atomicshop/wrappers/socketw/statistics_csv.py,sha256=t3dtDEfN47CfYVi0CW6Kc2QHTEeZVyYhc57IYYh5nmA,826
189
- atomicshop-2.5.5.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
190
- atomicshop-2.5.5.dist-info/METADATA,sha256=iVRLGp_JpWMG68tjZ0d3rvth64JzLho7ZRriSNsfNAE,10167
191
- atomicshop-2.5.5.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
192
- atomicshop-2.5.5.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
193
- atomicshop-2.5.5.dist-info/RECORD,,
191
+ atomicshop-2.5.6.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
192
+ atomicshop-2.5.6.dist-info/METADATA,sha256=R3xh983G78wSve1rqT6gdglDmTK5kH3fcMYnG-Q6O_I,10267
193
+ atomicshop-2.5.6.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
194
+ atomicshop-2.5.6.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
195
+ atomicshop-2.5.6.dist-info/RECORD,,