def register_addonsignals_slot(callback, signal=None, source_id=None): """Register a callback with AddonSignals for return calls""" name = signal if signal else callback.__name__ AddonSignals.registerSlot(signaler_id=source_id or IPC_ADDON_ID, signal=name, callback=callback) LOG.debug('Registered AddonSignals slot {} to {}'.format(name, callback))
def initialize_connection(self): """Checks database existence and performs first connection tests""" try: LOG.debug('Trying connection to the database {}', self.db_filename) self.conn = sql.connect(self.db_file_path, check_same_thread=False) cur = self.conn.cursor() cur.execute(str('SELECT SQLITE_VERSION()')) LOG.debug('Database connection {} was successful (SQLite ver. {})', self.db_filename, cur.fetchone()[0]) cur.row_factory = lambda cursor, row: row[0] cur.execute( str('SELECT name FROM sqlite_master WHERE type=\'table\' ' 'AND name NOT LIKE \'sqlite_%\'')) list_tables = cur.fetchall() if not list_tables: # If no tables exist create a new one self.conn.close() db_create_sqlite.create_database(self.db_file_path, self.db_filename) except sql.Error as exc: LOG.error('SQLite error {}:', exc.args[0]) raise DBSQLiteConnectionError from exc finally: if self.conn: self.conn.close()
def _notify_all_apps(self, callback_name, data=None, extra_data_app=None): for _app in self._apps: _data = deepcopy(data) if extra_data_app[0] == self._active_app: # If current app then send extra data only for this app _data.update(extra_data_app[1]) LOG.debug('Notify Kodi callback {} to {} with data: {}', callback_name, _app.DIAL_APP_NAME, _data) self._execute_notify(_app, callback_name, _data)
def _execute(executor_type, pathitems, params): """Execute an action as specified by the path""" try: executor = executor_type(params).__getattribute__( pathitems[0] if pathitems else 'root') except AttributeError as exc: raise InvalidPathError('Unknown action {}'.format( '/'.join(pathitems))) from exc LOG.debug('Invoking action: {}', executor.__name__) executor(pathitems=pathitems[1:])
def route(pathitems): """Route to the appropriate handler""" LOG.debug('Routing navigation request') root_handler = pathitems[0] if pathitems else G.MODE_DIRECTORY if root_handler == G.MODE_INSTALL: from resources.lib.navigation.install import install install(pathitems[1:], G.REQUEST_PARAMS) else: nav_handler = _get_nav_handler(root_handler, pathitems) _execute(nav_handler, pathitems[1:], G.REQUEST_PARAMS) return True
def _notify_apps(self, callback_name, data=None): if self._active_app is None: LOG.warn('Ignored Kodi callback {}, no app currently active', callback_name) return False self._mutex.acquire() LOG.debug('Notify Kodi callback {} to {} with data: {}', callback_name, self._active_app.DIAL_APP_NAME, data) ret = self._execute_notify(self._active_app, callback_name, data) self._mutex.release() return ret
def make_addonsignals_call(callname, data=None): """Make an IPC call via AddonSignals and wait for it to return. The contents of data will be expanded to kwargs and passed into the target function.""" LOG.debug('Handling AddonSignals IPC call to {}'.format(callname)) try: result = AddonSignals.makeCall(source_id=IPC_ADDON_ID, signal=callname, data=data, timeout_ms=IPC_TIMEOUT_SECS * 1000, use_timeout_exception=True) _raise_for_error(result) except AddonSignals.WaitTimeoutError: raise Exception('Addon Signals call timeout') return result
def _get_system_uuid(): uuid_value = None system = get_system_platform() if system in ['windows', 'uwp']: uuid_value = _get_windows_uuid() elif system == 'android': uuid_value = _get_android_uuid() elif system == 'linux': uuid_value = _get_linux_uuid() elif system == 'osx': # Due to OS restrictions on 'ios' and 'tvos' is not possible to use _get_macos_uuid() # See python limits in the wiki development page uuid_value = _get_macos_uuid() if not uuid_value: LOG.debug('It is not possible to get a system UUID creating a new UUID') uuid_value = _get_fake_uuid(system not in ['android', 'linux']) return str(uuid_value)
def _get_macos_uuid(): # pylint: disable=broad-except import subprocess sp_dict_values = None try: proc = subprocess.Popen( ['/usr/sbin/system_profiler', 'SPHardwareDataType', '-detaillevel', 'full', '-xml'], stdout=subprocess.PIPE) output_data = proc.communicate()[0].decode('utf-8') if output_data: sp_dict_values = _parse_osx_xml_plist_data(output_data) except Exception as exc: LOG.debug('Failed to fetch OSX/IOS system profile {}'.format(exc)) if sp_dict_values: if 'UUID' in list(sp_dict_values.keys()): return sp_dict_values['UUID'] if 'serialnumber' in list(sp_dict_values.keys()): return sp_dict_values['serialnumber'] return None
def __init__(self, params): LOG.debug('Initializing "ActionsExecutor" with params: {}', params) self.params = params
def make_http_request(url): LOG.debug('Execute HTTP request to: {}', url) return urlopen(Request(url), timeout=10).read()
def __init__(self, params): LOG.debug('Initializing "Directory" with params: {}', params) self.params = params
def create_database(db_file_path, db_filename): LOG.debug('The SQLite database {} is empty, creating tables', db_filename) _create_local_database(db_file_path)