ezKit 1.8.8__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:
373
+ if isTrue(equally, bool):
450
374
 
451
- _step_number = step_number_for_split_equally(_data_length, number, debug=debug)
452
-
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,8 +402,7 @@ 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
 
@@ -510,7 +422,7 @@ def list_print_by_step(
510
422
  # result.append(data)
511
423
  # else:
512
424
  # data_list = list_split(data, step, debug=debug)
513
- # if data_list is None or v_true(data_list, list) is False:
425
+ # if data_list is None or isTrue(data_list, list) is False:
514
426
  # return False
515
427
  # result = data_list
516
428
 
@@ -535,10 +447,10 @@ def list_print_by_step(
535
447
 
536
448
  # 判断参数数据
537
449
  match True:
538
- case True if v_true(data, list) is False:
450
+ case True if not isTrue(data, list):
539
451
  logger.error("argument error: data")
540
452
  return False
541
- case True if v_true(step, int) is False:
453
+ case True if not isTrue(step, int):
542
454
  logger.error("argument error: step")
543
455
  return False
544
456
  case _:
@@ -561,8 +473,7 @@ def list_print_by_step(
561
473
 
562
474
  def list_remove_list(
563
475
  original: list,
564
- remove: list,
565
- debug: bool = False
476
+ remove: list
566
477
  ) -> list | None:
567
478
  """List remove List"""
568
479
  try:
@@ -570,14 +481,12 @@ def list_remove_list(
570
481
  _remove = deepcopy(remove)
571
482
  return [i for i in _original if i not in _remove]
572
483
  except Exception as e:
573
- if v_true(debug, bool):
574
- logger.exception(e)
484
+ logger.exception(e)
575
485
  return None
576
486
 
577
487
 
578
488
  def list_merge(
579
- data: list,
580
- debug: bool = False
489
+ data: list
581
490
  ) -> list | None:
582
491
  """list merge"""
583
492
  # 合并 List 中的 List 为一个 List
@@ -587,16 +496,14 @@ def list_merge(
587
496
  _results += i
588
497
  return _results
589
498
  except Exception as e:
590
- if v_true(debug, bool):
591
- logger.exception(e)
499
+ logger.exception(e)
592
500
  return None
593
501
 
594
502
 
595
503
  def list_to_file(
596
504
  data: list,
597
505
  file: str,
598
- encoding: str = 'utf-8-sig',
599
- debug: bool = False
506
+ encoding: str = 'utf-8-sig'
600
507
  ) -> bool:
601
508
  """list to file"""
602
509
  try:
@@ -605,8 +512,7 @@ def list_to_file(
605
512
  _file.write(f"{line}\n")
606
513
  return True
607
514
  except Exception as e:
608
- if v_true(debug, bool):
609
- logger.exception(e)
515
+ logger.exception(e)
610
516
  return False
611
517
 
612
518
  def list_to_csvfile(
@@ -614,7 +520,6 @@ def list_to_csvfile(
614
520
  file: str,
615
521
  fields: list | None = None,
616
522
  encoding: str = 'utf-8-sig',
617
- debug: bool = False,
618
523
  **kwargs
619
524
  ) -> bool:
620
525
  """list to csvfile"""
@@ -623,21 +528,19 @@ def list_to_csvfile(
623
528
  # CRLF replaced by LF
624
529
  # https://stackoverflow.com/a/29976091
625
530
  outcsv = csv.writer(_file, lineterminator=os.linesep, **kwargs)
626
- if v_true(fields, list) and fields is not None:
531
+ if fields is not None and isTrue(fields, list):
627
532
  outcsv.writerow(fields)
628
533
  outcsv.writerows(data)
629
534
  return True
630
535
  except Exception as e:
631
- if v_true(debug, bool):
632
- logger.exception(e)
536
+ logger.exception(e)
633
537
  return False
634
538
 
635
539
  def range_zfill(
636
540
  start: int,
637
541
  stop: int,
638
542
  step: int,
639
- width: int,
640
- debug: bool = False
543
+ width: int
641
544
  ) -> list | None:
642
545
  """range zfill"""
643
546
  # 生成长度相同的字符串的列表
@@ -649,8 +552,7 @@ def range_zfill(
649
552
  try:
650
553
  return [str(i).zfill(width) for i in range(start, stop, step)]
651
554
  except Exception as e:
652
- if v_true(debug, bool):
653
- logger.exception(e)
555
+ logger.exception(e)
654
556
  return None
655
557
 
656
558
 
@@ -659,8 +561,7 @@ def range_zfill(
659
561
 
660
562
  def dict_remove_key(
661
563
  data: dict,
662
- key: str,
663
- debug: bool = False
564
+ key: str
664
565
  ) -> dict | None:
665
566
  """dict remove key"""
666
567
  try:
@@ -668,15 +569,13 @@ def dict_remove_key(
668
569
  data_copy.pop(key)
669
570
  return data_copy
670
571
  except Exception as e:
671
- if v_true(debug, bool):
672
- logger.exception(e)
572
+ logger.exception(e)
673
573
  return None
674
574
 
675
575
  def dict_to_file(
676
576
  data: dict,
677
577
  file: str,
678
578
  encoding: str = 'utf-8-sig',
679
- debug: bool = False,
680
579
  **kwargs
681
580
  ) -> bool:
682
581
  """dict to file"""
@@ -685,23 +584,21 @@ def dict_to_file(
685
584
  json.dump(obj=data, fp=_file, indent=4, sort_keys=True, **kwargs)
686
585
  return True
687
586
  except Exception as e:
688
- if v_true(debug, bool):
689
- logger.exception(e)
587
+ logger.exception(e)
690
588
  return False
691
589
 
692
590
 
693
591
  def dict_nested_update(
694
592
  data: dict,
695
593
  key: str,
696
- value: Any,
697
- debug: bool = False
594
+ value: Any
698
595
  ) -> bool:
699
596
  """dict nested update"""
700
597
  # dictionary nested update
701
598
  # https://stackoverflow.com/a/58885744
702
599
  try:
703
600
 
704
- if not v_true(data, dict, debug=debug):
601
+ if not isTrue(data, dict):
705
602
  return False
706
603
 
707
604
  for _k, _v in data.items():
@@ -711,11 +608,11 @@ def dict_nested_update(
711
608
  data[_k] = value()
712
609
  else:
713
610
  data[_k] = value
714
- elif isinstance(_v, dict) is True:
611
+ elif isTrue(_v, dict):
715
612
  dict_nested_update(_v, key, value)
716
- elif isinstance(_v, list) is True:
613
+ elif isTrue(_v, list):
717
614
  for _o in _v:
718
- if isinstance(_o, dict):
615
+ if isTrue(_o, dict):
719
616
  dict_nested_update(_o, key, value)
720
617
  else:
721
618
  pass
@@ -723,8 +620,7 @@ def dict_nested_update(
723
620
  return True
724
621
 
725
622
  except Exception as e:
726
- if v_true(debug, bool):
727
- logger.exception(e)
623
+ logger.exception(e)
728
624
  return False
729
625
 
730
626
 
@@ -733,42 +629,24 @@ def dict_nested_update(
733
629
 
734
630
  def filename(
735
631
  file: str,
736
- split: str = '.',
737
- debug: bool = False
632
+ split: str = '.'
738
633
  ) -> str | None:
739
634
  """filename"""
740
635
  # 获取文件名称
741
636
  # https://stackoverflow.com/questions/678236/how-do-i-get-the-filename-without-the-extension-from-a-path-in-python
742
637
  # https://stackoverflow.com/questions/4152963/get-name-of-current-script-in-python
743
638
  try:
744
-
745
- if v_true(debug, bool):
746
- logger.info(f"file: {file}")
747
- logger.info(f"split: {split}")
748
-
749
639
  _basename = str(os.path.basename(file))
750
-
751
- if v_true(debug, bool):
752
- logger.info(f"basename: {_basename}")
753
-
754
640
  _index_of_split = _basename.index(split)
755
-
756
- if v_true(debug, bool):
757
- logger.info(f"index of split: {_index_of_split}")
758
- logger.info(f"filename: {_basename[:_index_of_split]}")
759
-
760
641
  return _basename[:_index_of_split]
761
-
762
642
  except Exception as e:
763
- if v_true(debug, bool):
764
- logger.exception(e)
643
+ logger.exception(e)
765
644
  return None
766
645
 
767
646
 
768
647
  def filehash(
769
648
  file: str,
770
- sha: str = 'md5',
771
- debug: bool = False
649
+ sha: str = 'md5'
772
650
  ) -> str | None:
773
651
  """filehash"""
774
652
  # 获取文件Hash
@@ -809,22 +687,19 @@ def filehash(
809
687
  file_hash.update(chunk)
810
688
  return file_hash.hexdigest()
811
689
  except Exception as e:
812
- if v_true(debug, bool):
813
- logger.exception(e)
690
+ logger.exception(e)
814
691
  return None
815
692
 
816
693
 
817
694
  def filesize(
818
- file: str,
819
- debug: bool = False
695
+ file: str
820
696
  ) -> int | None:
821
697
  """filesize"""
822
698
  # 获取文件大小
823
699
  try:
824
700
  return os.path.getsize(file)
825
701
  except Exception as e:
826
- if v_true(debug, bool):
827
- logger.exception(e)
702
+ logger.exception(e)
828
703
  return None
829
704
 
830
705
 
@@ -844,61 +719,52 @@ def filesize(
844
719
  # ) -> str | None:
845
720
  # """获取父目录名称"""
846
721
  # try:
847
- # 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
848
723
  # except Exception as e:
849
- # if v_true(debug, bool):
724
+ # if isTrue(debug, bool):
850
725
  # logger.exception(e)
851
726
  # return None
852
727
 
853
728
 
854
729
  def realpath(
855
730
  path: str,
856
- debug: bool = False,
857
731
  **kwargs
858
732
  ) -> str | None:
859
733
  """获取对象真实路径"""
860
734
  try:
861
- # if v_true(debug, bool):
862
- # logger.info(f"path: {path}")
863
- # return os.path.realpath(path, **kwargs)
864
- if v_true(path, str, debug=debug) is False:
735
+ if not isTrue(path, str):
865
736
  return None
866
737
  return str(Path(path, **kwargs).resolve())
867
738
  except Exception as e:
868
- if v_true(debug, bool):
869
- logger.exception(e)
739
+ logger.exception(e)
870
740
  return None
871
741
 
872
742
 
873
743
  def current_dir(
874
744
  path: str,
875
- debug: bool = False,
876
745
  **kwargs
877
746
  ) -> str | None:
878
747
  """获取对象所在目录"""
879
748
  try:
880
- if v_true(path, str, debug=debug) is False:
749
+ if not isTrue(path, str):
881
750
  return None
882
751
  return str(Path(path, **kwargs).parent.resolve())
883
752
  except Exception as e:
884
- if v_true(debug, bool):
885
- logger.exception(e)
753
+ logger.exception(e)
886
754
  return None
887
755
 
888
756
 
889
757
  def parent_dir(
890
758
  path: str,
891
- debug: bool = False,
892
759
  **kwargs
893
760
  ) -> str | None:
894
761
  """获取对象所在目录的父目录"""
895
762
  try:
896
- if v_true(path, str, debug=debug) is False:
763
+ if not isTrue(path, str):
897
764
  return None
898
765
  return str(Path(path, **kwargs).parent.parent.resolve())
899
766
  except Exception as e:
900
- if v_true(debug, bool):
901
- logger.exception(e)
767
+ logger.exception(e)
902
768
  return None
903
769
 
904
770
 
@@ -908,7 +774,6 @@ def parent_dir(
908
774
  def retry(
909
775
  times: int,
910
776
  func: Callable,
911
- debug: bool = False,
912
777
  **kwargs
913
778
  ):
914
779
  """重试"""
@@ -926,14 +791,11 @@ def retry(
926
791
  try:
927
792
  return func(**kwargs)
928
793
  except Exception as e:
929
- if v_true(debug, bool):
930
- logger.exception(e)
931
- logger.success('retrying ...')
794
+ logger.exception(e)
795
+ logger.info('retrying ...')
932
796
  continue
933
- # break
934
797
  except Exception as e:
935
- if v_true(debug, bool):
936
- logger.exception(e)
798
+ logger.exception(e)
937
799
 
938
800
 
939
801
  # --------------------------------------------------------------------------------------------------
@@ -983,30 +845,26 @@ def retry(
983
845
 
984
846
 
985
847
  def date_to_datetime(
986
- date_object: datetime.datetime,
987
- debug: bool = False
848
+ date_object: datetime.datetime
988
849
  ) -> datetime.datetime | None:
989
850
  """'日期'转换为'日期时间'"""
990
851
  # https://stackoverflow.com/a/1937636
991
852
  try:
992
853
  return datetime.datetime.combine(date_object, datetime.datetime.min.time())
993
854
  except Exception as e:
994
- if v_true(debug, bool):
995
- logger.exception(e)
855
+ logger.exception(e)
996
856
  return None
997
857
 
998
858
 
999
859
  def datetime_to_date(
1000
- datetime_instance: datetime.datetime,
1001
- debug: bool = False
860
+ datetime_instance: datetime.datetime
1002
861
  ) -> datetime.date | None:
1003
862
  """'日期时间'转换为'日期'"""
1004
863
  # https://stackoverflow.com/a/3743240
1005
864
  try:
1006
865
  return datetime_instance.date()
1007
866
  except Exception as e:
1008
- if v_true(debug, bool):
1009
- logger.exception(e)
867
+ logger.exception(e)
1010
868
  return None
1011
869
 
1012
870
 
@@ -1015,25 +873,20 @@ def local_timezone():
1015
873
  return datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
1016
874
 
1017
875
 
1018
- def datetime_now(
1019
- debug: bool = False,
1020
- **kwargs
1021
- ) -> datetime.datetime | None:
876
+ def datetime_now(**kwargs) -> datetime.datetime | None:
1022
877
  """获取当前日期和时间"""
1023
- _utc = kwargs.pop("utc", False)
878
+ utc = kwargs.pop("utc", False)
1024
879
  try:
1025
- if _utc is True:
880
+ if isTrue(utc, bool):
1026
881
  return datetime.datetime.now(datetime.timezone.utc)
1027
882
  return datetime.datetime.now(**kwargs)
1028
883
  except Exception as e:
1029
- if v_true(debug, bool):
1030
- logger.exception(e)
884
+ logger.exception(e)
1031
885
  return None
1032
886
 
1033
887
 
1034
888
  def datetime_offset(
1035
889
  datetime_instance: datetime.datetime | None = None,
1036
- debug: bool = False,
1037
890
  **kwargs
1038
891
  ) -> datetime.datetime | None:
1039
892
  """
@@ -1052,29 +905,27 @@ def datetime_offset(
1052
905
  return datetime.datetime.now() + datetime.timedelta(**kwargs)
1053
906
 
1054
907
  except Exception as e:
1055
- if v_true(debug, bool):
1056
- logger.exception(e)
908
+ logger.exception(e)
1057
909
  return None
1058
910
 
1059
911
 
1060
912
  def datetime_to_string(
1061
913
  datetime_instance: datetime.datetime,
1062
- string_format: str = '%Y-%m-%d %H:%M:%S',
1063
- debug: bool = False
914
+ string_format: str = '%Y-%m-%d %H:%M:%S'
1064
915
  ) -> str | None:
1065
916
  """'日期时间'转换为'字符串'"""
1066
917
  try:
1067
- 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)
1068
921
  except Exception as e:
1069
- if v_true(debug, bool):
1070
- logger.exception(e)
922
+ logger.exception(e)
1071
923
  return None
1072
924
 
1073
925
 
1074
926
  def datetime_to_timestamp(
1075
927
  datetime_instance: datetime.datetime,
1076
- utc: bool = False,
1077
- debug: bool = False
928
+ utc: bool = False
1078
929
  ) -> int | None:
1079
930
  """
1080
931
  Datatime 转换为 Unix Timestamp
@@ -1082,100 +933,93 @@ def datetime_to_timestamp(
1082
933
  UTC datetime 需要先替换 timezone 再转换为 Unix Timestamp
1083
934
  """
1084
935
  try:
1085
- if isinstance(datetime_instance, datetime.datetime):
1086
- return int(datetime_instance.replace(tzinfo=datetime.timezone.utc).timestamp()) if utc is True else int(datetime_instance.timestamp())
1087
- 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())
1088
939
  except Exception as e:
1089
- if v_true(debug, bool):
1090
- logger.exception(e)
940
+ logger.exception(e)
1091
941
  return None
1092
942
 
1093
943
 
1094
944
  def datetime_local_to_timezone(
1095
945
  datetime_instance: datetime.datetime,
1096
- tz: datetime.timezone = datetime.timezone.utc,
1097
- debug: bool = False
946
+ tz: datetime.timezone = datetime.timezone.utc
1098
947
  ) -> datetime.datetime | None:
1099
948
  """
1100
949
  Local datetime to TimeZone datetime (默认转换为 UTC datetime)
1101
950
  replace(tzinfo=None) 移除结尾的时区信息
1102
951
  """
1103
952
  try:
1104
- if isinstance(datetime_instance, datetime.datetime) is True:
1105
- return (datetime.datetime.fromtimestamp(datetime_instance.timestamp(), tz=tz)).replace(tzinfo=None)
1106
- else:
953
+ if not isTrue(datetime_instance, datetime.datetime):
1107
954
  return None
955
+ return (datetime.datetime.fromtimestamp(datetime_instance.timestamp(), tz=tz)).replace(tzinfo=None)
1108
956
  except Exception as e:
1109
- if v_true(debug, bool):
1110
- logger.exception(e)
957
+ logger.exception(e)
1111
958
  return None
1112
959
 
1113
960
 
1114
961
  def datetime_utc_to_timezone(
1115
962
  datetime_instance: datetime.datetime,
1116
- tz: Any = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo,
1117
- debug: bool = False
963
+ tz: Any = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
1118
964
  ) -> datetime.datetime | None:
1119
965
  """
1120
966
  UTC datetime to TimeZone datetime (默认转换为 Local datetime)
1121
967
  replace(tzinfo=None) 移除结尾的时区信息
1122
968
  """
1123
969
  try:
1124
- if isinstance(datetime_instance, datetime.datetime) is True:
1125
- return datetime_instance.replace(tzinfo=datetime.timezone.utc).astimezone(tz).replace(tzinfo=None)
1126
- else:
970
+ if not isTrue(datetime_instance, datetime.datetime):
1127
971
  return None
972
+ return datetime_instance.replace(tzinfo=datetime.timezone.utc).astimezone(tz).replace(tzinfo=None)
973
+
1128
974
  except Exception as e:
1129
- if v_true(debug, bool):
1130
- logger.exception(e)
975
+ logger.exception(e)
1131
976
  return None
1132
977
 
1133
978
 
1134
979
  def timestamp_to_datetime(
1135
980
  timestamp: int,
1136
- tz: datetime.timezone = datetime.timezone.utc,
1137
- debug: bool = False
981
+ tz: datetime.timezone = datetime.timezone.utc
1138
982
  ) -> datetime.datetime | None:
1139
983
  """Unix Timestamp 转换为 Datatime"""
1140
984
  try:
1141
- 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)
1142
988
  except Exception as e:
1143
- if v_true(debug, bool):
1144
- logger.exception(e)
989
+ logger.exception(e)
1145
990
  return None
1146
991
 
1147
992
 
1148
993
  def datetime_string_to_datetime(
1149
994
  datetime_string: str,
1150
- datetime_format: str = '%Y-%m-%d %H:%M:%S',
1151
- debug: bool = False
995
+ datetime_format: str = '%Y-%m-%d %H:%M:%S'
1152
996
  ) -> datetime.datetime | None:
1153
997
  """datetime string to datetime"""
1154
998
  try:
1155
- 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)
1156
1002
  except Exception as e:
1157
- if v_true(debug, bool):
1158
- logger.exception(e)
1003
+ logger.exception(e)
1159
1004
  return None
1160
1005
 
1161
1006
 
1162
1007
  def datetime_string_to_timestamp(
1163
1008
  datetime_string: str,
1164
- datetime_format: str = '%Y-%m-%d %H:%M:%S',
1165
- debug: bool = False
1009
+ datetime_format: str = '%Y-%m-%d %H:%M:%S'
1166
1010
  ) -> int | None:
1167
1011
  """datetime string to timestamp"""
1168
1012
  try:
1169
- 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)))
1170
1016
  except Exception as e:
1171
- if v_true(debug, bool):
1172
- logger.exception(e)
1017
+ logger.exception(e)
1173
1018
  return None
1174
1019
 
1175
1020
 
1176
1021
  def datetime_object(
1177
- date_time: datetime.datetime,
1178
- debug: bool = False
1022
+ date_time: datetime.datetime
1179
1023
  ) -> dict | None:
1180
1024
  """datetime object"""
1181
1025
  try:
@@ -1188,8 +1032,7 @@ def datetime_object(
1188
1032
  'datetime_zero': date_time.strftime('%Y-%m-%d 00:00:00')
1189
1033
  }
1190
1034
  except Exception as e:
1191
- if v_true(debug, bool):
1192
- logger.exception(e)
1035
+ logger.exception(e)
1193
1036
  return None
1194
1037
 
1195
1038
 
@@ -1219,15 +1062,14 @@ def shell(
1219
1062
  isfile: bool = False,
1220
1063
  sh_shell: str = '/bin/bash',
1221
1064
  sh_option: str | None = None,
1222
- debug: bool = False,
1223
1065
  **kwargs
1224
1066
  ) -> subprocess.CompletedProcess | None:
1225
1067
  """run shell command or script"""
1226
1068
  try:
1227
1069
  match True:
1228
- case True if not check_file_type(sh_shell, 'file', debug=debug):
1070
+ case True if not check_file_type(sh_shell, 'file'):
1229
1071
  return None
1230
- 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):
1231
1073
  if isfile is True:
1232
1074
  if sh_option is None:
1233
1075
  return subprocess.run([sh_shell, command], **kwargs, check=False)
@@ -1238,8 +1080,7 @@ def shell(
1238
1080
  case _:
1239
1081
  return None
1240
1082
  except Exception as e:
1241
- if v_true(debug, bool):
1242
- logger.exception(e)
1083
+ logger.exception(e)
1243
1084
  return None
1244
1085
 
1245
1086
 
@@ -1247,21 +1088,18 @@ def shell(
1247
1088
 
1248
1089
 
1249
1090
  def json_file_parser(
1250
- file: str,
1251
- debug: bool = False
1091
+ file: str
1252
1092
  ) -> dict | None:
1253
1093
  """JSON File Parser"""
1254
1094
  try:
1255
- if check_file_type(file, 'file', debug=debug):
1256
- with open(file, encoding="utf-8") as json_raw:
1257
- json_dict = json.load(json_raw)
1258
- return json_dict
1259
- if v_true(debug, bool):
1260
- logger.error(f"No such file: {file}")
1261
- 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
1262
1101
  except Exception as e:
1263
- if v_true(debug, bool):
1264
- logger.exception(e)
1102
+ logger.exception(e)
1265
1103
  return None
1266
1104
 
1267
1105
  # json_raw = '''
@@ -1285,15 +1123,15 @@ def json_file_parser(
1285
1123
 
1286
1124
  def json_sort(
1287
1125
  string: str,
1288
- debug: bool = False,
1289
1126
  **kwargs
1290
1127
  ) -> str | None:
1291
1128
  """JSON Sort"""
1292
1129
  try:
1293
- 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)
1294
1133
  except Exception as e:
1295
- if v_true(debug, bool):
1296
- logger.exception(e)
1134
+ logger.exception(e)
1297
1135
  return None
1298
1136
 
1299
1137
 
@@ -1301,48 +1139,39 @@ def json_sort(
1301
1139
 
1302
1140
 
1303
1141
  def delete_files(
1304
- files: Union[str, List],
1305
- debug: bool = False
1142
+ files: Union[str, List]
1306
1143
  ) -> bool:
1307
1144
  """删除文件"""
1308
1145
  try:
1309
1146
 
1310
- if isinstance(files, str) and check_file_type(files, 'file', debug=debug):
1311
-
1147
+ if isinstance(files, str) and check_file_type(files, 'file'):
1312
1148
  os.remove(files)
1313
- if v_true(debug, bool):
1314
- logger.success(f'deleted file: {files}')
1149
+ logger.success(f'deleted file: {files}')
1315
1150
  return True
1316
1151
 
1317
- if v_true(files, list, debug=debug):
1318
-
1319
- for _file in files:
1320
-
1321
- if v_true(_file, str, debug=debug) and check_file_type(_file, 'file', debug=debug):
1322
- try:
1323
- os.remove(_file)
1324
- logger.success(f'deleted file: {_file}')
1325
- except Exception as e:
1326
- logger.error(f'error file: {_file} {e}')
1327
- else:
1328
- logger.error(f'error file: {_file}')
1152
+ if not isTrue(files, list):
1153
+ return False
1329
1154
 
1330
- return True
1155
+ for _file in files:
1331
1156
 
1332
- if v_true(debug, bool):
1333
- 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}')
1334
1165
 
1335
- return False
1166
+ return True
1336
1167
 
1337
1168
  except Exception as e:
1338
- if v_true(debug, bool):
1339
- logger.exception(e)
1169
+ logger.exception(e)
1340
1170
  return False
1341
1171
 
1342
1172
 
1343
1173
  def delete_directory(
1344
- directory: Union[str, List],
1345
- debug: bool = False
1174
+ directory: Union[str, List]
1346
1175
  ) -> bool:
1347
1176
  """
1348
1177
  delete directory
@@ -1369,41 +1198,30 @@ def delete_directory(
1369
1198
  """
1370
1199
  try:
1371
1200
 
1372
- if isinstance(directory, str) and check_file_type(directory, 'dir', debug=debug):
1373
-
1201
+ if isinstance(directory, str) and check_file_type(directory, 'dir'):
1374
1202
  rmtree(directory)
1375
-
1376
- if v_true(debug, bool):
1377
- logger.success(f'deleted directory: {directory}')
1378
-
1203
+ logger.success(f'deleted directory: {directory}')
1379
1204
  return True
1380
1205
 
1381
- elif v_true(directory, list, debug=debug):
1382
-
1383
- for _dir in directory:
1206
+ if not isTrue(directory, list):
1207
+ logger.error(f'error directory: {directory}')
1208
+ return False
1384
1209
 
1385
- if v_true(_dir, str, debug=debug) and check_file_type(_dir, 'dir', debug=debug):
1386
- try:
1387
- rmtree(_dir)
1388
- if v_true(debug, bool):
1389
- logger.success(f'deleted directory: {_dir}')
1390
- except Exception as e:
1391
- if v_true(debug, bool):
1392
- logger.error(f'error directory: {_dir} {e}')
1393
- else:
1394
- if v_true(debug, bool):
1395
- logger.error(f'error directory: {_dir}')
1210
+ for _dir in directory:
1396
1211
 
1397
- 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}')
1398
1220
 
1399
- else:
1400
- if v_true(debug, bool):
1401
- logger.error(f'error directory: {directory}')
1402
- return False
1221
+ return True
1403
1222
 
1404
1223
  except Exception as e:
1405
- if v_true(debug, bool):
1406
- logger.exception(e)
1224
+ logger.exception(e)
1407
1225
  return False
1408
1226
 
1409
1227
 
@@ -1415,7 +1233,6 @@ def process_pool(
1415
1233
  process_data: Any = None,
1416
1234
  process_num: int = 2,
1417
1235
  thread: bool = False,
1418
- debug: bool = False,
1419
1236
  **kwargs
1420
1237
  ) -> list | bool:
1421
1238
  """
@@ -1428,37 +1245,29 @@ def process_pool(
1428
1245
  try:
1429
1246
 
1430
1247
  # 处理数据
1431
- if v_true(debug, bool):
1432
- logger.info("data split ......")
1433
1248
  if len(process_data) <= process_num:
1434
1249
  process_num = len(process_data)
1435
1250
  _data = process_data
1436
1251
  else:
1437
- _data = list_split(process_data, process_num, equally=True, debug=debug)
1252
+ _data = list_split(process_data, process_num, equally=True)
1438
1253
 
1439
1254
  if _data is None:
1440
1255
  return False
1441
1256
 
1442
- if v_true(debug, bool):
1443
- logger.info(f"data: {_data}")
1444
-
1445
1257
  # 执行函数
1446
- if v_true(thread, bool):
1258
+ if isTrue(thread, bool):
1447
1259
  # 多线程
1448
- if v_true(debug, bool):
1449
- logger.info("execute multi thread ......")
1260
+ logger.info("execute multi thread ......")
1450
1261
  with ThreadPool(process_num, **kwargs) as p:
1451
1262
  return p.map(process_func, _data)
1452
1263
  else:
1453
1264
  # 多进程
1454
- if v_true(debug, bool):
1455
- logger.info("execute multi process ......")
1265
+ logger.info("execute multi process ......")
1456
1266
  with Pool(process_num, **kwargs) as p:
1457
1267
  return p.map(process_func, _data)
1458
1268
 
1459
1269
  except Exception as e:
1460
- if v_true(debug, bool):
1461
- logger.exception(e)
1270
+ logger.exception(e)
1462
1271
  return False
1463
1272
 
1464
1273
 
@@ -1467,12 +1276,11 @@ def new_process(
1467
1276
  process_data: Any = None,
1468
1277
  thread: bool = False,
1469
1278
  daemon: bool = True,
1470
- debug: bool = False,
1471
1279
  **kwargs
1472
1280
  ) -> Thread | Process | bool:
1473
1281
  """New Process"""
1474
1282
  try:
1475
- if v_true(thread, bool):
1283
+ if isTrue(thread, bool):
1476
1284
  process = Thread(target=process_func, args=process_data, **kwargs)
1477
1285
  else:
1478
1286
  process = Process(target=process_func, args=process_data, **kwargs)
@@ -1480,8 +1288,7 @@ def new_process(
1480
1288
  process.start()
1481
1289
  return process
1482
1290
  except Exception as e:
1483
- if v_true(debug, bool):
1484
- logger.exception(e)
1291
+ logger.exception(e)
1485
1292
  return False
1486
1293
 
1487
1294
 
@@ -1489,28 +1296,22 @@ def new_process(
1489
1296
 
1490
1297
 
1491
1298
  def create_empty_file(
1492
- file: str | None = None,
1493
- debug: bool = False
1299
+ file: str | None = None
1494
1300
  ) -> str | None:
1495
1301
  """create empty file"""
1496
1302
  try:
1497
1303
  if file is None:
1498
1304
  # 当前时间戳(纳秒)
1499
1305
  timestamp = time.time_ns()
1500
- if v_true(debug, bool):
1501
- logger.info(f"timestamp: {timestamp}")
1502
1306
  # 空文件路径
1503
- file = f'/tmp/empty_file_{timestamp}.txt'
1307
+ file = f'/tmp/none_{timestamp}.txt'
1504
1308
  # 创建一个空文件
1505
- if v_true(debug, bool):
1506
- logger.info(f"file: {file}")
1507
1309
  # pylint: disable=R1732
1508
1310
  open(file, "w", encoding="utf-8").close()
1509
1311
  # 返回文件路径
1510
1312
  return file
1511
1313
  except Exception as e:
1512
- if v_true(debug, bool):
1513
- logger.exception(e)
1314
+ logger.exception(e)
1514
1315
  return None
1515
1316
 
1516
1317
 
@@ -1523,8 +1324,7 @@ def uuid4_hex() -> str:
1523
1324
 
1524
1325
 
1525
1326
  def increment_version(
1526
- version: str,
1527
- debug: bool = False
1327
+ version: str
1528
1328
  ) -> str | None:
1529
1329
  """版本号递增"""
1530
1330
  try:
@@ -1532,8 +1332,7 @@ def increment_version(
1532
1332
  version_numbers[-1] = str(int(version_numbers[-1]) + 1)
1533
1333
  return '.'.join(version_numbers)
1534
1334
  except Exception as e:
1535
- if v_true(debug, bool):
1536
- logger.exception(e)
1335
+ logger.exception(e)
1537
1336
  return None
1538
1337
 
1539
1338
 
@@ -1549,37 +1348,28 @@ def make_directory(
1549
1348
  os.makedirs(directory)
1550
1349
  return True
1551
1350
  except Exception as e:
1552
- if v_true(debug, bool):
1553
- logger.exception(e)
1351
+ logger.exception(e)
1554
1352
  return False
1555
1353
 
1556
1354
  def change_directory(
1557
- directory: str,
1558
- debug: bool = False
1355
+ directory: str
1559
1356
  ) -> bool:
1560
1357
  """改变目录"""
1561
1358
  try:
1562
1359
 
1563
- if not v_true(directory, str, debug=debug):
1360
+ if not isTrue(directory, str):
1564
1361
  return False
1565
1362
 
1566
- if v_true(debug, bool):
1567
- logger.info(f"directory: {directory}")
1568
-
1569
- if check_file_type(directory, 'dir', debug=debug):
1570
- if v_true(debug, bool):
1571
- logger.info(f"change directory to {directory}")
1572
- os.chdir(directory)
1573
- return True
1574
-
1575
- if v_true(debug, bool):
1363
+ if not check_file_type(directory, 'dir'):
1576
1364
  logger.error(f"no such directory: {directory}")
1365
+ return False
1577
1366
 
1578
- return False
1367
+ os.chdir(directory)
1368
+
1369
+ return True
1579
1370
 
1580
1371
  except Exception as e:
1581
- if v_true(debug, bool):
1582
- logger.exception(e)
1372
+ logger.exception(e)
1583
1373
  return False
1584
1374
 
1585
1375
 
@@ -1587,23 +1377,19 @@ def change_directory(
1587
1377
 
1588
1378
 
1589
1379
  def load_toml_file(
1590
- file: str,
1591
- debug: bool = False
1380
+ file: str
1592
1381
  ) -> dict | None:
1593
1382
  """Load TOML file"""
1594
1383
  info = '解析配置文件'
1595
1384
  try:
1596
- if v_true(debug, bool):
1597
- logger.info(f'{info}[执行]')
1385
+ logger.info(f'{info}[执行]')
1598
1386
  with open(file, "rb") as _file:
1599
1387
  config = tomllib.load(_file)
1600
- if v_true(debug, bool):
1601
- logger.success(f'{info}[成功]')
1388
+ logger.success(f'{info}[成功]')
1602
1389
  return config
1603
1390
  except Exception as e:
1604
- if v_true(debug, bool):
1605
- logger.error(f'{info}[失败]')
1606
- logger.exception(e)
1391
+ logger.error(f'{info}[失败]')
1392
+ logger.exception(e)
1607
1393
  return None
1608
1394
 
1609
1395
 
@@ -1612,35 +1398,33 @@ def git_clone(
1612
1398
  local_repository: str,
1613
1399
  timeout: int = 30,
1614
1400
  delete: bool = False,
1615
- log_prefix: str = '',
1616
- debug: bool = False,
1401
+ log_prefix: str = ''
1617
1402
  ) -> bool:
1618
1403
  """GIT Clone"""
1619
- try:
1620
1404
 
1621
- # 日志前缀
1622
- log_prefix = f'{log_prefix}[GitClone]'
1405
+ # 日志前缀
1406
+ log_prefix = f'{log_prefix} [GitClone]'
1407
+
1408
+ try:
1623
1409
 
1624
1410
  # 获取应用程序Git仓库
1625
- if v_true(debug, bool):
1626
- logger.info(f'{log_prefix}process the request')
1627
- logger.info(f'{log_prefix}git repository: {git_repository}')
1628
- 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}')
1629
1414
 
1630
1415
  # 删除本地仓库
1631
- if v_true(delete, bool):
1632
- delete_directory(local_repository, debug=debug)
1416
+ if isTrue(delete, bool):
1417
+ delete_directory(local_repository)
1633
1418
  time.sleep(1)
1634
1419
 
1635
1420
  # from shutil import which
1636
- # logger.info(which('timeout')) if v_true(debug, bool) else next
1421
+ # logger.info(which('timeout')) if isTrue(debug, bool) else next
1637
1422
  # if which('timeout') != None:
1638
1423
  # command = f'timeout -s 9 {timeout} git clone {git_repository} {local_repository}'
1639
1424
 
1640
1425
  # 克隆仓库
1641
1426
  result = shell(
1642
1427
  command=f'timeout -s 9 {timeout} git clone {git_repository} {local_repository}',
1643
- debug=debug,
1644
1428
  universal_newlines=True,
1645
1429
  stdout=subprocess.PIPE,
1646
1430
  stderr=subprocess.STDOUT
@@ -1652,42 +1436,34 @@ def git_clone(
1652
1436
  result_code: int = result.returncode
1653
1437
  result_info = result.stdout.splitlines()
1654
1438
 
1655
- if v_true(debug, bool):
1656
- logger.error(f'{log_prefix}unsuccessful')
1439
+ if result_code != 0:
1657
1440
  for i in result_info:
1658
1441
  logger.error(f'{log_prefix}{i}')
1442
+ return False
1659
1443
 
1660
- if result_code == 0:
1661
- return True
1662
-
1663
- return False
1444
+ return True
1664
1445
 
1665
1446
  except Exception as e:
1666
- if v_true(debug, bool):
1667
- logger.error(f'{log_prefix}unsuccessful')
1668
- logger.exception(e)
1447
+ logger.error(f'{log_prefix} [failure]')
1448
+ logger.exception(e)
1669
1449
  return False
1670
1450
 
1671
1451
 
1672
1452
  def url_parse(
1673
1453
  url: str,
1674
- scheme: str = 'http',
1675
- debug: bool = False
1454
+ scheme: str = 'http'
1676
1455
  ) -> ParseResult:
1677
1456
  """URL Parse"""
1678
1457
  none_result = ParseResult(scheme='', netloc='', path='', params='', query='', fragment='')
1679
1458
  try:
1680
- if v_true(debug, bool):
1681
- logger.info(f'url: {url}')
1682
1459
  # 如果没有 scheme 的话, 字符串是不解析的. 所以, 如果没有 scheme, 就添加一个 scheme, 默认添加 http
1683
- 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):
1684
1461
  url = f'{scheme}://{url}'
1685
- if v_true(url, str):
1462
+ if isTrue(url, str):
1686
1463
  return urlparse(url)
1687
1464
  return none_result
1688
1465
  except Exception as e:
1689
- if v_true(debug, bool):
1690
- logger.exception(e)
1466
+ logger.exception(e)
1691
1467
  return none_result
1692
1468
 
1693
1469
  # def debug_log(
@@ -1697,15 +1473,15 @@ def url_parse(
1697
1473
  # error: bool = False
1698
1474
  # ):
1699
1475
  # """debug log"""
1700
- # if v_true(log, str) and v_true(debug, bool):
1701
- # if v_true(error, bool):
1476
+ # if isTrue(log, str) and isTrue(debug, bool):
1477
+ # if isTrue(error, bool):
1702
1478
  # logger.error(log)
1703
1479
  # else:
1704
1480
  # logger.info(log)
1705
1481
  # return
1706
1482
 
1707
- # if v_true(exception, Exception):
1708
- # if v_true(debug, bool):
1483
+ # if isTrue(exception, Exception):
1484
+ # if isTrue(debug, bool):
1709
1485
  # logger.exception(exception)
1710
1486
  # else:
1711
1487
  # logger.error(exception)