Пример #1
0
 def check_finished(self):
     queued, finished, errors = self.multi.info_read()
     for handle in finished:
         try:
             self.pop_transfer(handle).on_finished()
         except StandardError:
             logging.stacktrace("Error calling on_finished()")
     for handle, code, message in errors:
         try:
             self.pop_transfer(handle).on_error(code, handle)
         except StandardError:
             logging.stacktrace("Error calling on_error()")
Пример #2
0
 def check_finished(self):
     queued, finished, errors = self.multi.info_read()
     for handle in finished:
         try:
             self.pop_transfer(handle).on_finished()
         except StandardError:
             logging.stacktrace("Error calling on_finished()")
     for handle, code, message in errors:
         try:
             self.pop_transfer(handle).on_error(code, handle)
         except StandardError:
             logging.stacktrace("Error calling on_error()")
Пример #3
0
    def crop_and_scale(self, src_x, src_y, src_width, src_height, dest_width,
            dest_height):
        if dest_width <= 0 or dest_height <= 0:
            logging.stacktrace("invalid dest sizes: %s %s" % (dest_width,
                    dest_height))
            return TransformedImage(self.nsimage)

        source_rect = NSMakeRect(src_x, src_y, src_width, src_height)
        dest_rect = NSMakeRect(0, 0, dest_width, dest_height)

        dest = NSImage.alloc().initWithSize_(NSSize(dest_width, dest_height))
        dest.lockFocus()
        try:
            NSGraphicsContext.currentContext().setImageInterpolation_(
                    NSImageInterpolationHigh)
            self.nsimage.drawInRect_fromRect_operation_fraction_(dest_rect,
                    source_rect, NSCompositeCopy, 1.0)
        finally:
            dest.unlockFocus()
        return TransformedImage(dest)
Пример #4
0
    def crop_and_scale(self, src_x, src_y, src_width, src_height, dest_width,
                       dest_height):
        if dest_width <= 0 or dest_height <= 0:
            logging.stacktrace("invalid dest sizes: %s %s" %
                               (dest_width, dest_height))
            return TransformedImage(self.nsimage)

        source_rect = NSMakeRect(src_x, src_y, src_width, src_height)
        dest_rect = NSMakeRect(0, 0, dest_width, dest_height)

        dest = NSImage.alloc().initWithSize_(NSSize(dest_width, dest_height))
        dest.lockFocus()
        try:
            NSGraphicsContext.currentContext().setImageInterpolation_(
                NSImageInterpolationHigh)
            self.nsimage.drawInRect_fromRect_operation_fraction_(
                dest_rect, source_rect, NSCompositeCopy, 1.0)
        finally:
            dest.unlockFocus()
        return TransformedImage(dest)
Пример #5
0
    def add_idle(self, function, name, args=None, kwargs=None):
        if args is None:
            args = ()
        if kwargs is None:
            kwargs = {}
        dc = DelayedCall(function, "idle (%s)" % (name,), args, kwargs)
        self.queue.put(dc)

        # Check if our queue size is too big and log a warning if so.  Only do
        # this a few times.  That should be enough to track down errors, but
        # not too much to kill the log file.
        #
        # NOTE: the code below doesn't take into account that this method
        # runs on multiple threads.  However, the worst that can happen is
        # we log an extra warning or two, so this doesn't seem bad.
        if self.queue_size_warning_count < 5 and self.queue.qsize() > 1000:
            if self.queue_size_warning_count < 5:
                logging.stacktrace("Queued called size too large")
                self.queue_size_warning_count += 1

        return dc
Пример #6
0
    def __iteration(self):

        if (self.__items):
            self.__priorized_pos = min(self.__priorized_pos, 
                                       len(self.__items) - 1)
            item, args = self.__items.pop(self.__priorized_pos)

            try:
                self.__handler(item, *args)
            except:
                logging.error("error in item scheduler:\n%s", logging.stacktrace())

            return True
            
        else:
            self.__scheduler = None
            return False
Пример #7
0

