Skip to content

Commit 9bdc17b

Browse files
📝 Add docstrings to prep-for-piers
Docstrings generation was requested by @bossanova808. * #1 (comment) The following files were modified: * `resources/lib/cabertoss.py` * `resources/lib/clean.py` * `resources/lib/store.py`
1 parent 07fe2ec commit 9bdc17b

3 files changed

Lines changed: 45 additions & 13 deletions

File tree

resources/lib/cabertoss.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818

1919
def gather_log_files():
2020
"""
21-
Gather a list of the standard Kodi log files (Kodi.log, Kodi.old.log) and the latest crash log, if there is one.
22-
23-
@return: list of log files in form [type, path], where type is log, oldlog, or crashlog
21+
Return a list of Kodi-related log files to copy: the main log, optional old log, and recent crash log(s).
22+
23+
The function inspects the configured LOG_PATH for kodi.log and kodi.old.log and attempts to locate platform-specific crash logs
24+
(if present) in known crash-report directories. Crash logs are filtered to those modified within the last 3 days; the most
25+
recent crash file is included (Windows may include the two most recent files because crash dumps come with accompanying stack traces).
26+
27+
Returns:
28+
list: A list of entries [type, path], where `type` is one of 'log', 'oldlog', or 'crashlog' and `path` is the full filesystem path.
2429
"""
2530

2631
# Basic log files
@@ -90,10 +95,19 @@ def gather_log_files():
9095

9196
def copy_log_files(log_files: List) -> bool:
9297
"""
93-
Actually copy the log files to the path in the addon settings
94-
95-
@param log_files: List list of log files to copy
96-
@return bool: indicating success or failure
98+
Copy the provided Kodi log files into a timestamped destination folder under the configured addon destination.
99+
100+
Detailed behavior:
101+
- Expects log_files as a list of 2-element entries [type, path], where `type` is e.g. 'log', 'oldlog', or 'crashlog' and `path` is the source filesystem path.
102+
- Creates a destination directory at Store.destination_path named "<hostname>_Kodi_Logs_<YYYY-MM-DD_HH-MM-SS>".
103+
- For entries with type 'log' or 'oldlog', reads the source, sanitizes the content with clean_log(), and writes the sanitized content to a file with the same basename in the destination folder.
104+
- For other types (e.g., crash logs), copies the source file to the destination folder unchanged.
105+
106+
Parameters:
107+
log_files (List): list of log descriptors [type, path] to copy.
108+
109+
Returns:
110+
bool: True if all files were copied (and sanitized when applicable) successfully; False if the input list is empty or an error occurred during processing.
97111
"""
98112
if not log_files:
99113
Logger.error(LANGUAGE(32025))
@@ -128,6 +142,17 @@ def copy_log_files(log_files: List) -> bool:
128142

129143
# This is 'main'...
130144
def run():
145+
"""
146+
Run the log collection and copying flow: initialize logging, load configuration, gather Kodi log files, copy them to the configured destination, notify the user, and stop logging.
147+
148+
This function performs the module's main orchestration. It:
149+
- Starts the logger and loads addon configuration from settings.
150+
- If no destination path is configured, shows an error notification and skips copying.
151+
- Otherwise, notifies the user, gathers available log files, attempts to copy them to the configured destination, and notifies success (including number of files copied) or failure.
152+
- Stops the logger before returning.
153+
154+
Side effects: starts/stops the logger, reads configuration, performs filesystem operations (reading, sanitizing, and copying log files), and shows user notifications. Returns None.
155+
"""
131156
Logger.start()
132157
Store.load_config_from_settings()
133158

resources/lib/clean.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
def clean_log(content):
55
"""
6-
Remove username/password details from log file content
7-
8-
@param content:
9-
@return:
6+
Sanitize log text by replacing embedded usernames and passwords with generic placeholders.
7+
8+
Replaces URL credentials (user:pass@), contents of <user>...</user>, and <pass>...</pass> with
9+
`//USER:PASSWORD@`, `<user>USER</user>`, and `<pass>PASSWORD</pass>` respectively.
10+
11+
Parameters:
12+
content (str): Log file content to sanitize.
13+
14+
Returns:
15+
str: Sanitized content with credential data redacted.
1016
"""
1117
replaces = (('//.+?:.+?@', '//USER:PASSWORD@'), ('<user>.+?</user>', '<user>USER</user>'), ('<pass>.+?</pass>', '<pass>PASSWORD</pass>'),)
1218

resources/lib/store.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def __init__(self):
2424
@staticmethod
2525
def load_config_from_settings():
2626
"""
27-
Load in the addon settings, at start or reload them if they have been changed
28-
Log each setting as it is loaded
27+
Load the addon's logging configuration from persistent settings.
28+
29+
Reads the 'log_path' setting and assigns it to Store.destination_path, then logs the resolved path (sanitized with clean_log). This is called at startup and when settings are reloaded; it has no return value.
2930
"""
3031
Logger.info("Loading configuration from settings")
3132
Store.destination_path = ADDON.getSetting('log_path')

0 commit comments

Comments
 (0)