ezKit 1.8.7__py3-none-any.whl → 1.9.0__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.
ezKit/utils.py CHANGED
@@ -29,15 +29,14 @@ NoneType = type(None)
29
29
  # --------------------------------------------------------------------------------------------------
30
30
 
31
31
 
32
- def v_true(
33
- v_instance: Any,
34
- v_type: Any = None,
32
+ def isTrue(
33
+ object_data: Any,
34
+ object_type: Any = None,
35
35
  true_list: list | tuple | set | str | None = None,
36
- false_list: list | tuple | set | str | None = None,
37
- debug: bool = False
36
+ false_list: list | tuple | set | str | None = None
38
37
  ) -> bool:
39
38
  """
40
- 检查变量类型以及变量是否为 True
39
+ 检查对象类型以及对象数据是否为 True
41
40
 
42
41
  常见类型:
43
42
 
@@ -56,7 +55,7 @@ def v_true(
56
55
 
57
56
  try:
58
57
 
59
- if isinstance(v_instance, v_type):
58
+ if isinstance(object_data, object_type):
60
59
 
61
60
  if all(
62
61
  [
@@ -65,7 +64,7 @@ def v_true(
65
64
  isinstance(true_list, (list, tuple, set, str))
66
65
  ]
67
66
  ):
68
- return v_instance in true_list
67
+ return object_data in true_list
69
68
 
70
69
  if all(
71
70
  [
@@ -74,7 +73,7 @@ def v_true(
74
73
  isinstance(false_list, (list, tuple, set, str))
75
74
  ]
76
75
  ):
77
- return v_instance not in false_list
76
+ return object_data not in false_list
78
77
 
79
78
  if all(
80
79
  [
@@ -84,15 +83,15 @@ def v_true(
84
83
  isinstance(false_list, (list, tuple, set, str))
85
84
  ]
86
85
  ):
87
- return (v_instance in true_list) and (v_instance not in false_list)
86
+ return (object_data in true_list) and (object_data not in false_list)
88
87
 
89
- return v_instance not in [False, None, 0, 0.0, '', (), [], {*()}, {*[]}, {*{}}, {}]
88
+ # return object_data not in [False, None, 0, 0.0, '', (), [], {}, {*()}, {*[]}, {*{}}]
89
+ return bool(object_data)
90
90
 
91
91
  return False
92
92
 
93
93
  except Exception as e:
94
- if v_true(debug, bool):
95
- logger.exception(e)
94
+ logger.exception(e)
96
95
  return False
97
96
 
98
97
 
@@ -101,8 +100,7 @@ def v_true(
101
100
 
102
101
  def os_environ(
103
102
  name: str,
104
- value: Any = None,
105
- debug: bool = False
103
+ value: Any = None
106
104
  ) -> Any:
107
105
  """
108
106
  系统变量
@@ -137,8 +135,7 @@ def os_environ(
137
135
  return value
138
136
 
139
137
  except Exception as e:
140
- if v_true(debug, bool):
141
- logger.exception(e)
138
+ logger.exception(e)
142
139
  return None
143
140
 
144
141
 
@@ -147,8 +144,7 @@ def os_environ(
147
144
 
148
145
  def mam_of_numbers(
149
146
  numbers: list | tuple,
150
- dest_type: str | None = None,
151
- debug: bool = False
147
+ dest_type: str | None = None
152
148
  ) -> tuple[int | float, int | float, int | float] | tuple[None, None, None]:
153
149
  """
154
150
  (maximum, average, minimum)
@@ -170,8 +166,7 @@ def mam_of_numbers(
170
166
  _num_min = min(_numbers)
171
167
  return _num_max, _num_avg, _num_min
172
168
  except Exception as e:
173
- if v_true(debug, bool):
174
- logger.exception(e)
169
+ logger.exception(e)
175
170
  return None, None, None
176
171
 
177
172
 
@@ -180,8 +175,7 @@ def mam_of_numbers(
180
175
 
181
176
  def step_number_for_split_equally(
182
177
  integer: int,
183
- split_equally_number: int,
184
- debug: bool = False
178
+ split_equally_number: int
185
179
  ) -> int | None:
186
180
  """
187
181
  step number for split equally
@@ -205,8 +199,7 @@ def step_number_for_split_equally(
205
199
  return int(integer / split_equally_number)
206
200
  return int(integer / split_equally_number) + 1
207
201
  except Exception as e:
208
- if v_true(debug, bool):
209
- logger.exception(e)
202
+ logger.exception(e)
210
203
  return None
211
204
 
212
205
 
@@ -215,69 +208,13 @@ def step_number_for_split_equally(
215
208
 
216
209
  def division(
217
210
  dividend: int | float,
218
- divisor: int | float,
219
- debug: bool = False
211
+ divisor: int | float
220
212
  ) -> float | None:
221
213
  """Division"""
222
214
  try:
223
215
  return dividend / divisor
224
216
  except Exception as e:
225
- if v_true(debug, bool):
226
- logger.exception(e)
227
- return None
228
-
229
-
230
- def divisor_1000(
231
- dividend: int | float,
232
- debug: bool = False
233
- ) -> float | None:
234
- """Division (divisor: 1000)"""
235
- # 除法, 除以 1000
236
- try:
237
- return dividend / 1000
238
- except Exception as e:
239
- if v_true(debug, bool):
240
- logger.exception(e)
241
- return None
242
-
243
-
244
- def divisor_1024(
245
- dividend: int | float,
246
- debug: bool = False
247
- ) -> float | None:
248
- """Division (divisor: 1024)"""
249
- # 除法, 除以 1024
250
- try:
251
- return dividend / 1024
252
- except Exception as e:
253
- if v_true(debug, bool):
254
- logger.exception(e)
255
- return None
256
-
257
-
258
- def divisor_square_1000(
259
- dividend: int | float,
260
- debug: bool = False
261
- ) -> float | None:
262
- """Division (divisor: 1000*1000)"""
263
- try:
264
- return dividend / (1000 * 1000)
265
- except Exception as e:
266
- if v_true(debug, bool):
267
- logger.exception(e)
268
- return None
269
-
270
-
271
- def divisor_square_1024(
272
- dividend: int | float,
273
- debug: bool = False
274
- ) -> float | None:
275
- """Division (divisor: 1024*1024)"""
276
- try:
277
- return dividend / (1024 * 1024)
278
- except Exception as e:
279
- if v_true(debug, bool):
280
- logger.exception(e)
217
+ logger.exception(e)
281
218
  return None
282
219
 
283
220
 
@@ -286,8 +223,7 @@ def divisor_square_1024(
286
223
 
287
224
  def check_file_type(
288
225
  file_object: str,
289
- file_type: str,
290
- debug: bool = False
226
+ file_type: str
291
227
  ) -> bool:
292
228
  """
293
229
  check file type
@@ -330,8 +266,7 @@ def check_file_type(
330
266
  return result
331
267
 
332
268
  except Exception as e:
333
- if v_true(debug, bool):
334
- logger.exception(e)
269
+ logger.exception(e)
335
270
  return False
336
271
 
337
272
 
@@ -341,7 +276,6 @@ def check_file_type(
341
276
  def list_sort(
342
277
  data: list,
343
278
  deduplication: bool = False,
344
- debug: bool = False,
345
279
  **kwargs
346
280
  ) -> list | None:
347
281
  """list sort"""
@@ -363,15 +297,13 @@ def list_sort(
363
297
  return _data
364
298
 
365
299
  except Exception as e:
366
- if v_true(debug, bool):
367
- logger.exception(e)
300
+ logger.exception(e)
368
301
  return None
369
302
 
370
303
 
371
304
  def list_dict_sorted_by_key(
372
305
  data: list | tuple,
373
306
  key: str,
374
- debug: bool = False,
375
307
  **kwargs
376
308
  ) -> list | None:
377
309
  """list dict sorted by key"""
@@ -381,16 +313,14 @@ def list_dict_sorted_by_key(
381
313
  _data = deepcopy(data)
382
314
  return sorted(_data, key=lambda x: x[key], **kwargs)
383
315
  except Exception as e:
384
- if v_true(debug, bool):
385
- logger.exception(e)
316
+ logger.exception(e)
386
317
  return None
387
318
 
388
319
 
389
320
  def list_split(
390
321
  data: list,
391
322
  number: int,
392
- equally: bool = False,
393
- debug: bool = False
323
+ equally: bool = False
394
324
  ) -> list | None:
395
325
  """list split"""
396
326
  # 列表分割
@@ -431,13 +361,7 @@ def list_split(
431
361
 
432
362
  _step_number: Optional[int] = None
433
363
 
434
- if v_true(debug, bool):
435
- logger.info(f"data object: {_data_object}")
436
- logger.info(f"data length: {_data_length}")
437
-
438
364
  if _data_length < number:
439
- if v_true(debug, bool):
440
- logger.error('number must greater than data length')
441
365
  return None
442
366
 
443
367
  if _data_length == number:
@@ -446,25 +370,14 @@ def list_split(
446
370
 
447
371
  else:
448
372
 
449
- if equally is True:
450
-
451
- _step_number = step_number_for_split_equally(_data_length, number, debug=debug)
373
+ if isTrue(equally, bool):
452
374
 
453
- if v_true(debug, bool):
454
- logger.info(f"step number: {_step_number}")
375
+ _step_number = step_number_for_split_equally(_data_length, number)
455
376
 
456
377
  if _data_length % number == 0:
457
378
 
458
379
  index_number_list = list(range(0, _data_length, number))
459
-
460
- if v_true(debug, bool):
461
- logger.info(f"index number list: {index_number_list}")
462
-
463
380
  for index_number in index_number_list:
464
-
465
- if v_true(debug, bool):
466
- logger.info(f"index: {index_number}, data: {_data_object[index_number:index_number + number]}")
467
-
468
381
  _data_result.append(deepcopy(_data_object[index_number:index_number + number]))
469
382
 
470
383
  else:
@@ -489,49 +402,78 @@ def list_split(
489
402
  return _data_result
490
403
 
491
404
  except Exception as e:
492
- if v_true(debug, bool):
493
- logger.exception(e)
405
+ logger.exception(e)
494
406
  return None
495
407
 
496
408
 
497
409
  def list_print_by_step(
498
410
  data: list,
499
- number: int,
500
- separator: str | None = None,
501
- debug: bool = False
411
+ step: int,
412
+ separator: str = " "
502
413
  ) -> bool:
503
414
  """
504
- list print by step
505
-
506
- 列表按照 步长 和 分隔符 有规律的输出
415
+ 根据 步长 分隔符 有规律的打印列表中的数据
507
416
  """
508
417
  try:
509
418
 
510
- result: list = []
419
+ # result: list = []
511
420
 
512
- if len(data) <= number:
513
- result.append(data)
514
- else:
515
- data_list = list_split(data, number, debug=debug)
516
- if data_list is None or v_true(data_list, list) is False:
421
+ # if len(data) <= step:
422
+ # result.append(data)
423
+ # else:
424
+ # data_list = list_split(data, step, debug=debug)
425
+ # if data_list is None or isTrue(data_list, list) is False:
426
+ # return False
427
+ # result = data_list
428
+
429
+ # for item in result:
430
+ # print(*item, sep=separator)
431
+
432
+ # return True
433
+
434
+ # 判断参数类型
435
+ match True:
436
+ case True if isinstance(data, list) is False:
437
+ logger.error("argument type error: data")
438
+ return False
439
+ case True if isinstance(step, int) is False:
440
+ logger.error("argument type error: step")
441
+ return False
442
+ case True if isinstance(separator, str) is False:
443
+ logger.error("argument type error: separator")
444
+ return False
445
+ case _:
446
+ pass
447
+
448
+ # 判断参数数据
449
+ match True:
450
+ case True if not isTrue(data, list):
451
+ logger.error("argument error: data")
517
452
  return False
518
- result = data_list
453
+ case True if not isTrue(step, int):
454
+ logger.error("argument error: step")
455
+ return False
456
+ case _:
457
+ pass
519
458
 
520
- for item in result:
521
- print(*item, sep=separator)
459
+ # 打印
460
+ for i, v in enumerate(data):
461
+ if i > 0 and i % step == 0:
462
+ print()
463
+ print(v, end=separator)
464
+
465
+ print()
522
466
 
523
467
  return True
524
468
 
525
469
  except Exception as e:
526
- if v_true(debug, bool):
527
- logger.exception(e)
470
+ logger.exception(e)
528
471
  return False
529
472
 
530
473
 
531
474
  def list_remove_list(
532
475
  original: list,
533
- remove: list,
534
- debug: bool = False
476
+ remove: list
535
477
  ) -> list | None:
536
478
  """List remove List"""
537
479
  try:
@@ -539,14 +481,12 @@ def list_remove_list(
539
481
  _remove = deepcopy(remove)
540
482
  return [i for i in _original if i not in _remove]
541
483
  except Exception as e:
542
- if v_true(debug, bool):
543
- logger.exception(e)
484
+ logger.exception(e)
544
485
  return None
545
486
 
546
487
 
547
488
  def list_merge(
548
- data: list,
549
- debug: bool = False
489
+ data: list
550
490
  ) -> list | None:
551
491
  """list merge"""
552
492
  # 合并 List 中的 List 为一个 List
@@ -556,16 +496,14 @@ def list_merge(
556
496
  _results += i
557
497
  return _results
558
498
  except Exception as e:
559
- if v_true(debug, bool):
560
- logger.exception(e)
499
+ logger.exception(e)
561
500
  return None
562
501
 
563
502
 
564
503
  def list_to_file(
565
504
  data: list,
566
505
  file: str,
567
- encoding: str = 'utf-8-sig',
568
- debug: bool = False
506
+ encoding: str = 'utf-8-sig'
569
507
  ) -> bool:
570
508
  """list to file"""
571
509
  try:
@@ -574,8 +512,7 @@ def list_to_file(
574
512
  _file.write(f"{line}\n")
575
513
  return True
576
514
  except Exception as e:
577
- if v_true(debug, bool):
578
- logger.exception(e)
515
+ logger.exception(e)
579
516
  return False
580
517
 
581
518
  def list_to_csvfile(
@@ -583,7 +520,6 @@ def list_to_csvfile(
583
520
  file: str,
584
521
  fields: list | None = None,
585
522
  encoding: str = 'utf-8-sig',
586
- debug: bool = False,
587
523
  **kwargs
588
524
  ) -> bool:
589
525
  """list to csvfile"""
@@ -592,21 +528,19 @@ def list_to_csvfile(
592
528
  # CRLF replaced by LF
593
529
  # https://stackoverflow.com/a/29976091
594
530
  outcsv = csv.writer(_file, lineterminator=os.linesep, **kwargs)
595
- if v_true(fields, list) and fields is not None:
531
+ if fields is not None and isTrue(fields, list):
596
532
  outcsv.writerow(fields)
597
533
  outcsv.writerows(data)
598
534
  return True
599
535
  except Exception as e:
600
- if v_true(debug, bool):
601
- logger.exception(e)
536
+ logger.exception(e)
602
537
  return False
603
538
 
604
539
  def range_zfill(
605
540
  start: int,
606
541
  stop: int,
607
542
  step: int,
608
- width: int,
609
- debug: bool = False
543
+ width: int
610
544
  ) -> list | None:
611
545
  """range zfill"""
612
546
  # 生成长度相同的字符串的列表
@@ -618,8 +552,7 @@ def range_zfill(
618
552
  try:
619
553
  return [str(i).zfill(width) for i in range(start, stop, step)]
620
554
  except Exception as e:
621
- if v_true(debug, bool):
622
- logger.exception(e)
555
+ logger.exception(e)
623
556
  return None
624
557
 
625
558
 
@@ -628,8 +561,7 @@ def range_zfill(
628
561
 
629
562
  def dict_remove_key(
630
563
  data: dict,
631
- key: str,
632
- debug: bool = False
564
+ key: str
633
565
  ) -> dict | None:
634
566
  """dict remove key"""
635
567
  try:
@@ -637,15 +569,13 @@ def dict_remove_key(
637
569
  data_copy.pop(key)
638
570
  return data_copy
639
571
  except Exception as e:
640
- if v_true(debug, bool):
641
- logger.exception(e)
572
+ logger.exception(e)
642
573
  return None
643
574
 
644
575
  def dict_to_file(
645
576
  data: dict,
646
577
  file: str,
647
578
  encoding: str = 'utf-8-sig',
648
- debug: bool = False,
649
579
  **kwargs
650
580
  ) -> bool:
651
581
  """dict to file"""
@@ -654,23 +584,21 @@ def dict_to_file(
654
584
  json.dump(obj=data, fp=_file, indent=4, sort_keys=True, **kwargs)
655
585
  return True
656
586
  except Exception as e:
657
- if v_true(debug, bool):
658
- logger.exception(e)
587
+ logger.exception(e)
659
588
  return False
660
589
 
661
590
 
662
591
  def dict_nested_update(
663
592
  data: dict,
664
593
  key: str,
665
- value: Any,
666
- debug: bool = False
594
+ value: Any
667
595
  ) -> bool:
668
596
  """dict nested update"""
669
597
  # dictionary nested update
670
598
  # https://stackoverflow.com/a/58885744
671
599
  try:
672
600
 
673
- if not v_true(data, dict, debug=debug):
601
+ if not isTrue(data, dict):
674
602
  return False
675
603
 
676
604
  for _k, _v in data.items():
@@ -680,11 +608,11 @@ def dict_nested_update(
680
608
  data[_k] = value()
681
609
  else:
682
610
  data[_k] = value
683
- elif isinstance(_v, dict) is True:
611
+ elif isTrue(_v, dict):
684
612
  dict_nested_update(_v, key, value)
685
- elif isinstance(_v, list) is True:
613
+ elif isTrue(_v, list):
686
614
  for _o in _v:
687
- if isinstance(_o, dict):
615
+ if isTrue(_o, dict):
688
616
  dict_nested_update(_o, key, value)
689
617
  else:
690
618
  pass
@@ -692,8 +620,7 @@ def dict_nested_update(
692
620
  return True
693
621
 
694
622
  except Exception as e:
695
- if v_true(debug, bool):
696
- logger.exception(e)
623
+ logger.exception(e)
697
624
  return False
698
625
 
699
626
 
@@ -702,42 +629,24 @@ def dict_nested_update(
702
629
 
703
630
  def filename(
704
631
  file: str,
705
- split: str = '.',
706
- debug: bool = False
632
+ split: str = '.'
707
633
  ) -> str | None:
708
634
  """filename"""
709
635
  # 获取文件名称
710
636
  # https://stackoverflow.com/questions/678236/how-do-i-get-the-filename-without-the-extension-from-a-path-in-python
711
637
  # https://stackoverflow.com/questions/4152963/get-name-of-current-script-in-python
712
638
  try:
713
-
714
- if v_true(debug, bool):
715
- logger.info(f"file: {file}")
716
- logger.info(f"split: {split}")
717
-
718
639
  _basename = str(os.path.basename(file))
719
-
720
- if v_true(debug, bool):
721
- logger.info(f"basename: {_basename}")
722
-
723
640
  _index_of_split = _basename.index(split)
724
-
725
- if v_true(debug, bool):
726
- logger.info(f"index of split: {_index_of_split}")
727
- logger.info(f"filename: {_basename[:_index_of_split]}")
728
-
729
641
  return _basename[:_index_of_split]
730
-
731
642
  except Exception as e:
732
- if v_true(debug, bool):
733
- logger.exception(e)
643
+ logger.exception(e)
734
644
  return None
735
645
 
736
646
 
737
647
  def filehash(
738
648
  file: str,
739
- sha: str = 'md5',
740
- debug: bool = False
649
+ sha: str = 'md5'
741
650
  ) -> str | None:
742
651
  """filehash"""
743
652
  # 获取文件Hash
@@ -778,22 +687,19 @@ def filehash(
778
687
  file_hash.update(chunk)
779
688
  return file_hash.hexdigest()
780
689
  except Exception as e:
781
- if v_true(debug, bool):
782
- logger.exception(e)
690
+ logger.exception(e)
783
691
  return None
784
692
 
785
693
 
786
694
  def filesize(
787
- file: str,
788
- debug: bool = False
695
+ file: str
789
696
  ) -> int | None:
790
697
  """filesize"""
791
698
  # 获取文件大小
792
699
  try:
793
700
  return os.path.getsize(file)
794
701
  except Exception as e:
795
- if v_true(debug, bool):
796
- logger.exception(e)
702
+ logger.exception(e)
797
703
  return None
798
704
 
799
705
 
@@ -813,61 +719,52 @@ def filesize(
813
719
  # ) -> str | None:
814
720
  # """获取父目录名称"""
815
721
  # try:
816
- # return str(Path(path, **kwargs).parent.resolve()) if v_true(path, str, debug=debug) else None
722
+ # return str(Path(path, **kwargs).parent.resolve()) if isTrue(path, str, debug=debug) else None
817
723
  # except Exception as e:
818
- # if v_true(debug, bool):
724
+ # if isTrue(debug, bool):
819
725
  # logger.exception(e)
820
726
  # return None
821
727
 
822
728
 
823
729
  def realpath(
824
730
  path: str,
825
- debug: bool = False,
826
731
  **kwargs
827
732
  ) -> str | None:
828
733
  """获取对象真实路径"""
829
734
  try:
830
- # if v_true(debug, bool):
831
- # logger.info(f"path: {path}")
832
- # return os.path.realpath(path, **kwargs)
833
- if v_true(path, str, debug=debug) is False:
735
+ if not isTrue(path, str):
834
736
  return None
835
737
  return str(Path(path, **kwargs).resolve())
836
738
  except Exception as e:
837
- if v_true(debug, bool):
838
- logger.exception(e)
739
+ logger.exception(e)
839
740
  return None
840
741
 
841
742
 
842
743
  def current_dir(
843
744
  path: str,
844
- debug: bool = False,
845
745
  **kwargs
846
746
  ) -> str | None:
847
747
  """获取对象所在目录"""
848
748
  try:
849
- if v_true(path, str, debug=debug) is False:
749
+ if not isTrue(path, str):
850
750
  return None
851
751
  return str(Path(path, **kwargs).parent.resolve())
852
752
  except Exception as e:
853
- if v_true(debug, bool):
854
- logger.exception(e)
753
+ logger.exception(e)
855
754
  return None
856
755
 
857
756
 
858
757
  def parent_dir(
859
758
  path: str,
860
- debug: bool = False,
861
759
  **kwargs
862
760
  ) -> str | None:
863
761
  """获取对象所在目录的父目录"""
864
762
  try:
865
- if v_true(path, str, debug=debug) is False:
763
+ if not isTrue(path, str):
866
764
  return None
867
765
  return str(Path(path, **kwargs).parent.parent.resolve())
868
766
  except Exception as e:
869
- if v_true(debug, bool):
870
- logger.exception(e)
767
+ logger.exception(e)
871
768
  return None
872
769
 
873
770
 
@@ -877,7 +774,6 @@ def parent_dir(
877
774
  def retry(
878
775
  times: int,
879
776
  func: Callable,
880
- debug: bool = False,
881
777
  **kwargs
882
778
  ):
883
779
  """重试"""
@@ -895,14 +791,11 @@ def retry(
895
791
  try:
896
792
  return func(**kwargs)
897
793
  except Exception as e:
898
- if v_true(debug, bool):
899
- logger.exception(e)
900
- logger.success('retrying ...')
794
+ logger.exception(e)
795
+ logger.info('retrying ...')
901
796
  continue
902
- # break
903
797
  except Exception as e:
904
- if v_true(debug, bool):
905
- logger.exception(e)
798
+ logger.exception(e)
906
799
 
907
800
 
908
801
  # --------------------------------------------------------------------------------------------------
@@ -952,30 +845,26 @@ def retry(
952
845
 
953
846
 
954
847
  def date_to_datetime(
955
- date_object: datetime.datetime,
956
- debug: bool = False
848
+ date_object: datetime.datetime
957
849
  ) -> datetime.datetime | None:
958
850
  """'日期'转换为'日期时间'"""
959
851
  # https://stackoverflow.com/a/1937636
960
852
  try:
961
853
  return datetime.datetime.combine(date_object, datetime.datetime.min.time())
962
854
  except Exception as e:
963
- if v_true(debug, bool):
964
- logger.exception(e)
855
+ logger.exception(e)
965
856
  return None
966
857
 
967
858
 
968
859
  def datetime_to_date(
969
- datetime_instance: datetime.datetime,
970
- debug: bool = False
860
+ datetime_instance: datetime.datetime
971
861
  ) -> datetime.date | None:
972
862
  """'日期时间'转换为'日期'"""
973
863
  # https://stackoverflow.com/a/3743240
974
864
  try:
975
865
  return datetime_instance.date()
976
866
  except Exception as e:
977
- if v_true(debug, bool):
978
- logger.exception(e)
867
+ logger.exception(e)
979
868
  return None
980
869
 
981
870
 
@@ -984,25 +873,20 @@ def local_timezone():
984
873
  return datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
985
874
 
986
875
 
987
- def datetime_now(
988
- debug: bool = False,
989
- **kwargs
990
- ) -> datetime.datetime | None:
876
+ def datetime_now(**kwargs) -> datetime.datetime | None:
991
877
  """获取当前日期和时间"""
992
- _utc = kwargs.pop("utc", False)
878
+ utc = kwargs.pop("utc", False)
993
879
  try:
994
- if _utc is True:
880
+ if isTrue(utc, bool):
995
881
  return datetime.datetime.now(datetime.timezone.utc)
996
882
  return datetime.datetime.now(**kwargs)
997
883
  except Exception as e:
998
- if v_true(debug, bool):
999
- logger.exception(e)
884
+ logger.exception(e)
1000
885
  return None
1001
886
 
1002
887
 
1003
888
  def datetime_offset(
1004
889
  datetime_instance: datetime.datetime | None = None,
1005
- debug: bool = False,
1006
890
  **kwargs
1007
891
  ) -> datetime.datetime | None:
1008
892
  """
@@ -1021,29 +905,27 @@ def datetime_offset(
1021
905
  return datetime.datetime.now() + datetime.timedelta(**kwargs)
1022
906
 
1023
907
  except Exception as e:
1024
- if v_true(debug, bool):
1025
- logger.exception(e)
908
+ logger.exception(e)
1026
909
  return None
1027
910
 
1028
911
 
1029
912
  def datetime_to_string(
1030
913
  datetime_instance: datetime.datetime,
1031
- string_format: str = '%Y-%m-%d %H:%M:%S',
1032
- debug: bool = False
914
+ string_format: str = '%Y-%m-%d %H:%M:%S'
1033
915
  ) -> str | None:
1034
916
  """'日期时间'转换为'字符串'"""
1035
917
  try:
1036
- return datetime.datetime.strftime(datetime_instance, string_format) if isinstance(datetime_instance, datetime.datetime) is True else None
918
+ if not isTrue(datetime_instance, datetime.datetime):
919
+ return None
920
+ return datetime.datetime.strftime(datetime_instance, string_format)
1037
921
  except Exception as e:
1038
- if v_true(debug, bool):
1039
- logger.exception(e)
922
+ logger.exception(e)
1040
923
  return None
1041
924
 
1042
925
 
1043
926
  def datetime_to_timestamp(
1044
927
  datetime_instance: datetime.datetime,
1045
- utc: bool = False,
1046
- debug: bool = False
928
+ utc: bool = False
1047
929
  ) -> int | None:
1048
930
  """
1049
931
  Datatime 转换为 Unix Timestamp
@@ -1051,100 +933,93 @@ def datetime_to_timestamp(
1051
933
  UTC datetime 需要先替换 timezone 再转换为 Unix Timestamp
1052
934
  """
1053
935
  try:
1054
- if isinstance(datetime_instance, datetime.datetime):
1055
- return int(datetime_instance.replace(tzinfo=datetime.timezone.utc).timestamp()) if utc is True else int(datetime_instance.timestamp())
1056
- return None
936
+ if not isTrue(datetime_instance, datetime.datetime):
937
+ return None
938
+ return int(datetime_instance.replace(tzinfo=datetime.timezone.utc).timestamp()) if utc is True else int(datetime_instance.timestamp())
1057
939
  except Exception as e:
1058
- if v_true(debug, bool):
1059
- logger.exception(e)
940
+ logger.exception(e)
1060
941
  return None
1061
942
 
1062
943
 
1063
944
  def datetime_local_to_timezone(
1064
945
  datetime_instance: datetime.datetime,
1065
- tz: datetime.timezone = datetime.timezone.utc,
1066
- debug: bool = False
946
+ tz: datetime.timezone = datetime.timezone.utc
1067
947
  ) -> datetime.datetime | None:
1068
948
  """
1069
949
  Local datetime to TimeZone datetime (默认转换为 UTC datetime)
1070
950
  replace(tzinfo=None) 移除结尾的时区信息
1071
951
  """
1072
952
  try:
1073
- if isinstance(datetime_instance, datetime.datetime) is True:
1074
- return (datetime.datetime.fromtimestamp(datetime_instance.timestamp(), tz=tz)).replace(tzinfo=None)
1075
- else:
953
+ if not isTrue(datetime_instance, datetime.datetime):
1076
954
  return None
955
+ return (datetime.datetime.fromtimestamp(datetime_instance.timestamp(), tz=tz)).replace(tzinfo=None)
1077
956
  except Exception as e:
1078
- if v_true(debug, bool):
1079
- logger.exception(e)
957
+ logger.exception(e)
1080
958
  return None
1081
959
 
1082
960
 
1083
961
  def datetime_utc_to_timezone(
1084
962
  datetime_instance: datetime.datetime,
1085
- tz: Any = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo,
1086
- debug: bool = False
963
+ tz: Any = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
1087
964
  ) -> datetime.datetime | None:
1088
965
  """
1089
966
  UTC datetime to TimeZone datetime (默认转换为 Local datetime)
1090
967
  replace(tzinfo=None) 移除结尾的时区信息
1091
968
  """
1092
969
  try:
1093
- if isinstance(datetime_instance, datetime.datetime) is True:
1094
- return datetime_instance.replace(tzinfo=datetime.timezone.utc).astimezone(tz).replace(tzinfo=None)
1095
- else:
970
+ if not isTrue(datetime_instance, datetime.datetime):
1096
971
  return None
972
+ return datetime_instance.replace(tzinfo=datetime.timezone.utc).astimezone(tz).replace(tzinfo=None)
973
+
1097
974
  except Exception as e:
1098
- if v_true(debug, bool):
1099
- logger.exception(e)
975
+ logger.exception(e)
1100
976
  return None
1101
977
 
1102
978
 
1103
979
  def timestamp_to_datetime(
1104
980
  timestamp: int,
1105
- tz: datetime.timezone = datetime.timezone.utc,
1106
- debug: bool = False
981
+ tz: datetime.timezone = datetime.timezone.utc
1107
982
  ) -> datetime.datetime | None:
1108
983
  """Unix Timestamp 转换为 Datatime"""
1109
984
  try:
1110
- return (datetime.datetime.fromtimestamp(timestamp, tz=tz)).replace(tzinfo=None) if v_true(timestamp, int, debug=debug) else None
985
+ if not isTrue(timestamp, int):
986
+ return None
987
+ return (datetime.datetime.fromtimestamp(timestamp, tz=tz)).replace(tzinfo=None)
1111
988
  except Exception as e:
1112
- if v_true(debug, bool):
1113
- logger.exception(e)
989
+ logger.exception(e)
1114
990
  return None
1115
991
 
1116
992
 
1117
993
  def datetime_string_to_datetime(
1118
994
  datetime_string: str,
1119
- datetime_format: str = '%Y-%m-%d %H:%M:%S',
1120
- debug: bool = False
995
+ datetime_format: str = '%Y-%m-%d %H:%M:%S'
1121
996
  ) -> datetime.datetime | None:
1122
997
  """datetime string to datetime"""
1123
998
  try:
1124
- return datetime.datetime.strptime(datetime_string, datetime_format) if v_true(datetime_string, str, debug=debug) else None
999
+ if not isTrue(datetime_string, str):
1000
+ return None
1001
+ return datetime.datetime.strptime(datetime_string, datetime_format)
1125
1002
  except Exception as e:
1126
- if v_true(debug, bool):
1127
- logger.exception(e)
1003
+ logger.exception(e)
1128
1004
  return None
1129
1005
 
1130
1006
 
1131
1007
  def datetime_string_to_timestamp(
1132
1008
  datetime_string: str,
1133
- datetime_format: str = '%Y-%m-%d %H:%M:%S',
1134
- debug: bool = False
1009
+ datetime_format: str = '%Y-%m-%d %H:%M:%S'
1135
1010
  ) -> int | None:
1136
1011
  """datetime string to timestamp"""
1137
1012
  try:
1138
- return int(time.mktime(time.strptime(datetime_string, datetime_format))) if v_true(datetime_string, str, debug=debug) else None
1013
+ if not isTrue(datetime_string, str):
1014
+ return None
1015
+ return int(time.mktime(time.strptime(datetime_string, datetime_format)))
1139
1016
  except Exception as e:
1140
- if v_true(debug, bool):
1141
- logger.exception(e)
1017
+ logger.exception(e)
1142
1018
  return None
1143
1019
 
1144
1020
 
1145
1021
  def datetime_object(
1146
- date_time: datetime.datetime,
1147
- debug: bool = False
1022
+ date_time: datetime.datetime
1148
1023
  ) -> dict | None:
1149
1024
  """datetime object"""
1150
1025
  try:
@@ -1157,8 +1032,7 @@ def datetime_object(
1157
1032
  'datetime_zero': date_time.strftime('%Y-%m-%d 00:00:00')
1158
1033
  }
1159
1034
  except Exception as e:
1160
- if v_true(debug, bool):
1161
- logger.exception(e)
1035
+ logger.exception(e)
1162
1036
  return None
1163
1037
 
1164
1038
 
@@ -1188,15 +1062,14 @@ def shell(
1188
1062
  isfile: bool = False,
1189
1063
  sh_shell: str = '/bin/bash',
1190
1064
  sh_option: str | None = None,
1191
- debug: bool = False,
1192
1065
  **kwargs
1193
1066
  ) -> subprocess.CompletedProcess | None:
1194
1067
  """run shell command or script"""
1195
1068
  try:
1196
1069
  match True:
1197
- case True if not check_file_type(sh_shell, 'file', debug=debug):
1070
+ case True if not check_file_type(sh_shell, 'file'):
1198
1071
  return None
1199
- case True if v_true(sh_shell, str, debug=debug) and v_true(command, str, debug=debug):
1072
+ case True if isTrue(sh_shell, str) and isTrue(command, str):
1200
1073
  if isfile is True:
1201
1074
  if sh_option is None:
1202
1075
  return subprocess.run([sh_shell, command], **kwargs, check=False)
@@ -1207,8 +1080,7 @@ def shell(
1207
1080
  case _:
1208
1081
  return None
1209
1082
  except Exception as e:
1210
- if v_true(debug, bool):
1211
- logger.exception(e)
1083
+ logger.exception(e)
1212
1084
  return None
1213
1085
 
1214
1086
 
@@ -1216,21 +1088,18 @@ def shell(
1216
1088
 
1217
1089
 
1218
1090
  def json_file_parser(
1219
- file: str,
1220
- debug: bool = False
1091
+ file: str
1221
1092
  ) -> dict | None:
1222
1093
  """JSON File Parser"""
1223
1094
  try:
1224
- if check_file_type(file, 'file', debug=debug):
1225
- with open(file, encoding="utf-8") as json_raw:
1226
- json_dict = json.load(json_raw)
1227
- return json_dict
1228
- if v_true(debug, bool):
1229
- logger.error(f"No such file: {file}")
1230
- return None
1095
+ if not check_file_type(file, 'file'):
1096
+ logger.error(f"no such file: {file}")
1097
+ return None
1098
+ with open(file, encoding="utf-8") as json_raw:
1099
+ json_dict = json.load(json_raw)
1100
+ return json_dict
1231
1101
  except Exception as e:
1232
- if v_true(debug, bool):
1233
- logger.exception(e)
1102
+ logger.exception(e)
1234
1103
  return None
1235
1104
 
1236
1105
  # json_raw = '''
@@ -1254,15 +1123,15 @@ def json_file_parser(
1254
1123
 
1255
1124
  def json_sort(
1256
1125
  string: str,
1257
- debug: bool = False,
1258
1126
  **kwargs
1259
1127
  ) -> str | None:
1260
1128
  """JSON Sort"""
1261
1129
  try:
1262
- return json.dumps(json.loads(string), indent=4, sort_keys=True, **kwargs) if v_true(string, str, debug=debug) else None
1130
+ if not isTrue(string, str):
1131
+ return None
1132
+ return json.dumps(json.loads(string), indent=4, sort_keys=True, **kwargs)
1263
1133
  except Exception as e:
1264
- if v_true(debug, bool):
1265
- logger.exception(e)
1134
+ logger.exception(e)
1266
1135
  return None
1267
1136
 
1268
1137
 
@@ -1270,48 +1139,39 @@ def json_sort(
1270
1139
 
1271
1140
 
1272
1141
  def delete_files(
1273
- files: Union[str, List],
1274
- debug: bool = False
1142
+ files: Union[str, List]
1275
1143
  ) -> bool:
1276
1144
  """删除文件"""
1277
1145
  try:
1278
1146
 
1279
- if isinstance(files, str) and check_file_type(files, 'file', debug=debug):
1280
-
1147
+ if isinstance(files, str) and check_file_type(files, 'file'):
1281
1148
  os.remove(files)
1282
- if v_true(debug, bool):
1283
- logger.success(f'deleted file: {files}')
1149
+ logger.success(f'deleted file: {files}')
1284
1150
  return True
1285
1151
 
1286
- if v_true(files, list, debug=debug):
1287
-
1288
- for _file in files:
1289
-
1290
- if v_true(_file, str, debug=debug) and check_file_type(_file, 'file', debug=debug):
1291
- try:
1292
- os.remove(_file)
1293
- logger.success(f'deleted file: {_file}')
1294
- except Exception as e:
1295
- logger.error(f'error file: {_file} {e}')
1296
- else:
1297
- logger.error(f'error file: {_file}')
1152
+ if not isTrue(files, list):
1153
+ return False
1298
1154
 
1299
- return True
1155
+ for _file in files:
1300
1156
 
1301
- if v_true(debug, bool):
1302
- logger.error(f'error file: {files}')
1157
+ if isinstance(_file, str) and check_file_type(_file, 'file'):
1158
+ try:
1159
+ os.remove(_file)
1160
+ logger.success(f'deleted file: {_file}')
1161
+ except Exception as e:
1162
+ logger.error(f'error file: {_file} {e}')
1163
+ else:
1164
+ logger.error(f'error file: {_file}')
1303
1165
 
1304
- return False
1166
+ return True
1305
1167
 
1306
1168
  except Exception as e:
1307
- if v_true(debug, bool):
1308
- logger.exception(e)
1169
+ logger.exception(e)
1309
1170
  return False
1310
1171
 
1311
1172
 
1312
1173
  def delete_directory(
1313
- directory: Union[str, List],
1314
- debug: bool = False
1174
+ directory: Union[str, List]
1315
1175
  ) -> bool:
1316
1176
  """
1317
1177
  delete directory
@@ -1338,41 +1198,30 @@ def delete_directory(
1338
1198
  """
1339
1199
  try:
1340
1200
 
1341
- if isinstance(directory, str) and check_file_type(directory, 'dir', debug=debug):
1342
-
1201
+ if isinstance(directory, str) and check_file_type(directory, 'dir'):
1343
1202
  rmtree(directory)
1344
-
1345
- if v_true(debug, bool):
1346
- logger.success(f'deleted directory: {directory}')
1347
-
1203
+ logger.success(f'deleted directory: {directory}')
1348
1204
  return True
1349
1205
 
1350
- elif v_true(directory, list, debug=debug):
1351
-
1352
- for _dir in directory:
1206
+ if not isTrue(directory, list):
1207
+ logger.error(f'error directory: {directory}')
1208
+ return False
1353
1209
 
1354
- if v_true(_dir, str, debug=debug) and check_file_type(_dir, 'dir', debug=debug):
1355
- try:
1356
- rmtree(_dir)
1357
- if v_true(debug, bool):
1358
- logger.success(f'deleted directory: {_dir}')
1359
- except Exception as e:
1360
- if v_true(debug, bool):
1361
- logger.error(f'error directory: {_dir} {e}')
1362
- else:
1363
- if v_true(debug, bool):
1364
- logger.error(f'error directory: {_dir}')
1210
+ for _dir in directory:
1365
1211
 
1366
- return True
1212
+ if isTrue(_dir, str) and check_file_type(_dir, 'dir'):
1213
+ try:
1214
+ rmtree(_dir)
1215
+ logger.success(f'deleted directory: {_dir}')
1216
+ except Exception as e:
1217
+ logger.error(f'error directory: {_dir} {e}')
1218
+ else:
1219
+ logger.error(f'error directory: {_dir}')
1367
1220
 
1368
- else:
1369
- if v_true(debug, bool):
1370
- logger.error(f'error directory: {directory}')
1371
- return False
1221
+ return True
1372
1222
 
1373
1223
  except Exception as e:
1374
- if v_true(debug, bool):
1375
- logger.exception(e)
1224
+ logger.exception(e)
1376
1225
  return False
1377
1226
 
1378
1227
 
@@ -1384,7 +1233,6 @@ def process_pool(
1384
1233
  process_data: Any = None,
1385
1234
  process_num: int = 2,
1386
1235
  thread: bool = False,
1387
- debug: bool = False,
1388
1236
  **kwargs
1389
1237
  ) -> list | bool:
1390
1238
  """
@@ -1397,37 +1245,29 @@ def process_pool(
1397
1245
  try:
1398
1246
 
1399
1247
  # 处理数据
1400
- if v_true(debug, bool):
1401
- logger.info("data split ......")
1402
1248
  if len(process_data) <= process_num:
1403
1249
  process_num = len(process_data)
1404
1250
  _data = process_data
1405
1251
  else:
1406
- _data = list_split(process_data, process_num, equally=True, debug=debug)
1252
+ _data = list_split(process_data, process_num, equally=True)
1407
1253
 
1408
1254
  if _data is None:
1409
1255
  return False
1410
1256
 
1411
- if v_true(debug, bool):
1412
- logger.info(f"data: {_data}")
1413
-
1414
1257
  # 执行函数
1415
- if v_true(thread, bool):
1258
+ if isTrue(thread, bool):
1416
1259
  # 多线程
1417
- if v_true(debug, bool):
1418
- logger.info("execute multi thread ......")
1260
+ logger.info("execute multi thread ......")
1419
1261
  with ThreadPool(process_num, **kwargs) as p:
1420
1262
  return p.map(process_func, _data)
1421
1263
  else:
1422
1264
  # 多进程
1423
- if v_true(debug, bool):
1424
- logger.info("execute multi process ......")
1265
+ logger.info("execute multi process ......")
1425
1266
  with Pool(process_num, **kwargs) as p:
1426
1267
  return p.map(process_func, _data)
1427
1268
 
1428
1269
  except Exception as e:
1429
- if v_true(debug, bool):
1430
- logger.exception(e)
1270
+ logger.exception(e)
1431
1271
  return False
1432
1272
 
1433
1273
 
@@ -1436,12 +1276,11 @@ def new_process(
1436
1276
  process_data: Any = None,
1437
1277
  thread: bool = False,
1438
1278
  daemon: bool = True,
1439
- debug: bool = False,
1440
1279
  **kwargs
1441
1280
  ) -> Thread | Process | bool:
1442
1281
  """New Process"""
1443
1282
  try:
1444
- if v_true(thread, bool):
1283
+ if isTrue(thread, bool):
1445
1284
  process = Thread(target=process_func, args=process_data, **kwargs)
1446
1285
  else:
1447
1286
  process = Process(target=process_func, args=process_data, **kwargs)
@@ -1449,8 +1288,7 @@ def new_process(
1449
1288
  process.start()
1450
1289
  return process
1451
1290
  except Exception as e:
1452
- if v_true(debug, bool):
1453
- logger.exception(e)
1291
+ logger.exception(e)
1454
1292
  return False
1455
1293
 
1456
1294
 
@@ -1458,28 +1296,22 @@ def new_process(
1458
1296
 
1459
1297
 
1460
1298
  def create_empty_file(
1461
- file: str | None = None,
1462
- debug: bool = False
1299
+ file: str | None = None
1463
1300
  ) -> str | None:
1464
1301
  """create empty file"""
1465
1302
  try:
1466
1303
  if file is None:
1467
1304
  # 当前时间戳(纳秒)
1468
1305
  timestamp = time.time_ns()
1469
- if v_true(debug, bool):
1470
- logger.info(f"timestamp: {timestamp}")
1471
1306
  # 空文件路径
1472
- file = f'/tmp/empty_file_{timestamp}.txt'
1307
+ file = f'/tmp/none_{timestamp}.txt'
1473
1308
  # 创建一个空文件
1474
- if v_true(debug, bool):
1475
- logger.info(f"file: {file}")
1476
1309
  # pylint: disable=R1732
1477
1310
  open(file, "w", encoding="utf-8").close()
1478
1311
  # 返回文件路径
1479
1312
  return file
1480
1313
  except Exception as e:
1481
- if v_true(debug, bool):
1482
- logger.exception(e)
1314
+ logger.exception(e)
1483
1315
  return None
1484
1316
 
1485
1317
 
@@ -1492,8 +1324,7 @@ def uuid4_hex() -> str:
1492
1324
 
1493
1325
 
1494
1326
  def increment_version(
1495
- version: str,
1496
- debug: bool = False
1327
+ version: str
1497
1328
  ) -> str | None:
1498
1329
  """版本号递增"""
1499
1330
  try:
@@ -1501,8 +1332,7 @@ def increment_version(
1501
1332
  version_numbers[-1] = str(int(version_numbers[-1]) + 1)
1502
1333
  return '.'.join(version_numbers)
1503
1334
  except Exception as e:
1504
- if v_true(debug, bool):
1505
- logger.exception(e)
1335
+ logger.exception(e)
1506
1336
  return None
1507
1337
 
1508
1338
 
@@ -1518,37 +1348,28 @@ def make_directory(
1518
1348
  os.makedirs(directory)
1519
1349
  return True
1520
1350
  except Exception as e:
1521
- if v_true(debug, bool):
1522
- logger.exception(e)
1351
+ logger.exception(e)
1523
1352
  return False
1524
1353
 
1525
1354
  def change_directory(
1526
- directory: str,
1527
- debug: bool = False
1355
+ directory: str
1528
1356
  ) -> bool:
1529
1357
  """改变目录"""
1530
1358
  try:
1531
1359
 
1532
- if not v_true(directory, str, debug=debug):
1360
+ if not isTrue(directory, str):
1533
1361
  return False
1534
1362
 
1535
- if v_true(debug, bool):
1536
- logger.info(f"directory: {directory}")
1537
-
1538
- if check_file_type(directory, 'dir', debug=debug):
1539
- if v_true(debug, bool):
1540
- logger.info(f"change directory to {directory}")
1541
- os.chdir(directory)
1542
- return True
1543
-
1544
- if v_true(debug, bool):
1363
+ if not check_file_type(directory, 'dir'):
1545
1364
  logger.error(f"no such directory: {directory}")
1365
+ return False
1546
1366
 
1547
- return False
1367
+ os.chdir(directory)
1368
+
1369
+ return True
1548
1370
 
1549
1371
  except Exception as e:
1550
- if v_true(debug, bool):
1551
- logger.exception(e)
1372
+ logger.exception(e)
1552
1373
  return False
1553
1374
 
1554
1375
 
@@ -1556,23 +1377,19 @@ def change_directory(
1556
1377
 
1557
1378
 
1558
1379
  def load_toml_file(
1559
- file: str,
1560
- debug: bool = False
1380
+ file: str
1561
1381
  ) -> dict | None:
1562
1382
  """Load TOML file"""
1563
1383
  info = '解析配置文件'
1564
1384
  try:
1565
- if v_true(debug, bool):
1566
- logger.info(f'{info}[执行]')
1385
+ logger.info(f'{info}[执行]')
1567
1386
  with open(file, "rb") as _file:
1568
1387
  config = tomllib.load(_file)
1569
- if v_true(debug, bool):
1570
- logger.success(f'{info}[成功]')
1388
+ logger.success(f'{info}[成功]')
1571
1389
  return config
1572
1390
  except Exception as e:
1573
- if v_true(debug, bool):
1574
- logger.error(f'{info}[失败]')
1575
- logger.exception(e)
1391
+ logger.error(f'{info}[失败]')
1392
+ logger.exception(e)
1576
1393
  return None
1577
1394
 
1578
1395
 
@@ -1581,35 +1398,33 @@ def git_clone(
1581
1398
  local_repository: str,
1582
1399
  timeout: int = 30,
1583
1400
  delete: bool = False,
1584
- log_prefix: str = '',
1585
- debug: bool = False,
1401
+ log_prefix: str = ''
1586
1402
  ) -> bool:
1587
1403
  """GIT Clone"""
1588
- try:
1589
1404
 
1590
- # 日志前缀
1591
- log_prefix = f'{log_prefix}[GitClone]'
1405
+ # 日志前缀
1406
+ log_prefix = f'{log_prefix} [GitClone]'
1407
+
1408
+ try:
1592
1409
 
1593
1410
  # 获取应用程序Git仓库
1594
- if v_true(debug, bool):
1595
- logger.info(f'{log_prefix}process the request')
1596
- logger.info(f'{log_prefix}git repository: {git_repository}')
1597
- logger.info(f'{log_prefix}local repository: {local_repository}')
1411
+ # logger.info(f'{log_prefix}process the request')
1412
+ # logger.info(f'{log_prefix}git repository: {git_repository}')
1413
+ # logger.info(f'{log_prefix}local repository: {local_repository}')
1598
1414
 
1599
1415
  # 删除本地仓库
1600
- if v_true(delete, bool):
1601
- delete_directory(local_repository, debug=debug)
1416
+ if isTrue(delete, bool):
1417
+ delete_directory(local_repository)
1602
1418
  time.sleep(1)
1603
1419
 
1604
1420
  # from shutil import which
1605
- # logger.info(which('timeout')) if v_true(debug, bool) else next
1421
+ # logger.info(which('timeout')) if isTrue(debug, bool) else next
1606
1422
  # if which('timeout') != None:
1607
1423
  # command = f'timeout -s 9 {timeout} git clone {git_repository} {local_repository}'
1608
1424
 
1609
1425
  # 克隆仓库
1610
1426
  result = shell(
1611
1427
  command=f'timeout -s 9 {timeout} git clone {git_repository} {local_repository}',
1612
- debug=debug,
1613
1428
  universal_newlines=True,
1614
1429
  stdout=subprocess.PIPE,
1615
1430
  stderr=subprocess.STDOUT
@@ -1621,42 +1436,34 @@ def git_clone(
1621
1436
  result_code: int = result.returncode
1622
1437
  result_info = result.stdout.splitlines()
1623
1438
 
1624
- if v_true(debug, bool):
1625
- logger.error(f'{log_prefix}unsuccessful')
1439
+ if result_code != 0:
1626
1440
  for i in result_info:
1627
1441
  logger.error(f'{log_prefix}{i}')
1442
+ return False
1628
1443
 
1629
- if result_code == 0:
1630
- return True
1631
-
1632
- return False
1444
+ return True
1633
1445
 
1634
1446
  except Exception as e:
1635
- if v_true(debug, bool):
1636
- logger.error(f'{log_prefix}unsuccessful')
1637
- logger.exception(e)
1447
+ logger.error(f'{log_prefix} [failure]')
1448
+ logger.exception(e)
1638
1449
  return False
1639
1450
 
1640
1451
 
1641
1452
  def url_parse(
1642
1453
  url: str,
1643
- scheme: str = 'http',
1644
- debug: bool = False
1454
+ scheme: str = 'http'
1645
1455
  ) -> ParseResult:
1646
1456
  """URL Parse"""
1647
1457
  none_result = ParseResult(scheme='', netloc='', path='', params='', query='', fragment='')
1648
1458
  try:
1649
- if v_true(debug, bool):
1650
- logger.info(f'url: {url}')
1651
1459
  # 如果没有 scheme 的话, 字符串是不解析的. 所以, 如果没有 scheme, 就添加一个 scheme, 默认添加 http
1652
- if v_true(url, str) and (url.find('://') == -1) and v_true(scheme, str):
1460
+ if isTrue(url, str) and (url.find('://') == -1) and isTrue(scheme, str):
1653
1461
  url = f'{scheme}://{url}'
1654
- if v_true(url, str):
1462
+ if isTrue(url, str):
1655
1463
  return urlparse(url)
1656
1464
  return none_result
1657
1465
  except Exception as e:
1658
- if v_true(debug, bool):
1659
- logger.exception(e)
1466
+ logger.exception(e)
1660
1467
  return none_result
1661
1468
 
1662
1469
  # def debug_log(
@@ -1666,15 +1473,15 @@ def url_parse(
1666
1473
  # error: bool = False
1667
1474
  # ):
1668
1475
  # """debug log"""
1669
- # if v_true(log, str) and v_true(debug, bool):
1670
- # if v_true(error, bool):
1476
+ # if isTrue(log, str) and isTrue(debug, bool):
1477
+ # if isTrue(error, bool):
1671
1478
  # logger.error(log)
1672
1479
  # else:
1673
1480
  # logger.info(log)
1674
1481
  # return
1675
1482
 
1676
- # if v_true(exception, Exception):
1677
- # if v_true(debug, bool):
1483
+ # if isTrue(exception, Exception):
1484
+ # if isTrue(debug, bool):
1678
1485
  # logger.exception(exception)
1679
1486
  # else:
1680
1487
  # logger.error(exception)