File size: 2,294 Bytes
27867f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
"""
MIT License
Copyright (C) 2023 ROCKY4546
https://github.com/rocky4546
This file is part of Cabernet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
"""
import json
import logging
import threading
import lib.common.utils as utils
from lib.common.decorators import handle_url_except
from lib.common.decorators import handle_json_except
class PluginPrograms:
def __init__(self, _instance_obj):
self.logger = logging.getLogger(__name__)
self.instance_obj = _instance_obj
self.config_obj = self.instance_obj.config_obj
self.instance_key = _instance_obj.instance_key
self.plugin_obj = _instance_obj.plugin_obj
self.config_section = self.instance_obj.config_section
def get_program_info(self, _prog_id):
"""
Interface method to override
"""
pass
def terminate(self):
"""
Removes all has a object from the object and calls any subclasses to also terminate
Not calling inherited class at this time
"""
self.logger = None
self.instance_obj = None
self.config_obj = None
self.instance_key = None
self.plugin_obj = None
self.config_section = None
@handle_url_except()
@handle_json_except
def get_uri_data(self, _uri, _retries, _header=None):
if _header is None:
header = {'User-agent': utils.DEFAULT_USER_AGENT}
else:
header = _header
resp = self.plugin_obj.http_session.get(_uri, headers=header, timeout=8)
x = resp.json()
resp.raise_for_status()
return x
def check_logger_refresh(self):
if not self.logger.isEnabledFor(40):
self.logger = logging.getLogger(__name__ + str(threading.get_ident()))
|