def trap_call(when, function, *args, **kwargs):
    """Version of trap_call for the libcurl thread.

    :retval the return value of the function, or the exception raised.
    """
    try:
        return function(*args, **kwargs)
    except (SystemExit, KeyboardInterrupt), e:
        # If we just re-raise these, then we will just crash the libcurl
        # thread.  Instead, we want to shutdown the eventloop.
        logging.warn("saw %s in libcurl thread, quitting")
        app.controller.shutdown()
    except Exception, e:
        logging.stacktrace("libcurl thread exception while %s" % when)
        eventloop.add_idle("sending exception",
                           signals.system.failed,
                           args=(when, ))
        return e


class HTTPError(NetworkError):
    def __init__(self, longDescription):
        NetworkError.__init__(self, _("HTTP error"), longDescription)


class ServerClosedConnection(HTTPError):
    def __init__(self, host):
        HTTPError.__init__(self, _('%(host)s closed connection',
                                   {"host": host}))
Пример #8
0
            app.config.get(prefs.HTTP_PROXY_PORT))

def trap_call(when, function, *args, **kwargs):
    """Version of trap_call for the libcurl thread.

    :retval the return value of the function, or the exception raised.
    """
    try:
        return function(*args, **kwargs)
    except (SystemExit, KeyboardInterrupt), e:
        # If we just re-raise these, then we will just crash the libcurl
        # thread.  Instead, we want to shutdown the eventloop.
        logging.warn("saw %s in libcurl thread, quitting")
        app.controller.shutdown()
    except Exception, e:
        logging.stacktrace("libcurl thread exception while %s" % when)
        eventloop.add_idle("sending exception", signals.system.failed,
                args=(when,))
        return e

class HTTPError(NetworkError):
    def __init__(self, longDescription):
        NetworkError.__init__(self, _("HTTP error"), longDescription)

class ServerClosedConnection(HTTPError):
    def __init__(self, host):
        HTTPError.__init__(self, _('%(host)s closed connection',
                                   {"host": host}))

class EmptyResponse(HTTPError):
    def __init__(self, host):
Пример #9
0
        elif event == gio.FILE_MONITOR_EVENT_DELETED:
            self._on_file_deleted(file_)

    def _on_file_added(self, f):
        try:
            info = f.query_info('standard::*')
        except (gio.Error, gobject.GError), e:
            logging.warn("Error calling query_info on %s: %s", f.get_path(), e)
            return
        file_type = info.get_attribute_uint32('standard::type')
        if file_type == gio.FILE_TYPE_REGULAR:
            self._send_added(f.get_path())
            try:
                content_set = self._contents[f.get_parent().get_path()]
            except KeyError:
                logging.stacktrace("Error getting content_set")
            else:
                content_set.add(f.get_basename())
        elif file_type == gio.FILE_TYPE_DIRECTORY:
            self._add_directory(f, True)

    def _on_file_deleted(self, f):
        path = f.get_path()
        if path in self._monitors:
            # file is one of the things we were monitoring.  Looks like it's a
            # directory
            del self._monitors[path]
            # send deleted events for the children
            for filename in self._contents[path]:
                self._send_deleted(f.get_child(filename).get_path())
            del self._contents[path]
Пример #10
0
            self._on_file_deleted(file_)

    def _on_file_added(self, f):
        try:
            info = f.query_info('standard::*')
        except (gio.Error, gobject.GError), e:
            logging.warn("Error calling query_info on %s: %s",
                    f.get_path(), e)
            return
        file_type = info.get_attribute_uint32('standard::type')
        if file_type == gio.FILE_TYPE_REGULAR:
            self._send_added(f.get_path())
            try:
                content_set = self._contents[f.get_parent().get_path()]
            except KeyError:
                logging.stacktrace("Error getting content_set")
            else:
                content_set.add(f.get_basename())
        elif file_type == gio.FILE_TYPE_DIRECTORY:
            self._add_directory(f, True)

    def _on_file_deleted(self, f):
        path = f.get_path()
        if path in self._monitors:
            # file is one of the things we were monitoring.  Looks like it's a
            # directory
            del self._monitors[path]
            # send deleted events for the children
            for filename in self._contents[path]:
                self._send_deleted(f.get_child(filename).get_path())
            del self._contents[path]