Skip to content

Commit

Permalink
Merge pull request #666 from StuffAnThings/develop
Browse files Browse the repository at this point in the history
4.1.11
  • Loading branch information
bobokun authored Oct 6, 2024
2 parents aa2c46e + 3d7b0ad commit ae22e32
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 37 deletions.
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,3 @@ repos:
language: script
pass_filenames: false
stages: [commit]
- repo: local
hooks:
- id: update-readme-version
name: Update readme version
entry: ./scripts/pre-commit/update-readme-version.sh
language: script
pass_filenames: false
stages: [commit]
13 changes: 10 additions & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Requirements Updated
- qbittorrent-api==2024.9.67
# New Updates
- Adds new config option `disable_qbt_default_share_limits` to allow qbit_manage to handle share limits and disable qbittorrent's default share limits
- Adds new config option `max_orphaned_files_to_delete` to set default safeguards against mass deletion when running remove orphaned.
- Adds new environment variables `QBT_LOG_SIZE` and `QBT_LOG_COUNT` to customize log retention (Closes #656)

**Full Changelog**: https://github.com/StuffAnThings/qbit_manage/compare/v4.1.9...v4.1.10
# Bug Fixes
- Truncates Recyclebin JSON filename when its too long. (Closes #604)
- Uses Qbittorrent's torrent export to save .torrent files for qbittorrent version > 4.5.0 (Closes #650)
- Include orphaned files and recycle bin in the list of folders to ignore when looking for noHL (Closes #660)

**Full Changelog**: https://github.com/StuffAnThings/qbit_manage/compare/v4.1.10...v4.1.11
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.10
4.1.11
5 changes: 5 additions & 0 deletions config/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ settings:
share_limits_filter_completed: True # Filters for completed torrents only when running share_limits command
tag_nohardlinks_filter_completed: True # Filters for completed torrents only when running tag_nohardlinks command
cat_update_all: True # Checks and updates all torrent categories if set to True when running cat_update command, otherwise only update torrents that are uncategorized
disable_qbt_default_share_limits: True # Allows QBM to handle share limits by disabling qBittorrents default Share limits. Only active when the share_limits command is set to True

directory:
# Do not remove these
Expand Down Expand Up @@ -276,6 +277,10 @@ orphaned:
- "/data/torrents/temp/**"
- "**/*.!qB"
- "**/*_unpackerred"
# Set your desired threshold for the maximum number of orphaned files qbm will delete in a single run. (-1 to disable safeguards)
# This will help reduce the number of accidental large amount orphaned deletions in a single run
# WARNING: Setting this variable to -1 will not safeguard against any deletions
max_orphaned_files_to_delete: 50

apprise:
# Apprise integration with webhooks
Expand Down
4 changes: 3 additions & 1 deletion docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
| `-sl` or `--share-limits` | QBT_SHARE_LIMITS | share_limits | Control how torrent share limits are set depending on the priority of your grouping. Each torrent will be matched with the share limit group with the highest priority that meets the group filter criteria. Each torrent can only be matched with one share limit group. | False |
| `-sc` or `--skip-cleanup` | QBT_SKIP_CLEANUP | skip_cleanup | Use this to skip emptying the Recycle Bin folder (`/root_dir/.RecycleBin`) and Orphaned directory. (`/root_dir/orphaned_data`) | False |
| `-dr` or `--dry-run` | QBT_DRY_RUN | dry_run | If you would like to see what is gonna happen but not actually move/delete or tag/categorize anything. | False |
| `-ll` or `--log-level LOGLEVEL` | QBT_LOG_LEVEL | N/A | Change the output log level. | INFO |
| `-ll` or `--log-level` | QBT_LOG_LEVEL | N/A | Change the output log level. | INFO |
| `-ls` or `--log-size` | QBT_LOG_SIZE | N/A | Maximum log size per file (in MB) | 10 |
| `-lc` or `--log-count` | QBT_LOG_COUNT | N/A | Maximum number of logs to keep | 5 |
| `--debug` | QBT_DEBUG | N/A | Adds debug logs | False |
| `--trace` | QBT_TRACE | N/A | Adds trace logs | False |
| `-d` or `--divider` | QBT_DIVIDER | N/A | Character that divides the sections (Default: '=') | = |
Expand Down
2 changes: 2 additions & 0 deletions docs/Config-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ This section defines any settings defined in the configuration.
| `share_limits_filter_completed` | When running `--share-limits` function, it will filter for completed torrents only. | True | <center>❌</center> |
| `tag_nohardlinks_filter_completed` | When running `--tag-nohardlinks` function, , it will filter for completed torrents only. | True | <center>❌</center> |
| `cat_update_all` | When running `--cat-update` function, it will check and update all torrents categories, otherwise it will only update uncategorized torrents. | True | <center>❌</center> |
| `disable_qbt_default_share_limits` | When running `--share-limits` function, it allows QBM to handle share limits by disabling qBittorrents default Share limits. | True | <center>❌</center> |
## **directory:**

---
Expand Down Expand Up @@ -198,6 +199,7 @@ This is handy when you have automatically generated files that certain OSs decid
| :------------------- | :------------------------------------------------------------------------------------------------------------------------------------------ | :------------- | :----------------- |
| `empty_after_x_days` | Will delete Orphaned data contents if the files have been in the Orphaned data for more than x days. (Uses date modified to track the time) | None | <center>❌</center> |
| `exclude_patterns` | List of [patterns](https://commandbox.ortusbooks.com/usage/parameters/globbing-patterns) to exclude certain files from orphaned | None | <center>❌</center> |
| `max_orphaned_files_to_delete` | This will help reduce the number of accidental large amount orphaned deletions in a single run. Set your desired threshold for the maximum number of orphaned files qbm will delete in a single run. (-1 to disable safeguards) | 50 | <center>❌</center> |
> Note: The more time you place for the `empty_after_x_days:` variable the better, allowing you more time to catch any mistakes by the script. If the variable is set to `0` it will delete contents immediately after every script run. If the variable is not set it will never delete the contents of the Orphaned Data.

## **apprise:**
Expand Down
13 changes: 13 additions & 0 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def __init__(self, default_dir, args):
logger.debug(f" --config-file (QBT_CONFIG): {args['config_files']}")
logger.debug(f" --log-file (QBT_LOGFILE): {args['log_file']}")
logger.debug(f" --log-level (QBT_LOG_LEVEL): {args['log_level']}")
logger.debug(f" --log-size (QBT_LOG_SIZE): {args['log_size']}")
logger.debug(f" --log-count (QBT_LOG_COUNT): {args['log_count']}")
logger.debug(f" --divider (QBT_DIVIDER): {args['divider']}")
logger.debug(f" --width (QBT_WIDTH): {args['screen_width']}")
logger.debug(f" --debug (QBT_DEBUG): {args['debug']}")
Expand Down Expand Up @@ -232,6 +234,9 @@ def hooks(attr):
"force_auto_tmm_ignore_tags": self.util.check_for_attribute(
self.data, "force_auto_tmm_ignore_tags", parent="settings", var_type="list", default=[]
),
"disable_qbt_default_share_limits": self.util.check_for_attribute(
self.data, "disable_qbt_default_share_limits", parent="settings", var_type="bool", default=True
),
}

self.tracker_error_tag = self.settings["tracker_error_tag"]
Expand Down Expand Up @@ -723,6 +728,14 @@ def _sort_share_limits(share_limits):
self.orphaned["exclude_patterns"] = self.util.check_for_attribute(
self.data, "exclude_patterns", parent="orphaned", var_type="list", default_is_none=True, do_print=False
)
self.orphaned["max_orphaned_files_to_delete"] = self.util.check_for_attribute(
self.data,
"max_orphaned_files_to_delete",
parent="orphaned",
var_type="int",
default=50,
min_int=-1,
)
if self.commands["rem_orphaned"]:
exclude_orphaned = f"**{os.sep}{os.path.basename(self.orphaned_dir.rstrip(os.sep))}{os.sep}*"
(
Expand Down
4 changes: 2 additions & 2 deletions modules/core/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def category(self):
new_cat.extend(self.get_tracker_cat(torrent) or self.qbt.get_category(torrent.save_path))
if not torrent.auto_tmm and torrent_category:
logger.print_line(
f"{torrent.name} has Automatic Torrent Management disabled and already has a category"
f"{torrent_category}. Skipping..",
f"{torrent.name} has Automatic Torrent Management disabled and already has the category"
f" {torrent_category}. Skipping..",
"DEBUG",
)
continue
Expand Down
18 changes: 15 additions & 3 deletions modules/core/remove_orphaned.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def rem_orphaned(self):
for fullpath in fullpathlist
]
)

orphaned_files = set(root_files.result()) - set(torrent_files)
root_files_set = set(root_files.result())
torrent_files_set = set(torrent_files)
orphaned_files = root_files_set - torrent_files_set

if self.config.orphaned["exclude_patterns"]:
logger.print_line("Processing orphan exclude patterns")
Expand All @@ -59,7 +60,18 @@ def rem_orphaned(self):

orphaned_files = set(orphaned_files) - set(excluded_orphan_files)

if orphaned_files:
# Check the threshold before deleting orphaned files
max_orphaned_files_to_delete = self.config.orphaned.get("max_orphaned_files_to_delete")
if len(orphaned_files) and len(orphaned_files) > max_orphaned_files_to_delete and max_orphaned_files_to_delete != -1:
e = (
f"Too many orphaned files detected ({len(orphaned_files)}). "
f"Max Threshold for deletion is set to {max_orphaned_files_to_delete}. "
"Aborting deletion to avoid accidental data loss."
)
self.config.notify(e, "Remove Orphaned", False)
logger.warning(e)
return
elif orphaned_files:
orphaned_files = sorted(orphaned_files)
os.makedirs(self.orphaned_dir, exist_ok=True)
body = []
Expand Down
2 changes: 1 addition & 1 deletion modules/core/tag_nohardlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def tag_nohardlinks(self):
"""Tag torrents with no hardlinks"""
logger.separator("Tagging Torrents with No Hardlinks", space=False, border=False)
nohardlinks = self.nohardlinks
check_hardlinks = util.CheckHardLinks(self.root_dir, self.remote_dir)
check_hardlinks = util.CheckHardLinks(self.config)
for category in nohardlinks:
torrent_list = self.qbt.get_torrents({"category": category, "status_filter": self.status_filter})
if len(torrent_list) == 0:
Expand Down
18 changes: 11 additions & 7 deletions modules/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def fmt_filter(record):
class MyLogger:
"""Logger class"""

def __init__(self, logger_name, log_file, log_level, default_dir, screen_width, separating_character, ignore_ghost):
def __init__(
self, logger_name, log_file, log_level, default_dir, screen_width, separating_character, ignore_ghost, log_size, log_count
):
"""Initialize logger"""
self.logger_name = logger_name
self.default_dir = default_dir
Expand All @@ -49,6 +51,8 @@ def __init__(self, logger_name, log_file, log_level, default_dir, screen_width,
self.config_handlers = {}
self.secrets = set()
self.spacing = 0
self.log_size = log_size
self.log_count = log_count
os.makedirs(self.log_dir, exist_ok=True)
self._logger = logging.getLogger(self.logger_name)
logging.DRYRUN = DRYRUN
Expand All @@ -69,13 +73,13 @@ def clear_errors(self):
"""Clear saved errors"""
self.saved_errors = []

def _get_handler(self, log_file, count=5):
def _get_handler(self, log_file):
"""Get handler for log file"""
max_bytes = 1024 * 1024 * 10
_handler = RotatingFileHandler(log_file, delay=True, mode="w", maxBytes=max_bytes, backupCount=count, encoding="utf-8")
max_bytes = 1024 * 1024 * self.log_size
_handler = RotatingFileHandler(
log_file, delay=True, mode="w", maxBytes=max_bytes, backupCount=self.log_count, encoding="utf-8"
)
self._formatter(handler=_handler)
# if os.path.isfile(log_file):
# _handler.doRollover()
return _handler

def _formatter(self, handler=None, border=True, log_only=False, space=False):
Expand All @@ -89,7 +93,7 @@ def _formatter(self, handler=None, border=True, log_only=False, space=False):

def add_main_handler(self):
"""Add main handler to logger"""
self.main_handler = self._get_handler(self.main_log, count=19)
self.main_handler = self._get_handler(self.main_log)
self.main_handler.addFilter(fmt_filter)
self._logger.addHandler(self.main_handler)

Expand Down
Loading

0 comments on commit ae22e32

Please sign in to comment.