atomicshop 2.11.47__py3-none-any.whl → 2.11.49__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.47'
4
+ __version__ = '2.11.49'
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
@@ -1180,52 +1182,94 @@ def create_dict_of_path(
1180
1182
  current_level = existing_entry["included"]
1181
1183
 
1182
1184
 
1183
- def is_any_file_in_directory_locked(directory_path: str) -> bool:
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:
1184
1190
  """
1185
- The function checks if any file in the directory is locked (if the file is currently being written to that directory
1186
- it will be locked for reading). Basically it opens a handle for read and write and if it fails, then the file is
1187
- locked.
1191
+ open_files: list = []
1188
1192
 
1189
- :param directory_path: string, full path to directory.
1190
- :return: boolean, if 'True', then at least one file in the directory is locked.
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_opened_by_process(directory_path: str) -> bool:
1191
1209
  """
1210
+ The function checks if any file in the directory is opened in any process using psutil.
1211
+
1212
+ :param directory_path: string, full path to directory.
1213
+ :return: boolean, if 'True', then at least one file in the directory is opened by a process.
1214
+ """
1215
+
1216
+ # for filename in os.listdir(directory_path):
1217
+ # file_path = os.path.join(directory_path, filename)
1218
+ # if os.path.isfile(file_path):
1219
+ # return is_file_locked(file_path)
1220
+ # return False
1221
+
1222
+ # Iterate over all running processes
1223
+ for proc in psutil.process_iter(['pid', 'name']):
1224
+ try:
1225
+ # List open files for the process
1226
+ proc_open_files = proc.open_files()
1227
+ for file in proc_open_files:
1228
+ if file.path.startswith(directory_path):
1229
+ return True
1230
+ except (psutil.AccessDenied, psutil.NoSuchProcess):
1231
+ # Ignore processes that can't be accessed
1232
+ continue
1192
1233
 
1193
- for filename in os.listdir(directory_path):
1194
- file_path = os.path.join(directory_path, filename)
1195
- if os.path.isfile(file_path):
1196
- return is_file_locked(file_path)
1197
1234
  return False
1198
1235
 
1199
1236
 
1200
- def is_any_file_locked_in_list(file_paths_list: list[str]) -> bool:
1237
+ def is_any_file_in_list_open_by_process(file_paths_list: list[str]) -> bool:
1201
1238
  """
1202
- The function checks if any file in the list is locked (if the file is currently being written to it will be locked
1203
- for reading). Basically it opens a handle for read and write and if it fails, then the file is locked.
1239
+ The function checks if any file in the list is opened by any running process.
1204
1240
 
1205
1241
  :param file_paths_list: list of strings, full paths to files.
1206
1242
  :return: boolean, if 'True', then at least one file in the list is locked.
1207
1243
  """
1208
1244
 
1209
1245
  for file_path in file_paths_list:
1210
- if is_file_locked(file_path):
1246
+ if is_file_open_by_process(file_path):
1211
1247
  return True
1212
1248
  return False
1213
1249
 
1214
1250
 
1215
- def is_file_locked(file_path: str) -> bool:
1251
+ def is_file_open_by_process(file_path: str) -> bool:
1216
1252
  """
1217
- The function checks if the file is locked (if the file is currently being written to it will be locked for reading).
1218
- Basically it opens a handle for read and write and if it fails, then the file is locked.
1253
+ The function checks if the file is opened in any of the running processes.
1219
1254
 
1220
1255
  :param file_path: string, full path to file.
1221
1256
  :return: boolean, if 'True', then the file is locked.
1222
1257
  """
1223
1258
 
1224
- try:
1225
- # Attempt to open the file exclusively
1226
- with open(file_path, 'rb+') as f:
1227
- pass
1228
- except IOError:
1229
- # If we can't open the file, it might be in the process of being copied
1230
- return True
1259
+ # If the file doesn't exist, or it is not a file, it's not locked.
1260
+ if not os.path.isfile(file_path):
1261
+ return False
1262
+
1263
+ # Iterate over all running processes
1264
+ for proc in psutil.process_iter(['pid', 'name']):
1265
+ try:
1266
+ # List open files for the process
1267
+ proc_open_files = proc.open_files()
1268
+ for file in proc_open_files:
1269
+ if file.path == file_path:
1270
+ return True
1271
+ except (psutil.AccessDenied, psutil.NoSuchProcess):
1272
+ # Ignore processes that can't be accessed
1273
+ continue
1274
+
1231
1275
  return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atomicshop
3
- Version: 2.11.47
3
+ Version: 2.11.49
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=iicioUVwuMXQSs-gY_TniBemm3mIn4HWv1LaKkaK9JU,124
1
+ atomicshop/__init__.py,sha256=qgi85ZKKeYx9w0YfZF0iWyjf6YkZavOGGnHhYdTgoP4,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=1KjRxsUVwtKwu87LheM6Tj1Wr2FLRmLA1YjLK-NpoUI,46010
17
+ atomicshop/filesystem.py,sha256=M4x2jTPMOyvwxJD9hJzgJ6BgF2Z9SIDf2Ye4ImXvXtY,47268
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.47.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
248
- atomicshop-2.11.47.dist-info/METADATA,sha256=Cv2ibrVF1l6qxqTF4UDs3Q5M3JuuC6wq_ISHxyxuoZ0,10448
249
- atomicshop-2.11.47.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
250
- atomicshop-2.11.47.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
251
- atomicshop-2.11.47.dist-info/RECORD,,
247
+ atomicshop-2.11.49.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
248
+ atomicshop-2.11.49.dist-info/METADATA,sha256=2Q8mFvwf5Wx4Hyhu2Ngv8Hr2U4hfvkBFGiNpaVdSkg4,10448
249
+ atomicshop-2.11.49.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
250
+ atomicshop-2.11.49.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
251
+ atomicshop-2.11.49.dist-info/RECORD,,