atomicshop 2.16.1__py3-none-any.whl → 2.16.3__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.16.1'
4
+ __version__ = '2.16.3'
@@ -1,4 +1,5 @@
1
1
  import statistics
2
+ from pathlib import Path
2
3
  from typing import Literal
3
4
 
4
5
  from ...print_api import print_api
@@ -39,12 +40,12 @@ def calculate_moving_average(
39
40
  :param print_kwargs: dict, the print_api arguments.
40
41
  """
41
42
 
42
- date_pattern: str = consts.DEFAULT_ROTATING_SUFFIXES_FROM_WHEN['midnight']
43
+ date_format: str = consts.DEFAULT_ROTATING_SUFFIXES_FROM_WHEN['midnight']
43
44
 
44
45
  # Get all the file paths and their midnight rotations.
45
46
  logs_paths: list = reading.get_logs_paths(
46
47
  log_file_path=file_path,
47
- date_pattern=date_pattern
48
+ date_format=date_format
48
49
  )
49
50
 
50
51
  if get_deviation_for_last_day_only:
@@ -129,7 +130,12 @@ def get_data_dict_from_statistics_content(
129
130
  type_to_check: str = line['host'] + line['path']
130
131
  # Remove the parameters from the URL.
131
132
  url_parsed = urls.url_parser(type_to_check)
132
- type_to_check = url_parsed['path']
133
+
134
+ if url_parsed['file'] and Path(url_parsed['file']).suffix in ['.gz', '.gzip', '.zip']:
135
+ type_to_check = '/'.join(url_parsed['directories'][:-1])
136
+ else:
137
+ type_to_check = url_parsed['path']
138
+
133
139
  # Remove the last slash from the URL.
134
140
  type_to_check = type_to_check.removesuffix('/')
135
141
  else:
atomicshop/urls.py CHANGED
@@ -8,6 +8,11 @@ def url_parser(url):
8
8
  directories = parts.path.strip('/').split('/')
9
9
  queries = parts.query.strip('&').split('&')
10
10
 
11
+ if len(directories) > 1 and '.' in directories[-1]:
12
+ file = directories[-1]
13
+ else:
14
+ file = ''
15
+
11
16
  elements = {
12
17
  'scheme': parts.scheme,
13
18
  'netloc': parts.netloc,
@@ -17,6 +22,7 @@ def url_parser(url):
17
22
  'fragment': parts.fragment,
18
23
  'directories': directories,
19
24
  'queries': queries,
25
+ 'file': file
20
26
  }
21
27
 
22
28
  return elements
@@ -4,6 +4,7 @@ from pathlib import Path
4
4
  import datetime
5
5
 
6
6
  from ... import filesystem, datetimes
7
+ from ...basics import booleans
7
8
  from ...file_io import csvs
8
9
 
9
10
 
@@ -15,9 +16,10 @@ def get_logs_paths(
15
16
  log_files_directory_path: str = None,
16
17
  log_file_path: str = None,
17
18
  file_name_pattern: str = '*.*',
18
- date_pattern: str = None,
19
+ date_format: str = None,
19
20
  latest_only: bool = False,
20
- previous_day_only: bool = False
21
+ previous_day_only: bool = False,
22
+ specific_date: str = None
21
23
  ):
22
24
  """
23
25
  This function gets the logs file paths from the directory. Supports rotating files to get the logs by time.
@@ -37,11 +39,18 @@ def get_logs_paths(
37
39
  log_files_directory_path = 'C:/logs'
38
40
  :param file_name_pattern: Pattern to match the log files names.
39
41
  Default file_name_pattern will match all the files.
40
- :param date_pattern: Pattern to match the date in the log file name.
42
+ :param date_format: date format string pattern to match the date in the log file name.
41
43
  If specified, the function will get the log file by the date pattern.
42
44
  If not specified, the function will get the file date by file last modified time.
45
+
46
+ Example:
47
+ date_format = '%Y-%m-%d'
43
48
  :param latest_only: Boolean, if True, only the latest log file path will be returned.
44
49
  :param previous_day_only: Boolean, if True, only the log file path from the previous day will be returned.
50
+ :param specific_date: Specific date to get the log file path.
51
+ If specified, the function will get the log file by the specific date.
52
+ Meaning that 'date_format' must be specified.
53
+
45
54
  """
46
55
 
47
56
  if not log_files_directory_path and not log_file_path:
@@ -49,8 +58,14 @@ def get_logs_paths(
49
58
  elif log_files_directory_path and log_file_path:
50
59
  raise ValueError('Both "log_files_directory_path" and "log_file_path" cannot be specified at the same time.')
51
60
 
52
- if latest_only and previous_day_only:
53
- raise ValueError('Both "latest_only" and "previous_day_only" cannot be True at the same time.')
61
+ if latest_only or previous_day_only or specific_date:
62
+ booleans.check_3_booleans_when_only_1_can_be_true(
63
+ (latest_only, 'latest_only'),
64
+ (previous_day_only, 'previous_day_only'),
65
+ (specific_date, 'specific_date'))
66
+
67
+ if not date_format and specific_date:
68
+ raise ValueError('If "specific_date" is specified, "date_format" must be specified.')
54
69
 
55
70
  # If log file path is specified, get the file_name_pattern from the file name.
56
71
  if log_file_path:
@@ -74,22 +89,22 @@ def get_logs_paths(
74
89
  if logs_files:
75
90
  first_file_name: str = Path(logs_files[0]['file_path']).name
76
91
  first_datetime_object, first_date_string, first_timestamp_float = (
77
- datetimes.get_datetime_from_complex_string_by_pattern(first_file_name, date_pattern))
92
+ datetimes.get_datetime_from_complex_string_by_pattern(first_file_name, date_format))
78
93
 
79
94
  # The problem here is the file name that doesn't contain the date string in the name.
80
95
  # If it is regular log rotation, then there will be one file that doesn't have the date string in the name.
81
96
  # If the function used to get the previous day log, then there will be no file that doesn't have the date string.
82
97
  if len(logs_files) > 1 or (len(logs_files) == 1 and first_date_string):
83
- if date_pattern:
98
+ if date_format:
84
99
  latest_timestamp: float = 0
85
100
  for file_index, single_file in enumerate(logs_files):
86
101
  # Get file name from current loop file path.
87
102
  current_file_name: str = Path(single_file['file_path']).name
88
103
  logs_files[file_index]['file_name'] = current_file_name
89
104
 
90
- # Get the datetime object from the file name by the date pattern.
105
+ # Get the datetime object from the file name by the date format pattern.
91
106
  datetime_object, date_string, timestamp_float = (
92
- datetimes.get_datetime_from_complex_string_by_pattern(current_file_name, date_pattern))
107
+ datetimes.get_datetime_from_complex_string_by_pattern(current_file_name, date_format))
93
108
 
94
109
  # Update the last modified time to the dictionary.
95
110
  logs_files[file_index]['last_modified'] = timestamp_float
@@ -113,7 +128,7 @@ def get_logs_paths(
113
128
  latest_timestamp += 86400
114
129
  logs_files[file_index]['last_modified'] = latest_timestamp
115
130
  logs_files[file_index]['datetime'] = datetime.datetime.fromtimestamp(latest_timestamp)
116
- logs_files[file_index]['date_string'] = logs_files[file_index]['datetime'].strftime(date_pattern)
131
+ logs_files[file_index]['date_string'] = logs_files[file_index]['datetime'].strftime(date_format)
117
132
  break
118
133
 
119
134
  # Sort the files by the last modified time.
@@ -128,6 +143,10 @@ def get_logs_paths(
128
143
  logs_files = []
129
144
  else:
130
145
  logs_files = [logs_files[-2]]
146
+
147
+ if specific_date:
148
+ # Check if there is a specific date log file.
149
+ logs_files = [single_file for single_file in logs_files if single_file['date_string'] == specific_date]
131
150
  # If there is only one file, meaning it is the current day log.
132
151
  # If the 'previous_day_only' is True, then there are no previous day logs to output.
133
152
  elif len(logs_files) == 1 and previous_day_only:
@@ -140,7 +159,7 @@ def get_all_log_files_into_list(
140
159
  log_files_directory_path: str = None,
141
160
  log_file_path: str = None,
142
161
  file_name_pattern: str = '*.*',
143
- date_pattern: str = None,
162
+ date_format: str = None,
144
163
  log_type: Literal['csv'] = 'csv',
145
164
  header_type_of_files: Literal['first', 'all'] = 'first',
146
165
  remove_logs: bool = False,
@@ -155,9 +174,12 @@ def get_all_log_files_into_list(
155
174
  :param log_file_path: Path to the log file. Check the 'get_logs_paths' function for more details.
156
175
  :param file_name_pattern: Pattern to match the log files names.
157
176
  Default file_name_pattern will match all the files.
158
- :param date_pattern: Pattern to match the date in the log file name.
177
+ :param date_format: date format string pattern to match the date in the log file name.
159
178
  If specified, the function will get the log file by the date pattern.
160
179
  If not specified, the function will get the file date by file last modified time.
180
+
181
+ Example:
182
+ date_format = '%Y-%m-%d'
161
183
  :param log_type: Type of log to get.
162
184
  :param header_type_of_files: Type of header to get from the files.
163
185
  'first' - Only the first file has a header for CSV. This header will be used for the rest of the files.
@@ -183,7 +205,7 @@ def get_all_log_files_into_list(
183
205
  log_files_directory_path=log_files_directory_path,
184
206
  log_file_path=log_file_path,
185
207
  file_name_pattern=file_name_pattern,
186
- date_pattern=date_pattern)
208
+ date_format=date_format)
187
209
 
188
210
  # Read all the logs.
189
211
  logs_content: list = list()
@@ -263,16 +285,19 @@ class LogReader:
263
285
  def __init__(
264
286
  self,
265
287
  log_file_path: str,
266
- date_pattern: str = None,
288
+ date_format: str = None,
267
289
  log_type: Literal['csv'] = 'csv',
268
290
  get_previous_file: bool = False,
269
291
  header: list = None
270
292
  ):
271
293
  """
272
294
  :param log_file_path: Path to the log file.
273
- :param date_pattern: Pattern to match the date in the log file name.
295
+ :param date_format: date format string pattern to match the date in the log file name.
274
296
  If specified, the function will get the log file by the date pattern.
275
297
  If not specified, the function will get the file date by file last modified time.
298
+
299
+ Example:
300
+ date_format = '%Y-%m-%d'
276
301
  :param log_type: Type of log to get.
277
302
  :param get_previous_file: Boolean, if True, the function will get the previous log file.
278
303
  For example, your log is set to rotate every Midnight.
@@ -287,7 +312,7 @@ class LogReader:
287
312
  """
288
313
 
289
314
  self.log_file_path: str = log_file_path
290
- self.date_pattern: str = date_pattern
315
+ self.date_format: str = date_format
291
316
  self.log_type: Literal['csv'] = log_type
292
317
  self.get_previous_file: bool = get_previous_file
293
318
  self.header: list = header
@@ -329,7 +354,7 @@ class LogReader:
329
354
  # Get the latest statistics file path.
330
355
  latest_statistics_file_path_object = get_logs_paths(
331
356
  log_file_path=self.log_file_path,
332
- date_pattern=self.date_pattern,
357
+ date_format=self.date_format,
333
358
  latest_only=True
334
359
  )
335
360
 
@@ -344,7 +369,7 @@ class LogReader:
344
369
  try:
345
370
  previous_day_statistics_file_path = get_logs_paths(
346
371
  log_file_path=self.log_file_path,
347
- date_pattern=self.date_pattern,
372
+ date_format=self.date_format,
348
373
  previous_day_only=True
349
374
  )[0]['file_path']
350
375
  # If you get IndexError, it means that there are no previous day logs to read.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atomicshop
3
- Version: 2.16.1
3
+ Version: 2.16.3
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=tNo-zv64ouxuBBLz7a94FTgCjvROQM_rI3A3RN7k-R4,123
1
+ atomicshop/__init__.py,sha256=AKEuH8PqWV4-EZXo12aT4GrKcoEcFGoUZbDx7SgXtAY,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
@@ -41,7 +41,7 @@ atomicshop/system_resource_monitor.py,sha256=WvnnQrD5W9NRqOWI2YNcL-ut2UrvhrYToVl
41
41
  atomicshop/system_resources.py,sha256=0mhDZBEcMzToCOw5ArJhtqYjktOW6iJGdyRkJ01Cpwk,9272
42
42
  atomicshop/tempfiles.py,sha256=uq1ve2WlWehZ3NOTXJnpBBMt6HyCdBufqedF0HyzA6k,2517
43
43
  atomicshop/timer.py,sha256=7Zw1KRV0acHCRATMnanyX2MLBb63Hc-6us3rCZ9dNlY,2345
44
- atomicshop/urls.py,sha256=yqEn8YJS2Ma-cZidn0NZgIfuzFX0rReJ_L5IDt6iWJA,1414
44
+ atomicshop/urls.py,sha256=aJ0NGS9qqaKeqjkkWBs80jaBBg6MYBiPuLIyPGxscVc,1557
45
45
  atomicshop/uuids.py,sha256=JSQdm3ZTJiwPQ1gYe6kU0TKS_7suwVrHc8JZDGYlydM,2214
46
46
  atomicshop/virtualization.py,sha256=LPP4vjE0Vr10R6DA4lqhfX_WaNdDGRAZUW0Am6VeGco,494
47
47
  atomicshop/web.py,sha256=J9izvF5LNEVOVkkWon0XUgJmR7nrFln03nIxW7wUZWg,11547
@@ -143,7 +143,7 @@ atomicshop/mitm/engines/__reference_general/recorder___reference_general.py,sha2
143
143
  atomicshop/mitm/engines/__reference_general/responder___reference_general.py,sha256=1AM49UaFTKA0AHw-k3SV3uH3QbG-o6ux0c-GoWkKNU0,6993
144
144
  atomicshop/mitm/statistic_analyzer_helper/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
145
145
  atomicshop/mitm/statistic_analyzer_helper/analyzer_helper.py,sha256=pk6L1t1ea1kvlBoR9QEJptOmaX-mumhwLsP2GCKukbk,5920
146
- atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py,sha256=xMvFnbsiDjtbmASErV-Deuy9u4ft14seM33o-immhhM,16391
146
+ atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py,sha256=lsG_eSWf6M_3AfWqIYEBNwYAyVHJfBiRVKHhmWIOZ9A,16615
147
147
  atomicshop/monitor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
148
148
  atomicshop/monitor/change_monitor.py,sha256=K5NlVp99XIDDPnQQMdru4BDmua_DtcDIhVAzkTOvD5s,7673
149
149
  atomicshop/monitor/checks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -248,7 +248,7 @@ atomicshop/wrappers/loggingw/formatters.py,sha256=7XUJvlB0CK4DCkEp8NTL0S0dkyrZD0
248
248
  atomicshop/wrappers/loggingw/handlers.py,sha256=yFYBeTkxnpmtlauoH3ZEFEHUYQYu9YL-ycd9sYTvOl4,16928
249
249
  atomicshop/wrappers/loggingw/loggers.py,sha256=DHOOTAtqkwn1xgvLHSkOiBm6yFGNuQy1kvbhG-TDog8,2374
250
250
  atomicshop/wrappers/loggingw/loggingw.py,sha256=lo4OZPXCbYZi3GqpaaJSs9SOGFfqD2EgHzzTK7f5IR4,11275
251
- atomicshop/wrappers/loggingw/reading.py,sha256=ZgFbmQdStLg2nlgzJEznsvEP0r63ki_2RRwsNnggLDI,18148
251
+ atomicshop/wrappers/loggingw/reading.py,sha256=ZVFc6jjxNBbxknK8m4ec5WUFHtDUiM7vnsyYnWUBjWU,19109
252
252
  atomicshop/wrappers/mongodbw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
253
253
  atomicshop/wrappers/mongodbw/infrastructure.py,sha256=tHqtt__yKGtj24CT5AIk0V0k9t1p_PjezFExXRmmmcA,1517
254
254
  atomicshop/wrappers/mongodbw/install_mongodb.py,sha256=21Re0NpikgYOKelyPTkosoQQxzu67dy80Kj204TL5eo,6644
@@ -304,8 +304,8 @@ atomicshop/wrappers/socketw/socket_server_tester.py,sha256=SdchUf9qrPk1Rrat0RzvM
304
304
  atomicshop/wrappers/socketw/socket_wrapper.py,sha256=655nGQp0HFy-7KNx8zHsA-miXi9ufC7DNeGsvvGALak,28415
305
305
  atomicshop/wrappers/socketw/ssl_base.py,sha256=k4V3gwkbq10MvOH4btU4onLX2GNOsSfUAdcHmL1rpVE,2274
306
306
  atomicshop/wrappers/socketw/statistics_csv.py,sha256=q5vRA7jL5ERFhIGctn5HjBlOppwSY9qMoEVgo898AIo,2979
307
- atomicshop-2.16.1.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
308
- atomicshop-2.16.1.dist-info/METADATA,sha256=M8TADOGpoNdNhtlfkIZsTKGma4EbAlbeDeSKjINGIvA,10502
309
- atomicshop-2.16.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
310
- atomicshop-2.16.1.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
311
- atomicshop-2.16.1.dist-info/RECORD,,
307
+ atomicshop-2.16.3.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
308
+ atomicshop-2.16.3.dist-info/METADATA,sha256=ysLTKs85RLuQJr6JD-u3QVGH4EkdVE4ETVdwMjdCm-M,10502
309
+ atomicshop-2.16.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
310
+ atomicshop-2.16.3.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
311
+ atomicshop-2.16.3.dist-info/RECORD,,