Esempio n. 1
0
def HandleSocketError(e, strErrorBase):
    global latestSocketError
    errorcode = e[0]
    friendly_error_msgs = {
        errno.ECONNREFUSED:  "Connection was refused",
        errno.WSAECONNRESET: "Connection was reset or forcibly closed by the remote host",
        errno.ETIMEDOUT:     "Connection timed out"
    }
    if errorcode not in errno.errorcode:
        log_error("Unknown socket error (%s) occurred: %s" % (str(errorcode), str(e)))
        return False
    error_constant = errno.errorcode[errorcode]
    if errorcode in friendly_error_msgs:
        strError = friendly_error_msgs[errorcode]
    else:
        strError = "Unhandled socket error (%s) occurred" % error_constant
    latestSocketError = {'code': errorcode, 'friendly_error_msg': strError, 'constant': error_constant}
    strError = "Error: %s while %s\r\n" % (strError, strErrorBase)
    log_error(" SocketError.%s:  " % error_constant + strError)
    log_error(str(e))
    log(" SocketError.%s:  " % error_constant + strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
Esempio n. 2
0
def HandleSocketError(e, strErrorBase):
    global latestSocketError
    errorcode = e[0]
    friendly_error_msgs = {
        errno.ECONNREFUSED: "Connection was refused",
        errno.WSAECONNRESET:
        "Connection was reset or forcibly closed by the remote host",
        errno.ETIMEDOUT: "Connection timed out"
    }
    if errorcode not in errno.errorcode:
        log_error("Unknown socket error (%s) occurred: %s" %
                  (str(errorcode), str(e)))
        return False
    error_constant = errno.errorcode[errorcode]
    if errorcode in friendly_error_msgs:
        strError = friendly_error_msgs[errorcode]
    else:
        strError = "Unhandled socket error (%s) occurred" % error_constant
    latestSocketError = {
        'code': errorcode,
        'friendly_error_msg': strError,
        'constant': error_constant
    }
    strError = "Error: %s while %s\r\n" % (strError, strErrorBase)
    log_error(" SocketError.%s:  " % error_constant + strError)
    log_error(str(e))
    log(" SocketError.%s:  " % error_constant + strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
Esempio n. 3
0
def find_deleted_notes(automated=False):
    if not automated:
        showInfo("""In order for this to work, you must create a 'Table of Contents' Note using the Evernote desktop application. Include all notes that you want to sync with Anki.

Export this note to the following path:
<b>%s</b>

Press Okay to save and close your Anki collection, open the command-line deleted notes detection tool, and then re-open your Anki collection.

Once the command line tool is done running, you will get a summary of the results, and will be prompted to delete Anki Orphan Notes or download Missing Evernote Notes""".replace(
            '\n', '\n<br />') % FILES.USER.TABLE_OF_CONTENTS_ENEX, richText=True)
    from anknotes import find_deleted_notes
    returnedData = find_deleted_notes.do_find_deleted_notes()
    if returnedData is False:
        showInfo("An error occurred while executing the script. Please ensure you created the TOC note and saved it as instructed in the previous dialog.")
        return
    lines = returnedData['Summary']
    info = tableify_lines(lines, '#|Type|Info')
    # info = '<table><tr class=tr0><td class=t1>#</td><td class=t2>Type</td><td class=t3></td></tr>%s</table>' % '\n'.join(lines)
    # info = info.replace('\n', '\n<BR>').replace('  ', '&nbsp; &nbsp; ')
    anknotes_dels = returnedData['AnknotesOrphans']
    anknotes_dels_count = len(anknotes_dels)
    anki_dels = returnedData['AnkiOrphans']
    anki_dels_count = len(anki_dels)
    missing_evernote_notes = returnedData['MissingEvernoteNotes']
    missing_evernote_notes_count = len(missing_evernote_notes)
    showInfo(info, richText=True, minWidth=600)
    db_changed = False
    if anknotes_dels_count > 0:
        correct_code = 'ANKNOTES_DEL_%d' % anknotes_dels_count
        code = getText("Please enter code '%s' to delete your orphan Anknotes DB note(s)" % correct_code)[0]
        if code == correct_code:
            ankDB().executemany("DELETE FROM {n} WHERE guid = ?", [[x] for x in anknotes_dels])
            delete_anki_notes_and_cards_by_guid(anknotes_dels)
            db_changed = True
            show_tooltip("Deleted all %d Orphan Anknotes DB Notes" % anknotes_dels_count, 5, 3)
    if anki_dels_count > 0:
        correct_code = 'ANKI_DEL_%d' % anki_dels_count
        code = getText("Please enter code '%s' to delete your orphan Anki note(s)" % correct_code)[0]
        if code == correct_code:
            delete_anki_notes_and_cards_by_guid(anki_dels)
            db_changed = True
            show_tooltip("Deleted all %d Orphan Anki Notes" % anki_dels_count, 5, 6)
    if db_changed:
        ankDB().commit()
    if missing_evernote_notes_count > 0:
        text = "Would you like to import %d missing Evernote Notes?<BR><BR><a href='%s'>Click to view results</a>" % (
                        missing_evernote_notes_count,
                        convert_filename_to_local_link(get_log_full_path(FILES.LOGS.FDN.UNIMPORTED_EVERNOTE_NOTES, filter_disabled=False)))
        if showInfo(text, cancelButton=True, richText=True):
            import_from_evernote_manual_metadata(missing_evernote_notes)
Esempio n. 4
0
def HandleEDAMRateLimitError(e, strError):
    global latestEDAMRateLimit
    if not e.errorCode is EDAMErrorCode.RATE_LIMIT_REACHED:
        return False
    latestEDAMRateLimit = e.rateLimitDuration
    m, s = divmod(e.rateLimitDuration, 60)
    strError = "Error: Rate limit has been reached while %s\r\n" % strError
    strError += "Please retry your request in {} min".format("%d:%02d" % (m, s))
    log_strError = " EDAMErrorCode.RATE_LIMIT_REACHED:  " + strError.replace('\r\n', '\n')
    log_error(log_strError)
    log(log_strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
Esempio n. 5
0
def HandleEDAMRateLimitError(e, strError):
    global latestEDAMRateLimit
    if not e.errorCode is EDAMErrorCode.RATE_LIMIT_REACHED:
        return False
    latestEDAMRateLimit = e.rateLimitDuration
    m, s = divmod(e.rateLimitDuration, 60)
    strError = "Error: Rate limit has been reached while %s\r\n" % strError
    strError += "Please retry your request in {} min".format("%d:%02d" %
                                                             (m, s))
    log_strError = " EDAMErrorCode.RATE_LIMIT_REACHED:  " + strError.replace(
        '\r\n', '\n')
    log_error(log_strError)
    log(log_strError, 'api')
    if EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.AlertError:
        showInfo(strError)
    elif EVERNOTE.API.EDAM_RATE_LIMIT_ERROR_HANDLING is EVERNOTE.API.RateLimitErrorHandling.ToolTipError:
        show_tooltip(strError)
    return True
Esempio n. 6
0
def validate_pending_notes(showAlerts=True, uploadAfterValidation=True, callback=None, unloadedCollection=False,
                           reload_delay=10):
    if not unloadedCollection:
        return unload_collection(
        lambda *xargs, **xkwargs: validate_pending_notes(showAlerts, uploadAfterValidation, callback(*xargs, **xkwargs),
                                                         True))
    log("Validating Notes", 'automation')
    if showAlerts:
        showInfo("""Press Okay to save and close your Anki collection, open the command-line note validation tool, and then re-open your Anki collection.%s

Anki will be unresponsive until the validation tool completes. This will take at least 45 seconds.  The tool's output will be displayed upon completion. """
                 % (
                     ' You will be given the option of uploading successfully validated notes once your Anki collection is reopened.' if uploadAfterValidation else ''))
    handle = Popen(['python', FILES.SCRIPTS.VALIDATION], stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True)
    stdoutdata, stderrdata = handle.communicate()
    stdoutdata = re.sub(' +', ' ', stdoutdata)
    info = ("ERROR: {%s}<HR>" % stderrdata) if stderrdata else ''
    allowUpload = True
    if showAlerts:
        tds = [[str(count), '<a href="%s">VIEW %s VALIDATIONS LOG</a>' % (fn, key.upper())] for key, fn, count in [
            [key, get_log_full_path('MakeNoteQueue\\' + key, filter_disabled=False, as_url_link=True),
             int(re.search(r'CHECKING +(\d{1,3}) +' + key.upper() + ' MAKE NOTE QUEUE ITEMS', stdoutdata).group(1))]
            for key in ['Pending', 'Successful', 'Failed']] if count > 0]
        if not tds:
            show_tooltip("No notes found in the validation queue.")
            allowUpload = False
        else:
            info += tableify_lines(tds, '#|Results')
            successful = int(
                re.search(r'CHECKING +(\d{1,3}) +' + 'Successful'.upper() + ' MAKE NOTE QUEUE ITEMS', stdoutdata).group(
                    1))
            allowUpload = (uploadAfterValidation and successful > 0)
            allowUpload = allowUpload & showInfo("Completed: %s<BR>%s" % (
                'Press Okay to begin uploading %d successfully validated note(s) to the Evernote Servers' % successful if (
                    uploadAfterValidation and successful > 0) else '',
                info), cancelButton=(successful > 0), richText=True)
    log("Validate Notes completed", 'automation')
    if callback is None and allowUpload:
        def callback(*xa, **xkw): return upload_validated_notes()
    mw.progress.timer(reload_delay * 1000, lambda: reload_collection(callback), False)