mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-11-10 00:10:46 +08:00
Adds #124 custom orphaned path
This commit is contained in:
parent
218712fd00
commit
f2ce39f9c4
3 changed files with 16 additions and 7 deletions
|
|
@ -43,6 +43,7 @@ directory:
|
||||||
remote_dir: "/mnt/user/data/torrents/"
|
remote_dir: "/mnt/user/data/torrents/"
|
||||||
recycle_bin: "/mnt/user/data/torrents/.RecycleBin"
|
recycle_bin: "/mnt/user/data/torrents/.RecycleBin"
|
||||||
torrents_dir: "/qbittorrent/data/BT_backup"
|
torrents_dir: "/qbittorrent/data/BT_backup"
|
||||||
|
orphaned_dir: "/data/torrents/orphaned_data"
|
||||||
|
|
||||||
cat:
|
cat:
|
||||||
# Category & Path Parameters
|
# Category & Path Parameters
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,14 @@ class Config:
|
||||||
self.cross_seed_dir = self.util.check_for_attribute(self.data, "cross_seed", parent="directory", var_type="path")
|
self.cross_seed_dir = self.util.check_for_attribute(self.data, "cross_seed", parent="directory", var_type="path")
|
||||||
else:
|
else:
|
||||||
self.cross_seed_dir = self.util.check_for_attribute(self.data, "cross_seed", parent="directory", default_is_none=True)
|
self.cross_seed_dir = self.util.check_for_attribute(self.data, "cross_seed", parent="directory", default_is_none=True)
|
||||||
|
if self.commands["rem_orphaned"]:
|
||||||
|
if "orphaned_dir" in self.data["directory"] and self.data["directory"]["orphaned_dir"] is not None:
|
||||||
|
default_orphaned = os.path.join(self.remote_dir, os.path.basename(self.data['directory']['orphaned_dir'].rstrip(os.sep)))
|
||||||
|
else:
|
||||||
|
default_orphaned = os.path.join(self.remote_dir, 'orphaned_data')
|
||||||
|
self.orphaned_dir = self.util.check_for_attribute(self.data, "orphaned_dir", parent="directory", var_type="path", default=default_orphaned, make_dirs=True)
|
||||||
|
else:
|
||||||
|
self.orphaned_dir = None
|
||||||
if self.recyclebin['enabled']:
|
if self.recyclebin['enabled']:
|
||||||
if "recycle_bin" in self.data["directory"] and self.data["directory"]["recycle_bin"] is not None:
|
if "recycle_bin" in self.data["directory"] and self.data["directory"]["recycle_bin"] is not None:
|
||||||
default_recycle = os.path.join(self.remote_dir, os.path.basename(self.data['directory']['recycle_bin'].rstrip(os.sep)))
|
default_recycle = os.path.join(self.remote_dir, os.path.basename(self.data['directory']['recycle_bin'].rstrip(os.sep)))
|
||||||
|
|
|
||||||
|
|
@ -776,13 +776,14 @@ class Qbt:
|
||||||
orphaned_parent_path = set()
|
orphaned_parent_path = set()
|
||||||
remote_path = self.config.remote_dir
|
remote_path = self.config.remote_dir
|
||||||
root_path = self.config.root_dir
|
root_path = self.config.root_dir
|
||||||
|
orphaned_path = self.config.orphaned_dir
|
||||||
if (remote_path != root_path):
|
if (remote_path != root_path):
|
||||||
root_files = [os.path.join(path.replace(remote_path, root_path), name)
|
root_files = [os.path.join(path.replace(remote_path, root_path), name)
|
||||||
for path, subdirs, files in alive_it(os.walk(remote_path))
|
for path, subdirs, files in alive_it(os.walk(remote_path))
|
||||||
for name in files if os.path.join(remote_path, 'orphaned_data') not in path]
|
for name in files if orphaned_path.replace(remote_path, root_path) not in path]
|
||||||
else:
|
else:
|
||||||
root_files = [os.path.join(path, name) for path, subdirs, files in alive_it(os.walk(root_path))
|
root_files = [os.path.join(path, name) for path, subdirs, files in alive_it(os.walk(root_path))
|
||||||
for name in files if os.path.join(root_path, 'orphaned_data') not in path]
|
for name in files if orphaned_path.replace(root_path, remote_path) not in path]
|
||||||
|
|
||||||
# Get an updated list of torrents
|
# Get an updated list of torrents
|
||||||
torrent_list = self.get_torrents({'sort': 'added_on'})
|
torrent_list = self.get_torrents({'sort': 'added_on'})
|
||||||
|
|
@ -813,20 +814,19 @@ class Qbt:
|
||||||
logger.separator("Deleting Orphaned Files", space=False, border=False, loglevel='DEBUG')
|
logger.separator("Deleting Orphaned Files", space=False, border=False, loglevel='DEBUG')
|
||||||
|
|
||||||
if orphaned_files:
|
if orphaned_files:
|
||||||
dir_out = os.path.join(remote_path, 'orphaned_data')
|
os.makedirs(orphaned_path, exist_ok=True)
|
||||||
os.makedirs(dir_out, exist_ok=True)
|
|
||||||
body = []
|
body = []
|
||||||
num_orphaned = len(orphaned_files)
|
num_orphaned = len(orphaned_files)
|
||||||
logger.print_line(f"{num_orphaned} Orphaned files found", loglevel)
|
logger.print_line(f"{num_orphaned} Orphaned files found", loglevel)
|
||||||
body += logger.print_line("\n".join(orphaned_files), loglevel)
|
body += logger.print_line("\n".join(orphaned_files), loglevel)
|
||||||
body += logger.print_line(f"{'Did not move' if dry_run else 'Moved'} {num_orphaned} Orphaned files to {dir_out.replace(remote_path,root_path)}", loglevel)
|
body += logger.print_line(f"{'Did not move' if dry_run else 'Moved'} {num_orphaned} Orphaned files to {orphaned_path.replace(remote_path,root_path)}", loglevel)
|
||||||
|
|
||||||
attr = {
|
attr = {
|
||||||
"function": "rem_orphaned",
|
"function": "rem_orphaned",
|
||||||
"title": f"Removing {num_orphaned} Orphaned Files",
|
"title": f"Removing {num_orphaned} Orphaned Files",
|
||||||
"body": "\n".join(body),
|
"body": "\n".join(body),
|
||||||
"orphaned_files": list(orphaned_files),
|
"orphaned_files": list(orphaned_files),
|
||||||
"orphaned_directory": dir_out.replace(remote_path, root_path),
|
"orphaned_directory": orphaned_path.replace(remote_path, root_path),
|
||||||
"total_orphaned_files": num_orphaned,
|
"total_orphaned_files": num_orphaned,
|
||||||
}
|
}
|
||||||
self.config.send_notifications(attr)
|
self.config.send_notifications(attr)
|
||||||
|
|
@ -835,7 +835,7 @@ class Qbt:
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
for file in alive_it(orphaned_files):
|
for file in alive_it(orphaned_files):
|
||||||
src = file.replace(root_path, remote_path)
|
src = file.replace(root_path, remote_path)
|
||||||
dest = os.path.join(dir_out, file.replace(root_path, ''))
|
dest = os.path.join(orphaned_path, file.replace(root_path, ''))
|
||||||
util.move_files(src, dest)
|
util.move_files(src, dest)
|
||||||
orphaned_parent_path.add(os.path.dirname(file).replace(root_path, remote_path))
|
orphaned_parent_path.add(os.path.dirname(file).replace(root_path, remote_path))
|
||||||
for parent_path in orphaned_parent_path:
|
for parent_path in orphaned_parent_path:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue