Example #1
0
    def test_stringify(self):
        # input, handleerror, expected output if handlerror is None,
        # then it isn't passed in as an argument

        class GoodStringObject(object):
            """Object whose __str__ method returns an ASCII string."""
            def __str__(self):
                return "abc"

        class BadStringObject(object):
            """Object whose __str__ method returns a non-ASCII string."""
            def __str__(self):
                return "abc\xe4"

        for i, h, o in [
            ("", None, ""),
            ("abc", None, "abc"),
            (5, None, "5"),
            (5.5, None, "5.5"),
            (u"abc", None, "abc"),
            (u"abc\xe4", None, "abcä"),
            (u"abc\xe4", "replace", "abc?"),
                # test that bytestrings are converted to plain ASCII
            ("abc", None, "abc"),
            ("abc\xe4", None, "abc?"),
                # test that objects are converted to plain ASCII
            (GoodStringObject(), None, "abc"),
            (BadStringObject(), None, "abc?"),
        ]:

            if h == None:
                self.assertEquals(util.stringify(i), o)
            else:
                self.assertEquals(util.stringify(i, h), o)
Example #2
0
    def test_stringify(self):
        # input, handleerror, expected output if handlerror is None,
        # then it isn't passed in as an argument

        class GoodStringObject(object):
            """Object whose __str__ method returns an ASCII string."""
            def __str__(self):
                return "abc"

        class BadStringObject(object):
            """Object whose __str__ method returns a non-ASCII string."""
            def __str__(self):
                return "abc\xe4"

        for i, h, o in [
            ( "", None, ""),
            ( "abc", None, "abc"),
            ( 5, None, "5"),
            ( 5.5, None, "5.5"),
            ( u"abc", None, "abc"),
            ( u"abc\xe4", None, "abcä"),
            ( u"abc\xe4", "replace", "abc?"),
            # test that bytestrings are converted to plain ASCII
            ( "abc", None, "abc"),
            ( "abc\xe4", None, "abc\\xe4"),
            # test that objects are converted to plain ASCII
            ( GoodStringObject(), None, "abc"),
            ( BadStringObject(), None, "abc\\xe4"),
            ]:

            if h == None:
                self.assertEquals(util.stringify(i), o)
            else:
                self.assertEquals(util.stringify(i, h), o)
Example #3
0
    def test_stringify(self):
        # input, handleerror, expected output if handlerror is None,
        # then it isn't passed in as an argument

        for i, h, o in [
            ( "", None, ""),
            ( "abc", None, "abc"),
            ( 5, None, "5"),
            ( 5.5, None, "5.5"),
            ( u"abc", None, "abc"),
            ( u"abc\xe4", None, "abcä"),
            ( u"abc\xe4", "replace", "abc?")
            ]:

            if h == None:
                self.assertEquals(util.stringify(i), o)
            else:
                self.assertEquals(util.stringify(i, h), o)
Example #4
0
    def test_stringify(self):
        # input, handleerror, expected output if handlerror is None,
        # then it isn't passed in as an argument

        for i, h, o in [
            ( "", None, ""),
            ( "abc", None, "abc"),
            ( 5, None, "5"),
            ( 5.5, None, "5.5"),
            ( u"abc", None, "abc"),
            ( u"abc\xe4", None, "abcä"),
            ( u"abc\xe4", "replace", "abc?")
            ]:

            if h == None:
                self.assertEquals(util.stringify(i), o)
            else:
                self.assertEquals(util.stringify(i, h), o)
Example #5
0
 def _start_logging(self, executable, params):
     log_folder = os.path.dirname(app.config.get(prefs.LOG_PATHNAME))
     self.log_path = os.path.join(
         log_folder, "conversion-%d-to-%s.log" % (self.item_info.id, self.converter_info.identifier)
     )
     self.log_file = file(self.log_path, "w")
     self._log_progress("STARTING CONVERSION")
     self._log_progress("-> Item: %s" % util.stringify(self.item_info.name))
     self._log_progress("-> Converter used: %s" % self.converter_info.name)
     self._log_progress("-> Executable: %s" % executable)
     self._log_progress("-> Parameters: %s" % " ".join(params))
     self._log_progress("")
Example #6
0
    def _start_logging(self, executable, params):
        log_folder = os.path.dirname(app.config.get(prefs.LOG_PATHNAME))
        # replace all non-alphanumeric characters with _
        item_id = re.sub(r"\W", "_", str(self.item_info.id))

        self.log_path = os.path.join(log_folder, "conversion-%s-to-%s.log" % (item_id, self.converter_info.identifier))
        self.log_file = file(self.log_path, "w")
        self._log_progress("STARTING CONVERSION")
        self._log_progress("-> Item: %s" % util.stringify(self.item_info.name))
        self._log_progress("-> Converter used: %s" % self.converter_info.name)
        self._log_progress("-> Executable: %s" % executable)
        self._log_progress("-> Parameters: %s" % " ".join(params))
        self._log_progress("")
Example #7
0
    def _start_logging(self, executable, params):
        log_folder = os.path.dirname(app.config.get(prefs.LOG_PATHNAME))
        # replace all non-alphanumeric characters with _
        item_id = re.sub(r'\W', '_', str(self.item_info.id))

        self.log_path = os.path.join(
            log_folder, "conversion-%s-to-%s.log" %
            (item_id, self.converter_info.identifier))
        self.log_file = file(self.log_path, "w")
        self._log_progress("STARTING CONVERSION")
        self._log_progress("-> Item: %s" % util.stringify(self.item_info.name))
        self._log_progress("-> Converter used: %s" % self.converter_info.name)
        self._log_progress("-> Executable: %s" % executable)
        self._log_progress("-> Parameters: %s" % ' '.join(params))
        self._log_progress("")
Example #8
0
 def __str__(self):
     return "DialogButton(%r)" % util.stringify(self.text)
Example #9
0
 def __init__(self, path):
     msg = _("Could not write to %(filename)s",
             {"filename": util.stringify(path)})
     NetworkError.__init__(self, _('Write error'), msg)
Example #10
0
def format_crash_report(when, exc_info, details):
    header = ""
    header += "App:        %s\n" % app.config.get(prefs.LONG_APP_NAME)
    header += "Publisher:  %s\n" % app.config.get(prefs.PUBLISHER)
    header += "Platform:   %s\n" % app.config.get(prefs.APP_PLATFORM)
    header += "Python:     %s\n" % sys.version.replace("\r\n"," ").replace("\n"," ").replace("\r"," ")
    header += "Py Path:    %s\n" % repr(sys.path)
    header += "Version:    %s\n" % app.config.get(prefs.APP_VERSION)
    header += "Serial:     %s\n" % app.config.get(prefs.APP_SERIAL)
    header += "Revision:   %s\n" % app.config.get(prefs.APP_REVISION)
    header += "Builder:    %s\n" % app.config.get(prefs.BUILD_MACHINE)
    header += "Build Time: %s\n" % app.config.get(prefs.BUILD_TIME)
    header += "Time:       %s\n" % time.asctime()
    header += "When:       %s\n" % when
    header += "\n"

    if exc_info:
        header += "Exception\n---------\n"
        header += ''.join(traceback.format_exception(*exc_info))
        header += "\n"
    if details:
        header += "Details: %s\n" % (details, )
    header += "Call stack\n----------\n"
    try:
        stack = util.get_nice_stack()
    except (SystemExit, KeyboardInterrupt):
        raise
    except:
        stack = traceback.extract_stack()
    header += ''.join(traceback.format_list(stack))
    header += "\n"

    header += "Threads\n-------\n"
    header += "Current: %s\n" % threading.currentThread().getName()
    header += "Active:\n"
    for t in threading.enumerate():
        header += " - %s%s\n" % \
            (t.getName(),
             t.isDaemon() and ' [Daemon]' or '')

    # Combine the header with the logfile contents, if available, to
    # make the dialog box crash message. {{{ and }}} are Trac
    # Wiki-formatting markers that force a fixed-width font when the
    # report is pasted into a ticket.
    report = "{{{\n%s}}}\n" % header

    def read_log(logFile, logName="Log"):
        try:
            f = open(logFile, "rt")
            logContents = "%s\n---\n" % logName
            logContents += f.read()
            f.close()
        except (SystemExit, KeyboardInterrupt):
            raise
        except:
            logContents = ''
        return logContents

    logFile = app.config.get(prefs.LOG_PATHNAME)
    downloaderLogFile = app.config.get(prefs.DOWNLOADER_LOG_PATHNAME)
    if logFile is None:
        logContents = "No logfile available on this platform.\n"
    else:
        logContents = read_log(logFile)
    if downloaderLogFile is not None:
        if logContents is not None:
            logContents += "\n" + read_log(downloaderLogFile, "Downloader Log")
        else:
            logContents = read_log(downloaderLogFile)

    if logContents is not None:
        report += "{{{\n%s}}}\n" % util.stringify(logContents)

    # Dump the header for the report we just generated to the log, in
    # case there are multiple failures or the user sends in the log
    # instead of the report from the dialog box. (Note that we don't
    # do this until we've already read the log into the dialog
    # message.)
    logging.info ("----- CRASH REPORT (DANGER CAN HAPPEN) -----")
    logging.info (header)
    logging.info ("----- END OF CRASH REPORT -----")
    return report
Example #11
0
 def __init__(self, path):
     msg = _("Could not write to %(filename)s",
         {"filename": util.stringify(path)})
     NetworkError.__init__(self, _('Write error'), msg)
Example #12
0
File: net.py Project: cool-RR/Miro
 def __str__(self):
     return "%s: %s -- %s" % (self.__class__,
             util.stringify(self.getFriendlyDescription()), 
             util.stringify(self.getLongDescription()))
Example #13
0
 def handle_write_error(self, error):
     text = (_("Could not write to %(filename)s") %
             {"filename": stringify(self.filename)})
     self.handle_generic_error(text)
Example #14
0
 def handle_corrupt_torrent(self):
     self.handle_error(
         _("Corrupt Torrent"),
         _("The torrent file at %(url)s was not valid",
           {"url": stringify(self.url)})
         )
Example #15
0
File: net.py Project: kfatehi/miro
 def __str__(self):
     return "%s: %s -- %s" % (self.__class__,
             util.stringify(self.getFriendlyDescription()),
             util.stringify(self.getLongDescription()))
Example #16
0
 def __str__(self):
     return "DialogButton(%r)" % util.stringify(self.text)
Example #17
0
def format_crash_report(when, exc_info, details, log_report=True):
    header = ""
    header += "App:        %s\n" % app.config.get(prefs.LONG_APP_NAME)
    header += "Publisher:  %s\n" % app.config.get(prefs.PUBLISHER)
    header += "Platform:   %s\n" % app.config.get(prefs.APP_PLATFORM)
    header += "Python:     %s\n" % sys.version.replace("\r\n", " ").replace(
        "\n", " ").replace("\r", " ")
    header += "Py Path:    %s\n" % repr(sys.path)
    header += "Version:    %s\n" % app.config.get(prefs.APP_VERSION)
    header += "Serial:     %s\n" % app.config.get(prefs.APP_SERIAL)
    header += "Revision:   %s\n" % app.config.get(prefs.APP_REVISION)
    header += "Builder:    %s\n" % app.config.get(prefs.BUILD_MACHINE)
    header += "Build Time: %s\n" % app.config.get(prefs.BUILD_TIME)
    header += "Time:       %s\n" % time.asctime()
    header += "When:       %s\n" % when
    header += "\n"

    header += format_stack_report(details, exc_info)
    if details:
        header += "Details: %s\n" % (details, )

    header += "Threads\n-------\n"
    header += "Current: %s\n" % threading.currentThread().getName()
    header += "Active:\n"
    for t in threading.enumerate():
        isdaemon = t.isDaemon() and ' [Daemon]' or ''
        header += " - %s%s\n" % (t.getName(), isdaemon)

    header += END_HEADERS

    # Combine the header with the logfile contents, if available, to
    # make the dialog box crash message. {{{ and }}} are Trac
    # Wiki-formatting markers that force a fixed-width font when the
    # report is pasted into a ticket.
    report = "{{{\n%s}}}\n" % header

    def read_log(log_file, log_name="Log"):
        try:
            f = open(log_file, "rt")
            log_contents = "%s\n---\n" % log_name
            log_contents += f.read()
            f.close()
        except (IOError, OSError):
            log_contents = ''
        return log_contents

    log_file = app.config.get(prefs.LOG_PATHNAME)
    downloader_log_file = app.config.get(prefs.DOWNLOADER_LOG_PATHNAME)
    if log_file is None:
        log_contents = "No logfile available on this platform.\n"
    else:
        log_contents = read_log(log_file)
    if downloader_log_file is not None:
        if log_contents is not None:
            log_contents += "\n" + read_log(downloader_log_file,
                                            "Downloader Log")
        else:
            log_contents = read_log(downloader_log_file)

    if log_contents is not None:
        report += "{{{\n%s}}}\n" % util.stringify(log_contents)

    # Dump the header for the report we just generated to the log, in
    # case there are multiple failures or the user sends in the log
    # instead of the report from the dialog box. (Note that we don't
    # do this until we've already read the log into the dialog
    # message.)
    if log_report:
        logging.info("----- CRASH REPORT (DANGER CAN HAPPEN) -----")
        logging.info(header)
        logging.info("----- END OF CRASH REPORT -----")

    return report