mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-11-10 00:10:46 +08:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
a113179e48
commit
8d8e171b81
1 changed files with 9 additions and 10 deletions
|
|
@ -1,13 +1,15 @@
|
||||||
import os
|
import os
|
||||||
from multiprocessing import Pool, cpu_count
|
|
||||||
from itertools import repeat
|
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
from itertools import repeat
|
||||||
|
from multiprocessing import cpu_count
|
||||||
|
from multiprocessing import Pool
|
||||||
|
|
||||||
from modules import util
|
from modules import util
|
||||||
|
|
||||||
logger = util.logger
|
logger = util.logger
|
||||||
_config = None
|
_config = None
|
||||||
|
|
||||||
|
|
||||||
class RemoveOrphaned:
|
class RemoveOrphaned:
|
||||||
def __init__(self, qbit_manager):
|
def __init__(self, qbit_manager):
|
||||||
self.qbt = qbit_manager
|
self.qbt = qbit_manager
|
||||||
|
|
@ -49,7 +51,6 @@ class RemoveOrphaned:
|
||||||
if self.orphaned_dir not in path
|
if self.orphaned_dir not in path
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Get an updated list of torrents
|
# Get an updated list of torrents
|
||||||
logger.print_line("Removing torrent files from orphans", self.config.loglevel)
|
logger.print_line("Removing torrent files from orphans", self.config.loglevel)
|
||||||
torrent_list = self.qbt.get_torrents({"sort": "added_on"})
|
torrent_list = self.qbt.get_torrents({"sort": "added_on"})
|
||||||
|
|
@ -70,10 +71,7 @@ class RemoveOrphaned:
|
||||||
for exclude_pattern in self.config.orphaned["exclude_patterns"]
|
for exclude_pattern in self.config.orphaned["exclude_patterns"]
|
||||||
]
|
]
|
||||||
excluded_orphan_files = [
|
excluded_orphan_files = [
|
||||||
file
|
file for file in orphaned_files for exclude_pattern in exclude_patterns if fnmatch(file, exclude_pattern)
|
||||||
for file in orphaned_files
|
|
||||||
for exclude_pattern in exclude_patterns
|
|
||||||
if fnmatch(file, exclude_pattern)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
orphaned_files = set(orphaned_files) - set(excluded_orphan_files)
|
orphaned_files = set(orphaned_files) - set(excluded_orphan_files)
|
||||||
|
|
@ -103,7 +101,7 @@ class RemoveOrphaned:
|
||||||
# Delete empty directories after moving orphan files
|
# Delete empty directories after moving orphan files
|
||||||
logger.info("Cleaning up any empty directories...")
|
logger.info("Cleaning up any empty directories...")
|
||||||
if not self.config.dry_run:
|
if not self.config.dry_run:
|
||||||
with Pool(processes = cpu_count()) as pool:
|
with Pool(processes=cpu_count()) as pool:
|
||||||
orphaned_parent_path = set(pool.map(move_orphan, orphaned_files))
|
orphaned_parent_path = set(pool.map(move_orphan, orphaned_files))
|
||||||
|
|
||||||
logger.print_line("Removing orphan dirs", self.config.loglevel)
|
logger.print_line("Removing orphan dirs", self.config.loglevel)
|
||||||
|
|
@ -111,8 +109,9 @@ class RemoveOrphaned:
|
||||||
else:
|
else:
|
||||||
logger.print_line("No Orphaned Files found.", self.config.loglevel)
|
logger.print_line("No Orphaned Files found.", self.config.loglevel)
|
||||||
|
|
||||||
|
|
||||||
def move_orphan(file):
|
def move_orphan(file):
|
||||||
src = file.replace(_config.root_dir, _config.remote_dir) # Could be optimized to only run when root != remote
|
src = file.replace(_config.root_dir, _config.remote_dir) # Could be optimized to only run when root != remote
|
||||||
dest = os.path.join(_config.orphaned_dir, file.replace(_config.root_dir, ""))
|
dest = os.path.join(_config.orphaned_dir, file.replace(_config.root_dir, ""))
|
||||||
util.move_files(src, dest, True)
|
util.move_files(src, dest, True)
|
||||||
return os.path.dirname(file).replace(_config.root_dir, _config.remote_dir) # Another candidate for micro optimizing
|
return os.path.dirname(file).replace(_config.root_dir, _config.remote_dir) # Another candidate for micro optimizing
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue