atomicshop 2.11.46__py3-none-any.whl → 2.11.48__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.11.46'
4
+ __version__ = '2.11.48'
atomicshop/filesystem.py CHANGED
@@ -7,6 +7,8 @@ import stat
7
7
  import errno
8
8
  from contextlib import contextmanager
9
9
 
10
+ import psutil
11
+
10
12
  from .print_api import print_api, print_status_of_list
11
13
  from .basics import strings, list_of_dicts
12
14
  from .file_io import file_io
@@ -1178,3 +1180,100 @@ def create_dict_of_path(
1178
1180
  # If it's not the last part and the entry exists, navigate deeper
1179
1181
  if not is_last_part:
1180
1182
  current_level = existing_entry["included"]
1183
+
1184
+
1185
+ def list_open_files_in_directory(directory):
1186
+ """
1187
+ The function lists all open files by any processes in the directory.
1188
+ :param directory:
1189
+ :return:
1190
+ """
1191
+ open_files: list = []
1192
+
1193
+ # Iterate over all running processes
1194
+ for proc in psutil.process_iter(['pid', 'name']):
1195
+ try:
1196
+ # List open files for the process
1197
+ proc_open_files = proc.open_files()
1198
+ for file in proc_open_files:
1199
+ if file.path.startswith(directory):
1200
+ open_files.append((proc.info['pid'], proc.info['name'], file.path))
1201
+ except (psutil.AccessDenied, psutil.NoSuchProcess):
1202
+ # Ignore processes that can't be accessed
1203
+ continue
1204
+
1205
+ return open_files
1206
+
1207
+
1208
+ def is_any_file_in_directory_locked(directory_path: str) -> bool:
1209
+ """
1210
+ The function checks if any file in the directory is locked (if the file is currently being written to that directory
1211
+ it will be locked for reading). Basically it opens a handle for read and write and if it fails, then the file is
1212
+ locked.
1213
+
1214
+ :param directory_path: string, full path to directory.
1215
+ :return: boolean, if 'True', then at least one file in the directory is locked.
1216
+ """
1217
+
1218
+ # for filename in os.listdir(directory_path):
1219
+ # file_path = os.path.join(directory_path, filename)
1220
+ # if os.path.isfile(file_path):
1221
+ # return is_file_locked(file_path)
1222
+ # return False
1223
+
1224
+ # Iterate over all running processes
1225
+ for proc in psutil.process_iter(['pid', 'name']):
1226
+ try:
1227
+ # List open files for the process
1228
+ proc_open_files = proc.open_files()
1229
+ for file in proc_open_files:
1230
+ if file.path.startswith(directory_path):
1231
+ return True
1232
+ except (psutil.AccessDenied, psutil.NoSuchProcess):
1233
+ # Ignore processes that can't be accessed
1234
+ continue
1235
+
1236
+ return False
1237
+
1238
+
1239
+ def is_any_file_locked_in_list(file_paths_list: list[str]) -> bool:
1240
+ """
1241
+ The function checks if any file in the list is locked (if the file is currently being written to it will be locked
1242
+ for reading). Basically it opens a handle for read and write and if it fails, then the file is locked.
1243
+
1244
+ :param file_paths_list: list of strings, full paths to files.
1245
+ :return: boolean, if 'True', then at least one file in the list is locked.
1246
+ """
1247
+
1248
+ for file_path in file_paths_list:
1249
+ if is_file_locked(file_path):
1250
+ return True
1251
+ return False
1252
+
1253
+
1254
+ def is_file_locked(file_path: str) -> bool:
1255
+ """
1256
+ The function checks if the file is locked (if the file is currently being written to it will be locked for reading).
1257
+ Basically it opens a handle for read and write and if it fails, then the file is locked.
1258
+
1259
+ :param file_path: string, full path to file.
1260
+ :return: boolean, if 'True', then the file is locked.
1261
+ """
1262
+
1263
+ # If the file doesn't exist, or it is not a file, it's not locked.
1264
+ if not os.path.isfile(file_path):
1265
+ return False
1266
+
1267
+ # Iterate over all running processes
1268
+ for proc in psutil.process_iter(['pid', 'name']):
1269
+ try:
1270
+ # List open files for the process
1271
+ proc_open_files = proc.open_files()
1272
+ for file in proc_open_files:
1273
+ if file.path == file_path:
1274
+ return True
1275
+ except (psutil.AccessDenied, psutil.NoSuchProcess):
1276
+ # Ignore processes that can't be accessed
1277
+ continue
1278
+
1279
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atomicshop
3
- Version: 2.11.46
3
+ Version: 2.11.48
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=bxumtahjd5gofnYy1s9ED-rXiK-IjMdcWAoyOByHwl0,124
1
+ atomicshop/__init__.py,sha256=cFT8R-KwR0UCeMnGtLPqN3BpDbAz4usM9rbu1PpVwTg,124
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
@@ -14,7 +14,7 @@ atomicshop/dns.py,sha256=bNZOo5jVPzq7OT2qCPukXoK3zb1oOsyaelUwQEyK1SA,2500
14
14
  atomicshop/domains.py,sha256=Rxu6JhhMqFZRcoFs69IoEd1PtYca0lMCG6F1AomP7z4,3197
15
15
  atomicshop/emails.py,sha256=I0KyODQpIMEsNRi9YWSOL8EUPBiWyon3HRdIuSj3AEU,1410
16
16
  atomicshop/file_types.py,sha256=-0jzQMRlmU1AP9DARjk-HJm1tVE22E6ngP2mRblyEjY,763
17
- atomicshop/filesystem.py,sha256=I72yd_-G1y7aWtD7IzgUQn5BBg8Dpri8o7Jrb_-kfW4,44060
17
+ atomicshop/filesystem.py,sha256=tpuFGFo6sjsuTILY0K-NI4w3CsELoGOoFpAViSnGtzs,47658
18
18
  atomicshop/functions.py,sha256=pK8hoCE9z61PtWCxQJsda7YAphrLH1wxU5x-1QJP-sY,499
19
19
  atomicshop/hashing.py,sha256=Le8qGFyt3_wX-zGTeQShz7L2HL_b6nVv9PnawjglyHo,3474
20
20
  atomicshop/http_parse.py,sha256=nrf2rZcprLqtW8HVrV7TCZ1iTBcWRRy-mXIlAOzcaJs,9703
@@ -244,8 +244,8 @@ atomicshop/wrappers/socketw/socket_server_tester.py,sha256=AhpurHJmP2kgzHaUbq5ey
244
244
  atomicshop/wrappers/socketw/socket_wrapper.py,sha256=aXBwlEIJhFT0-c4i8iNlFx2It9VpCEpsv--5Oqcpxao,11624
245
245
  atomicshop/wrappers/socketw/ssl_base.py,sha256=k4V3gwkbq10MvOH4btU4onLX2GNOsSfUAdcHmL1rpVE,2274
246
246
  atomicshop/wrappers/socketw/statistics_csv.py,sha256=t3dtDEfN47CfYVi0CW6Kc2QHTEeZVyYhc57IYYh5nmA,826
247
- atomicshop-2.11.46.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
248
- atomicshop-2.11.46.dist-info/METADATA,sha256=z9gx8Ogm7E4ZDU2NuTw-xhnx3CPGOPeg3r5uN6PGFDc,10448
249
- atomicshop-2.11.46.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
250
- atomicshop-2.11.46.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
251
- atomicshop-2.11.46.dist-info/RECORD,,
247
+ atomicshop-2.11.48.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
248
+ atomicshop-2.11.48.dist-info/METADATA,sha256=hrq4NMvVR15pdZZrP0cmhUp6Vy42wQxe0QOIkf-_vZ4,10448
249
+ atomicshop-2.11.48.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
250
+ atomicshop-2.11.48.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
251
+ atomicshop-2.11.48.dist-info/RECORD,,