additional error handling

This commit is contained in:
bobokun 2021-12-13 17:04:43 -05:00
parent c126962150
commit 6e996c6034
No known key found for this signature in database
GPG key ID: 9665BA6CF5DC2671
3 changed files with 35 additions and 27 deletions

View file

@ -41,11 +41,12 @@ class Config:
util.print_stacktrace()
raise Failed(f"YAML Error: {e}")
if self.data["cat"] is None: self.data["cat"] = {}
if self.data["tags"] is None: self.data["tags"] = {}
self.session = requests.Session()
#nohardlinks
self.nohardlinks = None
if "nohardlinks" in self.data:
if "nohardlinks" in self.data and self.args['tag_nohardlinks']:
self.nohardlinks = {}
for cat in self.data["nohardlinks"]:
if cat in list(self.data["cat"].keys()):
@ -58,7 +59,7 @@ class Config:
raise Failed(f"Config Error: Category {cat} is defined under nohardlinks attribute but is not defined in the cat attriute.")
else:
if self.args["tag_nohardlinks"]:
raise Failed("C onfig Error: nohardlinks attribute not found")
raise Failed("Config Error: nohardlinks attribute not found")
#Add RecycleBin
self.recyclebin = {}
@ -125,11 +126,13 @@ class Config:
# If using Format 1
if isinstance(tag_details,str):
tags['new_tag'] = self.util.check_for_attribute(self.data, tag_url, parent="tags",default=default_tag)
if tags['new_tag'] == default_tag: self.data['tags'][tag_url] = default_tag
# Using Format 2
else:
if 'tag' not in tag_details:
logger.warning(f'No tags defined for {tag_url}. Please check your config.yml file. Setting tag to {tag_url}')
tags['new_tag'] = self.util.check_for_attribute(self.data, "tag", parent="tags", subparent=tag_url, default=tag_url)
tags['new_tag'] = self.util.check_for_attribute(self.data, "tag", parent="tags", subparent=tag_url, default=tag_url)
if tags['new_tag'] == tag_url: self.data['tags'][tag_url]['tag'] = tag_url
tags['max_ratio'] = self.util.check_for_attribute(self.data, "max_ratio", parent="tags", subparent=tag_url, var_type="float", default_int=-2, default_is_none=True,do_print=False)
tags['max_seeding_time'] = self.util.check_for_attribute(self.data, "max_seeding_time", parent="tags", subparent=tag_url, var_type="int", default_int=-2, default_is_none=True,do_print=False)
tags['limit_upload_speed'] = self.util.check_for_attribute(self.data, "limit_upload_speed", parent="tags", subparent=tag_url, var_type="int", default_int=-1, default_is_none=True,do_print=False)
@ -137,6 +140,7 @@ class Config:
if tags['url']:
default_tag = tags['url'].split('/')[2].split(':')[0]
tags['new_tag'] = self.util.check_for_attribute(self.data, default_tag, parent="tags",default=default_tag)
self.data['tags'][str(default_tag)] = default_tag
logger.warning(f'No tags matched for {tags["url"]}. Please check your config.yml file. Setting tag to {default_tag}')
return (tags)
@ -152,8 +156,8 @@ class Config:
break
if not category:
default_cat = path.split('/')[-2]
self.util.check_for_attribute(self.data, default_cat, parent="cat",default=path)
category = default_cat
category = self.util.check_for_attribute(self.data, default_cat, parent="cat",default=path)
self.data['cat'][str(default_cat)] = path
logger.warning(f'No categories matched for the save path {path}. Check your config.yml file. - Setting category to {default_cat}')
return category

View file

