def run(self): try: xbmc.log( '[ script.module.fenomscrapers ] CheckSettingsFile Service Starting...', LOGNOTICE) window.clearProperty('fenomscrapers_settings') profile_dir = control.dataPath if not control.existsPath(profile_dir): success = control.makeDirs(profile_dir) if success: xbmc.log('%s : created successfully' % profile_dir, LOGNOTICE) else: xbmc.log('%s : already exists' % profile_dir, LOGNOTICE) settings_xml = control.joinPath(profile_dir, 'settings.xml') if not control.existsPath(settings_xml): control.setSetting('module.provider', 'Fenomscrapers') xbmc.log('%s : created successfully' % settings_xml, LOGNOTICE) else: xbmc.log('%s : already exists' % settings_xml, LOGNOTICE) return xbmc.log( '[ script.module.fenomscrapers ] Finished CheckSettingsFile Service', LOGNOTICE) except: import traceback traceback.print_exc()
def get(file): helpFile = control.joinPath(fenomscrapers_path, 'lib', 'fenomscrapers', 'help', file + '.txt') r = open(helpFile) text = r.read() r.close() control.dialog.textviewer( '[COLOR red]Fenomscrapers[/COLOR] - v%s - %s' % (fenomscrapers_version, file), text)
def log(msg, caller=None, level=LOGNOTICE): debug_enabled = getSetting('debug.enabled') == 'true' if not debug_enabled: return debug_location = getSetting('debug.location') if isinstance(msg, int): msg = lang(msg) # for strings.po translations try: if py_tools.isPY3: if not msg.isprintable( ): # ex. "\n" is not a printable character so returns False on those sort of cases msg = '%s (NORMALIZED by log_utils.log())' % normalize(msg) if isinstance(msg, py_tools.binary_type): msg = '%s (ENCODED by log_utils.log())' % (py_tools.ensure_str( msg, errors='replace')) else: if not is_printable( msg ): # if not all(c in printable for c in msg): # isprintable() not available in py2 msg = normalize(msg) if isinstance(msg, py_tools.binary_type): msg = '%s (ENCODED by log_utils.log())' % ( py_tools.ensure_text(msg)) if caller == 'scraper_error': pass elif caller is not None and level != LOGERROR: func = inspect.currentframe().f_back.f_code line_number = inspect.currentframe().f_back.f_lineno caller = "%s.%s()" % (caller, func.co_name) msg = 'From func name: %s Line # :%s\n msg : %s' % ( caller, line_number, msg) elif caller is not None and level == LOGERROR: msg = 'From func name: %s.%s() Line # :%s\n msg : %s' % ( caller[0], caller[1], caller[2], msg) if debug_location == '1': log_file = joinPath(LOGPATH, 'fenomscrapers.log') if not existsPath(log_file): f = open(log_file, 'w') f.close() with open(log_file, 'a', encoding='utf-8') as f: #with auto cleans up and closes line = '[%s %s] %s: %s' % ( datetime.now().date(), str(datetime.now().time())[:8], DEBUGPREFIX % debug_list[level], msg) f.write(line.rstrip('\r\n') + '\n') # f.writelines([line1, line2]) ## maybe an option for the 2 lines without using "\n" else: xbmc.log('%s: %s' % (DEBUGPREFIX % debug_list[level], msg, level)) except Exception as e: import traceback traceback.print_exc() xbmc.log( '[ script.module.fenomonscrapers ] log_utils.log() Logging Failure: %s' % (e), LOGERROR)
def get(): fenomscrapers_path = addonPath() fenomscrapers_version = addonVersion() changelogfile = joinPath(fenomscrapers_path, 'changelog.txt') r = open(changelogfile, 'r', encoding='utf-8', errors='ignore') text = r.read() r.close() heading = '[B]FenomScrapers - v%s - ChangeLog[/B]' % fenomscrapers_version windows = TextViewerXML('textviewer.xml', fenomscrapers_path, heading=heading, text=text) windows.run() del windows
def upload_LogFile(): from fenomscrapers.modules.control import notification url = 'https://paste.kodi.tv/' log_file = joinPath(LOGPATH, 'fenomscrapers.log') if not existsPath(log_file): return notification( message='Log File not found, likely logging is not enabled.') try: import requests from fenomscrapers.modules.control import addonVersion, selectDialog f = open(log_file, 'r', encoding='utf-8', errors='ignore') text = f.read() f.close() UserAgent = 'FenomScrpaers %s' % addonVersion() response = requests.post(url + 'documents', data=text.encode('utf-8', errors='ignore'), headers={'User-Agent': UserAgent}) # log('log_response: ' + str(response)) if 'key' in response.json(): result = url + response.json()['key'] log('FenomScrapers log file uploaded to: %s' % result) from sys import platform as sys_platform supported_platform = any(value in sys_platform for value in ['win32', 'linux2']) highlight_color = 'gold' list = [ ('[COLOR %s]url:[/COLOR] %s' % (highlight_color, str(result)), str(result)) ] if supported_platform: list += [('[COLOR %s] -- Copy url To Clipboard[/COLOR]' % highlight_color, ' ')] select = selectDialog([i[0] for i in list], lang(32059)) if 'Copy url To Clipboard' in list[select][0]: from fenomscrapers.modules.source_utils import copy2clip copy2clip(list[select - 1][1]) elif 'message' in response.json(): notification(message='FenomScrapers Log upload failed: %s' % str(response.json()['message'])) log('FenomScrapers Log upload failed: %s' % str(response.json()['message']), level=LOGERROR) else: notification(message='FenomScrapers Log upload failed') log('FenomScrapers Log upload failed: %s' % response.text, level=LOGERROR) except: error('FenomScrapers log upload failed') notification(message='pastebin post failed: See log for more info')
def get(file): fenomscrapers_path = addonPath() fenomscrapers_version = addonVersion() helpFile = joinPath(fenomscrapers_path, 'lib', 'fenomscrapers', 'help', file + '.txt') r = open(helpFile, 'r', encoding='utf-8', errors='ignore') text = r.read() r.close() heading = '[B]FenomScrapers - v%s - %s[/B]' % (fenomscrapers_version, file) windows = TextViewerXML('textviewer.xml', fenomscrapers_path, heading=heading, text=text) windows.run() del windows
def clear_logFile(): cleared = False try: from fenomscrapers.modules.control import yesnoDialog if not yesnoDialog(lang(32060), '', ''): return 'canceled' log_file = joinPath(LOGPATH, 'fenomscrapers.log') if not existsPath(log_file): f = open(log_file, 'w') return f.close() f = open(log_file, 'r+') f.truncate(0) # need '0' when using r f.close() cleared = True except Exception as e: import xbmc xbmc.log( '[ script.module.fenomonscrapers ] log_utils.clear_logFile() Failure: %s' % (e), LOGERROR) cleared = False return cleared
def view_LogFile(name): try: from fenomscrapers.windows.textviewer import TextViewerXML from fenomscrapers.modules.control import addonPath log_file = joinPath(LOGPATH, '%s.log' % name.lower()) if not existsPath(log_file): from fenomscrapers.modules.control import notification return notification( message='Log File not found, likely logging is not enabled.') f = open(log_file, 'r', encoding='utf-8', errors='ignore') text = f.read() f.close() heading = '[B]%s - LogFile[/B]' % name windows = TextViewerXML('textviewer.xml', addonPath(), heading=heading, text=text) windows.run() del windows except: error()
# -*- coding: utf-8 -*- """ Fenomscrapers Module """ from fenomscrapers.modules import control fenomscrapers_path = control.addonPath() fenomscrapers_version = control.addonVersion() changelogfile = control.joinPath(fenomscrapers_path, 'changelog.txt') def get(): r = open(changelogfile) text = r.read() r.close() control.dialog.textviewer( '[COLOR red]Fenomscrapers[/COLOR] - v%s - ChangeLog' % fenomscrapers_version, text)