absfuyu 4.1.0__py3-none-any.whl → 4.1.1__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 absfuyu might be problematic. Click here for more details.

absfuyu/__init__.py CHANGED
@@ -22,7 +22,7 @@ Using in cmd (`absfuyu[cli]` required):
22
22
  __title__ = "absfuyu"
23
23
  __author__ = "AbsoluteWinter"
24
24
  __license__ = "MIT License"
25
- __version__ = "4.1.0"
25
+ __version__ = "4.1.1"
26
26
  __all__ = [
27
27
  "core",
28
28
  "config",
absfuyu/cli/do_group.py CHANGED
@@ -3,7 +3,7 @@ ABSFUYU CLI
3
3
  -----------
4
4
  Do
5
5
 
6
- Version: 1.3.0
6
+ Version: 1.3.1
7
7
  Date updated: 01/02/2025 (dd/mm/yyyy)
8
8
  """
9
9
 
@@ -18,7 +18,7 @@ from absfuyu import __title__
18
18
  from absfuyu.cli.color import COLOR
19
19
  from absfuyu.core import __package_feature__
20
20
  from absfuyu.general.human import Human2
21
- from absfuyu.tools.checksum import checksum_operation
21
+ from absfuyu.tools.checksum import Checksum
22
22
  from absfuyu.util.zipped import Zipper
23
23
  from absfuyu.version import PkgVersion
24
24
 
@@ -109,6 +109,26 @@ def unzip_files_in_dir(dir: str) -> None:
109
109
  show_default=True,
110
110
  help="Hash mode",
111
111
  )
112
+ @click.option(
113
+ "--save-result",
114
+ "-s",
115
+ "save_result",
116
+ type=bool,
117
+ default=False,
118
+ is_flag=True,
119
+ show_default=True,
120
+ help="Save checksum result to file",
121
+ )
122
+ @click.option(
123
+ "--recursive",
124
+ "-r",
125
+ "recursive_mode",
126
+ type=bool,
127
+ default=False,
128
+ is_flag=True,
129
+ show_default=True,
130
+ help="Do checksum for every file in the folder (including child folder)",
131
+ )
112
132
  @click.option(
113
133
  "--compare",
114
134
  "-c",
@@ -121,11 +141,14 @@ def unzip_files_in_dir(dir: str) -> None:
121
141
  def file_checksum(
122
142
  file_path: str,
123
143
  hash_mode: str | Literal["md5", "sha1", "sha256", "sha512"],
144
+ save_result: bool,
145
+ recursive_mode: bool,
124
146
  hash_to_compare: str,
125
147
  ) -> None:
126
148
  """Checksum for file"""
127
-
128
- res = checksum_operation(file_path, hash_mode=hash_mode)
149
+ # print(hash_mode, save_result, recursive_mode)
150
+ instance = Checksum(file_path, hash_mode=hash_mode, save_result_to_file=save_result)
151
+ res = instance.checksum(recursive=recursive_mode)
129
152
  if hash_to_compare:
130
153
  print(res == hash_to_compare)
131
154
  else:
absfuyu/core.py CHANGED
@@ -3,7 +3,7 @@ Absfuyu: Core
3
3
  -------------
4
4
  Contain type hints and other stuffs
5
5
 
6
- Version: 2.3.0
6
+ Version: 2.3.1
7
7
  Date updated: 01/02/2025 (dd/mm/yyyy)
8
8
  """
9
9
 
@@ -25,7 +25,6 @@ __package_feature__ = ["beautiful", "extra", "res", "full", "dev"]
25
25
  ###########################################################################
26
26
  from importlib import import_module
27
27
  from importlib.resources import files
28
- from typing import Iterable
29
28
 
30
29
 
31
30
  class CLITextColor:
@@ -54,5 +53,5 @@ try:
54
53
  tqdm = import_module("tqdm").tqdm
55
54
  except ModuleNotFoundError:
56
55
 
57
- def tqdm(iterable: Iterable, **kwargs):
56
+ def tqdm(iterable, **kwargs):
58
57
  return iterable
absfuyu/tools/checksum.py CHANGED
@@ -3,13 +3,13 @@ Absufyu: Checksum
3
3
  -----------------
4
4
  Check MD5, SHA256, ...
5
5
 
6
- Version: 1.0.0
6
+ Version: 1.1.0
7
7
  Date updated: 01/02/2025 (dd/mm/yyyy)
8
8
  """
9
9
 
10
10
  # Module level
11
11
  ###########################################################################
12
- __all__ = ["checksum_operation"]
12
+ __all__ = ["Checksum", "checksum_operation"]
13
13
 
14
14
 
15
15
  # Library
@@ -18,9 +18,13 @@ import hashlib
18
18
  from pathlib import Path
19
19
  from typing import Literal
20
20
 
21
+ from absfuyu.core import tqdm
21
22
 
22
23
  # Function
23
24
  ###########################################################################
25
+
26
+
27
+ # Deprecated
24
28
  def checksum_operation(
25
29
  file: Path | str,
26
30
  hash_mode: str | Literal["md5", "sha1", "sha256", "sha512"] = "sha256",
@@ -38,9 +42,6 @@ def checksum_operation(
38
42
  hash_engine = hashlib.md5()
39
43
 
40
44
  with open(Path(file), "rb") as f:
41
- # Read and hash the file in 4K chunks. Reading the whole
42
- # file at once might consume a lot of memory if it is
43
- # large.
44
45
  while True:
45
46
  data = f.read(4096)
46
47
  if len(data) == 0:
@@ -50,6 +51,92 @@ def checksum_operation(
50
51
  return hash_engine.hexdigest()
51
52
 
52
53
 
54
+ class Checksum:
55
+ def __init__(
56
+ self,
57
+ path: str | Path,
58
+ hash_mode: str | Literal["md5", "sha1", "sha256", "sha512"] = "sha256",
59
+ save_result_to_file: bool = False,
60
+ ) -> None:
61
+ self.path = Path(path)
62
+ self.hash_mode = hash_mode
63
+ self.save_result_to_file = save_result_to_file
64
+ self.checksum_result_file_name = "checksum_results.txt"
65
+
66
+ def _get_hash_engine(self):
67
+ hash_mode = self.hash_mode
68
+ if hash_mode.lower() == "md5":
69
+ hash_engine = hashlib.md5()
70
+ elif hash_mode.lower() == "sha1":
71
+ hash_engine = hashlib.sha1()
72
+ elif hash_mode.lower() == "sha256":
73
+ hash_engine = hashlib.sha256()
74
+ elif hash_mode.lower() == "sha512":
75
+ hash_engine = hashlib.sha512()
76
+ else:
77
+ hash_engine = hashlib.md5()
78
+ return hash_engine
79
+
80
+ def _checksum_operation(
81
+ self,
82
+ file: Path | str,
83
+ ) -> str:
84
+ """This performs checksum"""
85
+
86
+ hash_engine = self._get_hash_engine().copy()
87
+ with open(Path(file), "rb") as f:
88
+ # Read and hash the file in 4K chunks. Reading the whole
89
+ # file at once might consume a lot of memory if it is
90
+ # large.
91
+ while True:
92
+ data = f.read(4096)
93
+ if len(data) == 0:
94
+ break
95
+ else:
96
+ hash_engine.update(data)
97
+ return hash_engine.hexdigest() # type: ignore
98
+
99
+ def checksum(self, recursive: bool = True) -> str:
100
+ """Perform checksum
101
+
102
+ Parameters
103
+ ----------
104
+ recursive : bool, optional
105
+ Do checksum for every file in the folder (including child folder), by default True
106
+
107
+ Returns
108
+ -------
109
+ str
110
+ Checksum hash
111
+ """
112
+ if self.path.absolute().is_dir():
113
+ new_path = self.path.joinpath(self.checksum_result_file_name)
114
+ # List of files
115
+ if recursive:
116
+ file_list: list[Path] = [
117
+ x for x in self.path.glob("**/*") if x.is_file()
118
+ ]
119
+ else:
120
+ file_list = [x for x in self.path.glob("*") if x.is_file()]
121
+
122
+ # Checksum
123
+ res = []
124
+ for x in tqdm(file_list, desc="Calculating hash", unit_scale=True):
125
+ name = x.relative_to(self.path)
126
+ res.append(f"{self._checksum_operation(x)} | {name}")
127
+ output = "\n".join(res)
128
+ else:
129
+ new_path = self.path.with_name(self.checksum_result_file_name)
130
+ output = self._checksum_operation(self.path)
131
+
132
+ # Save result
133
+ if self.save_result_to_file:
134
+ with open(new_path, "w", encoding="utf-8") as f:
135
+ f.write(output)
136
+
137
+ return output
138
+
139
+
53
140
  # Run
54
141
  ###########################################################################
55
142
  if __name__ == "__main__":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: absfuyu
3
- Version: 4.1.0
3
+ Version: 4.1.1
4
4
  Summary: A small collection of code
5
5
  Project-URL: Homepage, https://github.com/AbsoluteWinter/absfuyu-public
6
6
  Project-URL: Documentation, https://absolutewinter.github.io/absfuyu-docs/
@@ -1,6 +1,6 @@
1
- absfuyu/__init__.py,sha256=H-4MDDeiuQVuYt4Qrv8ae8286dc3Vv2JHgOkU6VxCKw,638
1
+ absfuyu/__init__.py,sha256=EGTitZIqMbg-jQFJD5nJi4papdMQsCoYnr-9EnvlUmI,638
2
2
  absfuyu/__main__.py,sha256=OpMwc35W5VANzw6gvlqJaJOl2H89i_frFZbleUQwDss,163
3
- absfuyu/core.py,sha256=pGN-tBD5S_p0lm3f0clPujnH9n6JZSD1cqNilBM-ZK0,1279
3
+ absfuyu/core.py,sha256=MZQH3hpUAamGx2NM-TlIWvAnRBBwa9R9fm7F2WFe60c,1240
4
4
  absfuyu/everything.py,sha256=PGIXlqgxyADFPygohVYVIb7fZz72L_xXrlLX0WImuYg,788
5
5
  absfuyu/logger.py,sha256=Pue3oWYYSF03A-fVp3E137jzlZVI71mYqddic8myauQ,13141
6
6
  absfuyu/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -9,7 +9,7 @@ absfuyu/version.py,sha256=KMaeXNl93L4VU2RnTySoFv23IDyTvHfy84nyatFcKaE,14128
9
9
  absfuyu/cli/__init__.py,sha256=nKTbe4iPpkjtDDMJwVY36heInKDm1zyek9ags5an7s4,1105
10
10
  absfuyu/cli/color.py,sha256=7M3XqFllt26tv_NR5qKgyTId6wnVADtUB74cDYy8pOQ,497
11
11
  absfuyu/cli/config_group.py,sha256=FsyYm2apSyAA2PAD12CpHAizenRds_QlLf8j0AlLuVo,1230
12
- absfuyu/cli/do_group.py,sha256=_GzTrxZwVtrTl3kTd_MQTstX5DKQTjDbFgHmlghanP0,3533
12
+ absfuyu/cli/do_group.py,sha256=HS1G9nFnqtmNVwWZiOGvu4RB6URT2VnCpEtdY9e7n2Q,4132
13
13
  absfuyu/cli/game_group.py,sha256=ySpL2hm4VCplhNY0s22kBGI5eFCdJj9fm1T58yftU74,2348
14
14
  absfuyu/config/__init__.py,sha256=4r77tFm3mgHX8H1uWWNXC_FZ8hiSJzsYAyiStZiVj5w,8641
15
15
  absfuyu/config/config.json,sha256=-ZQnmDuLq0aAFfsrQbSNR3tq5k9Eu9IVUQgYD9htIQM,646
@@ -39,7 +39,7 @@ absfuyu/pkg_data/__init__.py,sha256=VbUoFnUDiw_3bKZVvIzwf_ve0y97rmhfpkbbrP_ob_w,
39
39
  absfuyu/pkg_data/chemistry.pkl,sha256=kYWNa_PVffoDnzT8b9Jvimmf_GZshPe1D-SnEKERsLo,4655
40
40
  absfuyu/pkg_data/tarot.pkl,sha256=ssXTCC_BQgslO5F-3a9HivbxFQ6BioIe2E1frPVi2m0,56195
41
41
  absfuyu/tools/__init__.py,sha256=VDmmMLEfiRyUWPVrPYc8JUEa5TXjLguKVnyI3YavFv0,118
42
- absfuyu/tools/checksum.py,sha256=33DlwXRqPcatuNJ14NG9gJLe3y5RgnJm0w0dkSFurhU,1563
42
+ absfuyu/tools/checksum.py,sha256=cLSuL_ZsoroFYYVR1GhOfBbon_iXEm1OazbjYFPJabM,4393
43
43
  absfuyu/tools/converter.py,sha256=8jqOSdkbzzupKJcBndV5q4OBu2kWFWpV3j2IswS4Vqc,10609
44
44
  absfuyu/tools/keygen.py,sha256=drj8OUDCXrLvcVf9_Shd5UMShm_mBTxa9Sg_BrAT5yM,7356
45
45
  absfuyu/tools/obfuscator.py,sha256=kiaFvMw2RwEfZvXKdbUrEYA_AuVETivoL2eVmtUWU4w,8669
@@ -54,8 +54,8 @@ absfuyu/util/performance.py,sha256=F-aLJ-5wmwkiOdl9_wZcFRKifL9zOahw52JeL4TbCuQ,9
54
54
  absfuyu/util/pkl.py,sha256=ZZf6-PFC2uRGXqARNi0PGH3A0IXwMP0sYPWZJXENvak,1559
55
55
  absfuyu/util/shorten_number.py,sha256=_R_FhzBYDvtX_B8jA0WhVyG2G_s-kyolra9Y2gH5e4w,6603
56
56
  absfuyu/util/zipped.py,sha256=CU_le1MynFwHfpajCRRJ7_A-r1jfMjt9uu72jLooW6w,3111
57
- absfuyu-4.1.0.dist-info/METADATA,sha256=xcjNv6lMttGHr7okEXP4HHZ2V2hGAhFV74q_zpBDBMw,3794
58
- absfuyu-4.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
59
- absfuyu-4.1.0.dist-info/entry_points.txt,sha256=bW5CgJRTTWJ2Pywojo07sf-YucRPcnHzMmETh5avbX0,79
60
- absfuyu-4.1.0.dist-info/licenses/LICENSE,sha256=pFCHBSNSzdXwYG1AHpq7VcofI1NMQ1Fc77RzZ4Ln2O4,1097
61
- absfuyu-4.1.0.dist-info/RECORD,,
57
+ absfuyu-4.1.1.dist-info/METADATA,sha256=dJJP-975rfpiV712uDMRZXbnOhDtmLGkfAWMfriu9L0,3794
58
+ absfuyu-4.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
59
+ absfuyu-4.1.1.dist-info/entry_points.txt,sha256=bW5CgJRTTWJ2Pywojo07sf-YucRPcnHzMmETh5avbX0,79
60
+ absfuyu-4.1.1.dist-info/licenses/LICENSE,sha256=pFCHBSNSzdXwYG1AHpq7VcofI1NMQ1Fc77RzZ4Ln2O4,1097
61
+ absfuyu-4.1.1.dist-info/RECORD,,