@ -12,7 +12,7 @@ logger = logging.getLogger("qBit Manage")
class Qbt:
def __init__(self, config, params):
self.config = config
config_handler.set_global(length=self.config.args['screen_width'])
config_handler.set_global(bar=None, receipt_text=False)
self.host = params["host"]
self.username = params["username"]
self.password = params["password"]
@ -185,26 +185,26 @@ class Qbt:
continue
for torrent in alive_it(torrent_list):
tags = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith('http')])
if not nohardlinks[category]['exclude_tags']:
if any(tag in torrent.tags for tag in nohardlinks[category]['exclude_tags']):
#Skip to the next torrent if we find any torrents that are in the exclude tag
continue
#Checks for any hard links and not already tagged
if util.nohardlink(torrent['content_path'].replace(root_dir,remote_dir)):
#Will only tag new torrents that don't have noHL tag
if 'noHL' not in torrent.tags :
num_tags += 1
print_line(util.insert_space(f'Torrent Name: {torrent.name}',3),loglevel)
print_line(util.insert_space(f'Added Tag: noHL',6),loglevel)
print_line(util.insert_space(f'Tracker: {tags["url"]}',8),loglevel)
self.set_tags_and_limits(torrent, nohardlinks[category]["max_ratio"], nohardlinks[category]["max_seeding_time"],tags='noHL')
#Cleans up previously tagged noHL torrents
else:
# Deletes torrent with data if cleanup is set to true and meets the ratio/seeding requirements
if (nohardlinks[category]['cleanup'] and torrent.state_enum.is_paused and len(nohardlinks[category])>0):
print_line(f'Torrent Name: {torrent.name} has no hard links found and meets ratio/seeding requirements.',loglevel)
print_line(util.insert_space(f"Cleanup flag set to true. {'Not Deleting' if dry_run else 'Deleting'} torrent + contents.",6),loglevel)
tdel_dict[torrent.name] = torrent['content_path'].replace(root_dir,root_dir)
if any(tag in torrent.tags for tag in nohardlinks[category]['exclude_tags']):
#Skip to the next torrent if we find any torrents that are in the exclude tag
continue
else:
#Checks for any hard links and not already tagged
if util.nohardlink(torrent['content_path'].replace(root_dir,remote_dir)):
#Will only tag new torrents that don't have noHL tag
if 'noHL' not in torrent.tags :
num_tags += 1
print_line(util.insert_space(f'Torrent Name: {torrent.name}',3),loglevel)
print_line(util.insert_space(f'Added Tag: noHL',6),loglevel)
print_line(util.insert_space(f'Tracker: {tags["url"]}',8),loglevel)
self.set_tags_and_limits(torrent, nohardlinks[category]["max_ratio"], nohardlinks[category]["max_seeding_time"],tags='noHL')
#Cleans up previously tagged noHL torrents
else:
# Deletes torrent with data if cleanup is set to true and meets the ratio/seeding requirements
if (nohardlinks[category]['cleanup'] and torrent.state_enum.is_paused and len(nohardlinks[category])>0):
print_line(f'Torrent Name: {torrent.name} has no hard links found and meets ratio/seeding requirements.',loglevel)
print_line(util.insert_space(f"Cleanup flag set to true. {'Not Deleting' if dry_run else 'Deleting'} torrent + contents.",6),loglevel)
tdel_dict[torrent.name] = torrent['content_path'].replace(root_dir,root_dir)
#Checks to see if previous noHL tagged torrents now have hard links.
if (not (util.nohardlink(torrent['content_path'].replace(root_dir,root_dir))) and ('noHL' in torrent.tags)):
num_untag += 1

View file

@ -26,6 +26,9 @@ class check:
if subparent is not None:
if data and parent in data and subparent in data[parent]:
data = data[parent][subparent]
else:
data = None
do_print = False
else:
if data and parent in data:
data = data[parent]
@ -62,6 +65,7 @@ class check:
else:
endline = ""
yaml.round_trip_dump(loaded_config, open(self.config.config_path, "w"), indent=None, block_seq_indent=2)
if default_is_none and var_type in ["list", "int_list"]: return []
elif data[attribute] is None:
if default_is_none and var_type == "list":
return []