예제 #1
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)
예제 #2
0
    def run(self):
        xbmc.log(
            '[ script.module.fenomscrapers ]  Addon checking available updates',
            LOGNOTICE)
        try:
            import re
            import requests
            repo_xml = requests.get(
                'https://raw.githubusercontent.com/mr-kodi/repository.fenomscrapers/master/zips/addons.xml'
            )
            if not repo_xml.status_code == 200:
                return xbmc.log(
                    '[ script.module.fenomscrapers ]  Could not connect to remote repo XML: status code = %s'
                    % repo_xml.status_code, LOGNOTICE)
            repo_version = re.search(
                r'<addon id=\"script.module.fenomscrapers\".*version=\"(\d*.\d*.\d*)\"',
                repo_xml.text, re.I).group(1)
            local_version = control.addonVersion(
            )[:
              5]  # 5 char max so pre-releases do try to compare more chars than github version

            def check_version_numbers(
                current, new
            ):  # Compares version numbers and return True if github version is newer
                current = current.split('.')
                new = new.split('.')
                step = 0
                for i in current:
                    if int(new[step]) > int(i): return True
                    if int(i) > int(new[step]): return False
                    if int(i) == int(new[step]):
                        step += 1
                        continue
                return False

            if check_version_numbers(local_version, repo_version):
                while control.condVisibility('Library.IsScanningVideo'):
                    control.sleep(10000)
                xbmc.log(
                    '[ script.module.fenomscrapers ]  A newer version is available. Installed Version: v%s, Repo Version: v%s'
                    % (local_version, repo_version), LOGNOTICE)
                control.notification(message=control.lang(32037) %
                                     repo_version,
                                     time=5000)
            return xbmc.log(
                '[ script.module.fenomscrapers ]  Addon update check complete',
                LOGNOTICE)
        except:
            import traceback
            traceback.print_exc()
예제 #3
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')
예제 #4
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