Пример #1
0
 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()
Пример #2
0
def get_connection():
    if not control.existsPath(control.dataPath):
        control.makeFile(control.dataPath)
    dbcon = db.connect(
        control.cacheFile,
        timeout=60)  # added timeout 3/23/21 for concurrency with threads
    dbcon.row_factory = _dict_factory
    return dbcon
Пример #3
0
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)
Пример #4
0
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')
Пример #5
0
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
Пример #6
0
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()