rkt-tool-lib 1.4.1__py3-none-any.whl → 2.0.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.
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: rkt_tool_lib
3
+ Version: 2.0.0
4
+ Summary: RootKit custom tool Lib
5
+ Author-email: RootKit <rootkit@rootkit-lab.org>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.7
@@ -0,0 +1,7 @@
1
+ tool/__init__.py,sha256=oZwsPvY-eg-vtlIvJ3f6SDboDl4niL6gA-jN40Ln9Ss,34
2
+ tool/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ tool/tool.py,sha256=KmaBffj-wEUw_jdvHF4O_ewts2xlVDjm7rrEu4ZwoY4,2712
4
+ rkt_tool_lib-2.0.0.dist-info/METADATA,sha256=BAJzGHOv6cfGSQLBfe2sVVzuPOh7NfJ0Sb6UbnqQkps,306
5
+ rkt_tool_lib-2.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
+ rkt_tool_lib-2.0.0.dist-info/top_level.txt,sha256=Z5SN2a_Wr-UEOwAp1ap88PiygkuvFvTwl9QNgw7baG0,5
7
+ rkt_tool_lib-2.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.1)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
tool/__init__.py CHANGED
@@ -1 +1 @@
1
- from .Tool import Tool, Singleton
1
+ from .tool import Singleton, Tool
tool/py.typed ADDED
File without changes
tool/tool.py ADDED
@@ -0,0 +1,84 @@
1
+ import os
2
+ from typing import Any, Optional
3
+
4
+
5
+ class Singleton(type):
6
+ """
7
+ The Singleton class can be implemented in different ways in Python. Some
8
+ possible methods include: base class, decorator, metaclass. We will use the
9
+ metaclass because it is best suited for this purpose.
10
+ """
11
+
12
+ _instances: dict[type, object] = {}
13
+
14
+ def __call__(cls, *args: Any, **kwargs: Any) -> Any:
15
+ """
16
+ Possible changes to the value of the `__init__` argument do not affect
17
+ the returned instance.
18
+ """
19
+ if cls not in cls._instances:
20
+ instance = super().__call__(*args, **kwargs)
21
+ cls._instances[cls] = instance
22
+ return cls._instances[cls]
23
+
24
+
25
+ class Tool:
26
+ """
27
+ Utility class for file system operations.
28
+
29
+ Provides cross-platform methods for path formatting and recursive directory searching.
30
+ """
31
+
32
+ @staticmethod
33
+ def formatted_from_os(path: str) -> str:
34
+ """
35
+ Format a path string to match the current operating system's separator.
36
+
37
+ Args:
38
+ path (str): The path to format.
39
+
40
+ Returns:
41
+ str: The formatted path with correct separators and trailing separator handled.
42
+ """
43
+ if os.name == "nt":
44
+ sep = "\\"
45
+ res = f"{path.replace('/', sep)}{sep if path[-1] != sep else ''}"
46
+ else:
47
+ res = f"{path}{'/' if path[-1] != '/' else ''}"
48
+
49
+ return res
50
+
51
+ def get_cwd(self) -> str:
52
+ """
53
+ Get the current working directory, formatted for the OS.
54
+
55
+ Returns:
56
+ str: Absolute path of the CWD.
57
+ """
58
+ return self.formatted_from_os(os.getcwd())
59
+
60
+ def get_dir(self, folder: str, root: Optional[str] = None) -> Optional[str]:
61
+ """
62
+ Recursively search for a directory by name.
63
+
64
+ Args:
65
+ folder (str): The name of the directory to find.
66
+ root (Optional[str], optional): The root directory to start searching from.
67
+ If None, uses current working directory. Defaults to None.
68
+
69
+ Returns:
70
+ Optional[str]: Absolute path to the found directory, or None if not found.
71
+ """
72
+ root = self.get_cwd() if not root else self.formatted_from_os(root)
73
+
74
+ for element in os.listdir(root):
75
+ if os.path.isdir(f"{root}{element}") and element == folder:
76
+ return self.formatted_from_os(f"{root}{element}")
77
+
78
+ for element in os.listdir(root):
79
+ if os.path.isdir(f"{root}{element}"):
80
+ found = self.get_dir(folder, self.formatted_from_os(f"{root}{element}"))
81
+ if found:
82
+ return found
83
+
84
+ return None
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Dabo Ross
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,81 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: rkt-tool-lib
3
- Version: 1.4.1
4
- Summary: RootKit custom tool Lib
5
- Author: RootKit
6
- Author-email: rootkit@rootkit-lab.org
7
- Classifier: Development Status :: 5 - Production/Stable
8
- Classifier: Intended Audience :: Developers
9
- Classifier: Intended Audience :: End Users/Desktop
10
- Classifier: Intended Audience :: Information Technology
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Natural Language :: English
13
- Classifier: Natural Language :: French
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3.7
16
- Classifier: Topic :: Utilities
17
- Requires-Python: >=3.7
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
-
21
- # rkt_tool_lib - Python library
22
-
23
- ![Package Version](https://badgen.net/badge/Package%20Version/latest%20-%201.3.0/green?scale=1.2)
24
-
25
- ![quality](https://sonarqube.tprc.ovh/api/project_badges/measure?project=python_rkt_lib_toolkit_AXqQ32evGCA0VuRY8SuD&metric=alert_status)
26
- ![reliability_rating](https://sonarqube.tprc.ovh/api/project_badges/measure?project=python_rkt_lib_toolkit_AXqQ32evGCA0VuRY8SuD&metric=reliability_rating)
27
- ![security_rating](https://sonarqube.tprc.ovh/api/project_badges/measure?project=python_rkt_lib_toolkit_AXqQ32evGCA0VuRY8SuD&metric=security_rating)
28
- ![vulnerabilities](https://sonarqube.tprc.ovh/api/project_badges/measure?project=python_rkt_lib_toolkit_AXqQ32evGCA0VuRY8SuD&metric=vulnerabilities)
29
- ![coverage](https://sonarqube.tprc.ovh/api/project_badges/measure?project=python_rkt_lib_toolkit_AXqQ32evGCA0VuRY8SuD&metric=coverage)
30
- ![maintainability](https://sonarqube.tprc.ovh/api/project_badges/measure?project=python_rkt_lib_toolkit_AXqQ32evGCA0VuRY8SuD&metric=sqale_rating)
31
-
32
- ##### Python minimal Version 3.7
33
-
34
- ----
35
-
36
- ## What is Python?
37
- Python is an interpreted high-level general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
38
-
39
- [source](https://en.wikipedia.org/wiki/Python_(programming_language))
40
-
41
- ## Libraries
42
- * Tool: toolbox library with, you can automatically format the path in your code without worrying about the platform hosting your script
43
-
44
- ## Use it
45
- ### Install
46
- ```bash
47
- (venv) my_project> pip install rkt_tool_lib [--index-url https://gitlab.tprc.ovh/api/v4/groups/python/-/packages/pypi]
48
- ```
49
-
50
- ### Example
51
-
52
- ```python
53
- from rkt_tool_lib import Tool
54
-
55
- t = Tool()
56
-
57
- print(t.get_cwd())
58
- print(t.get_dir('db'))
59
-
60
-
61
- ```
62
-
63
- ### Output (as file, sdtout or both)
64
- windows
65
- ```log
66
- C:\Users\Me\Documents\path\to\my\project\
67
- C:\Users\Me\Documents\path\to\my\project\db\
68
- ```
69
- linux:
70
- ```log
71
- /home/me/path/to/my/project/
72
- /home/me/path/to/my/project/db/
73
- ```
74
-
75
- ## Contributing
76
-
77
- If you find this library useful here's how you can help:
78
-
79
- - Send a merge request with your kickass new features and bug fixes
80
- - Help new users with [issues](https://gitlab.tprc.ovh/python/rkt_lib_toolkit/-/issues) they may encounter
81
- - Support the development of this library and star this repo!
@@ -1,7 +0,0 @@
1
- tool/Tool.py,sha256=1wZs4KSffNCbarqdry1d5jLpHjGd-IbUaehMk9SUFe0,1635
2
- tool/__init__.py,sha256=ZBbSM-vq6CjkI93WRe0-GZ71qXo8WwHmHuZSy79EKXk,34
3
- rkt_tool_lib-1.4.1.dist-info/LICENSE,sha256=cJOcDuuCS3-_wqJQeJzXupPQBeTXBxQR858ECRPkXkw,1097
4
- rkt_tool_lib-1.4.1.dist-info/METADATA,sha256=Ap9SBDWptBsdO1DO4HqUZn3iGDtqLg1UIOEW606IuNg,3114
5
- rkt_tool_lib-1.4.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
6
- rkt_tool_lib-1.4.1.dist-info/top_level.txt,sha256=Z5SN2a_Wr-UEOwAp1ap88PiygkuvFvTwl9QNgw7baG0,5
7
- rkt_tool_lib-1.4.1.dist-info/RECORD,,
tool/Tool.py DELETED
@@ -1,53 +0,0 @@
1
- import os
2
- from typing import Optional
3
-
4
-
5
- class Singleton(type):
6
- """
7
- The Singleton class can be implemented in different ways in Python. Some
8
- possible methods include: base class, decorator, metaclass. We will use the
9
- metaclass because it is best suited for this purpose.
10
- """
11
-
12
- _instances = {}
13
-
14
- def __call__(cls, *args, **kwargs):
15
- """
16
- Possible changes to the value of the `__init__` argument do not affect
17
- the returned instance.
18
- """
19
- if cls not in cls._instances:
20
- instance = super().__call__(*args, **kwargs)
21
- cls._instances[cls] = instance
22
- return cls._instances[cls]
23
-
24
-
25
- class Tool:
26
-
27
- @staticmethod
28
- def formatted_from_os(path) -> str:
29
- if os.name == "nt":
30
- sep = "\\"
31
- res = f'{path.replace("/", sep)}{sep if path[-1] != sep else ""}'
32
- else:
33
- res = f'{path}{"/" if path[-1] != "/" else ""}'
34
-
35
- return res
36
-
37
- def get_cwd(self) -> str:
38
- return self.formatted_from_os(os.getcwd())
39
-
40
- def get_dir(self, folder, root: Optional[str] = None) -> Optional[str]:
41
- root = self.get_cwd() if not root else self.formatted_from_os(root)
42
-
43
- for element in os.listdir(root):
44
- if os.path.isdir(f"{root}{element}") and element == folder:
45
- return self.formatted_from_os(f"{root}{element}")
46
-
47
- for element in os.listdir(root):
48
- if os.path.isdir(f"{root}{element}"):
49
- found = self.get_dir(folder, self.formatted_from_os(f"{root}{element}"))
50
- if found:
51
- return found
52
-
53
- return None