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() util.print_stacktrace()
raise Failed(f"YAML Error: {e}") 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() self.session = requests.Session()
#nohardlinks #nohardlinks
self.nohardlinks = None self.nohardlinks = None
if "nohardlinks" in self.data: if "nohardlinks" in self.data and self.args['tag_nohardlinks']:
self.nohardlinks = {} self.nohardlinks = {}
for cat in self.data["nohardlinks"]: for cat in self.data["nohardlinks"]:
if cat in list(self.data["cat"].keys()): if cat in list(self.data["cat"].keys()):
@ -125,11 +126,13 @@ class Config:
# If using Format 1 # If using Format 1
if isinstance(tag_details,str): if isinstance(tag_details,str):
tags['new_tag'] = self.util.check_for_attribute(self.data, tag_url, parent="tags",default=default_tag) 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 # Using Format 2
else: else:
if 'tag' not in tag_details: 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}') 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_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['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) 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']: if tags['url']:
default_tag = tags['url'].split('/')[2].split(':')[0] 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) 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}') logger.warning(f'No tags matched for {tags["url"]}. Please check your config.yml file. Setting tag to {default_tag}')
return (tags) return (tags)
@ -152,8 +156,8 @@ class Config:
break break
if not category: if not category:
default_cat = path.split('/')[-2] default_cat = path.split('/')[-2]
self.util.check_for_attribute(self.data, default_cat, parent="cat",default=path) category = self.util.check_for_attribute(self.data, default_cat, parent="cat",default=path)
category = default_cat 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}') logger.warning(f'No categories matched for the save path {path}. Check your config.yml file. - Setting category to {default_cat}')
return category return category

View file

@ -12,7 +12,7 @@ logger = logging.getLogger("qBit Manage")
class Qbt: class Qbt:
def __init__(self, config, params): def __init__(self, config, params):
self.config = config 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.host = params["host"]
self.username = params["username"] self.username = params["username"]
self.password = params["password"] self.password = params["password"]
@ -185,10 +185,10 @@ class Qbt:
continue continue
for torrent in alive_it(torrent_list): for torrent in alive_it(torrent_list):
tags = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith('http')]) 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']): 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 #Skip to the next torrent if we find any torrents that are in the exclude tag
continue continue
else:
#Checks for any hard links and not already tagged #Checks for any hard links and not already tagged
if util.nohardlink(torrent['content_path'].replace(root_dir,remote_dir)): if util.nohardlink(torrent['content_path'].replace(root_dir,remote_dir)):
#Will only tag new torrents that don't have noHL tag #Will only tag new torrents that don't have noHL tag

View file

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