예제 #1
0
파일: echonest.py 프로젝트: ShriramK/miro
def exec_codegen(codegen_info, media_path, callback, errback):
    """Run an echonest codegen in a worker thread.

    This method should work for both ENMFP and echoprint.

    On success, callback(media_path, echonest_code) will be called.

    On error, errback(media_path, exception) will be called.
    """
    codegen_path = codegen_info['path']
    codegen_env = codegen_info.get('env')
    def thread_function():
        stdout = util.call_command(codegen_path, media_path, env=codegen_env)
        results = json.loads(stdout)
        # not sure why the code generator always returns a 1-element list, but
        # it does
        results = results[0]
        if 'error' in results:
            raise CodegenError(results['error'])
        # NOTE: both codegens return some metadata that we can use, but
        # mutagen can get the same data so let's just pay attention to the
        # code.
        return results['code']

    def thread_callback(code):
        callback(media_path, code)

    def thread_errback(error):
        errback(media_path, error)

    logging.debug("Invoking echonest codegen on %s", media_path)
    eventloop.call_in_thread(thread_callback, thread_errback, thread_function,
                             'exec echonest codegen')
예제 #2
0
파일: devices.py 프로젝트: kmshi/miro
 def copy_file(self, info, final_path):
     if info.id in self.copying:
         logging.warn('tried to copy %r twice', info)
         return
     self.copying.add(info.id)
     eventloop.call_in_thread(lambda x: self._copy_file_callback(x),
                              lambda x: None, self._copy_in_thread, self,
                              info, final_path)
예제 #3
0
파일: devices.py 프로젝트: kmshi/miro
 def copy_file(self, info, final_path):
     if info.id in self.copying:
         logging.warn('tried to copy %r twice', info)
         return
     self.copying.add(info.id)
     eventloop.call_in_thread(lambda x: self._copy_file_callback(x),
                              lambda x: None,
                              self._copy_in_thread,
                              self, info, final_path)
예제 #4
0
def exec_codegen(codegen_info, media_path, callback, errback):
    """Run an echonest codegen in a worker thread.

    This method should work for both ENMFP and echoprint.

    On success, callback(media_path, echonest_code) will be called.

    On error, errback(media_path, exception) will be called.
    """
    if cant_run_codegen():
        # use add_idle to send the errback to make the timing closer to normal
        # operations.  Some code could potentially break if the errback runs
        # before this function returns.
        eventloop.add_idle(errback,
                           'exec_codegen errback',
                           args=(CodegenNotSupported(), ))
        return

    codegen_path = codegen_info['path']
    codegen_env = codegen_info.get('env')

    def thread_function():
        stdout = util.call_command(codegen_path, media_path, env=codegen_env)
        results = json.loads(stdout)
        # not sure why the code generator always returns a 1-element list, but
        # it does
        results = results[0]
        if 'error' in results:
            raise CodegenError(results['error'])
        # NOTE: both codegens return some metadata that we can use, but
        # mutagen can get the same data so let's just pay attention to the
        # code.
        return results['code']

    def thread_callback(code):
        callback(media_path, code)

    def thread_errback(error):
        errback(media_path, error)

    logging.debug("Invoking echonest codegen on %s", media_path)
    eventloop.call_in_thread(thread_callback, thread_errback, thread_function,
                             'exec echonest codegen')
예제 #5
0
def exec_codegen(codegen_info, media_path, callback, errback):
    """Run an echonest codegen in a worker thread.

    This method should work for both ENMFP and echoprint.

    On success, callback(media_path, echonest_code) will be called.

    On error, errback(media_path, exception) will be called.
    """
    if cant_run_codegen():
        # use add_idle to send the errback to make the timing closer to normal
        # operations.  Some code could potentially break if the errback runs
        # before this function returns.
        eventloop.add_idle(errback, 'exec_codegen errback',
                           args=(CodegenNotSupported(),))
        return

    codegen_path = codegen_info['path']
    codegen_env = codegen_info.get('env')
    def thread_function():
        stdout = util.call_command(codegen_path, media_path, env=codegen_env)
        results = json.loads(stdout)
        # not sure why the code generator always returns a 1-element list, but
        # it does
        results = results[0]
        if 'error' in results:
            raise CodegenError(results['error'])
        # NOTE: both codegens return some metadata that we can use, but
        # mutagen can get the same data so let's just pay attention to the
        # code.
        return results['code']

    def thread_callback(code):
        callback(media_path, code)

    def thread_errback(error):
        errback(media_path, error)

    logging.debug("Invoking echonest codegen on %s", media_path)
    eventloop.call_in_thread(thread_callback, thread_errback, thread_function,
                             'exec echonest codegen')
예제 #6
0
파일: net.py 프로젝트: cool-RR/Miro
 def onSocketOpen(self):
     self.socket.setblocking(1)
     eventloop.call_in_thread(onSSLOpen, handleSSLError, convert_to_ssl,
                            "AsyncSSL onSocketOpen()",
                            self.socket)
예제 #7
0
파일: net.py 프로젝트: cool-RR/Miro
                trap_call(self, errback, ConnectionError(fullmsg))
        def onWriteReady():
            eventloop.remove_write_callback(self.socket)
            self.socketConnectTimeout.cancel()
            rv = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
            if rv == 0:
                trap_call(self, callback, self)
            else:
                msg = errno.errorcode.get(rv, _('Unknown Error code'))
                trap_call(self, errback, ConnectionError(msg))
            self.connectionErrback = None
        def onWriteTimeout():
            eventloop.remove_write_callback(self.socket)
            trap_call(self, errback, ConnectionTimeout(host))
            self.connectionErrback = None
        eventloop.call_in_thread(onAddressLookup, handleGetAddrInfoException,
                socket.getaddrinfo, "getAddrInfo - %s:%s" % (host, port), host, port)

    def accept_connection(self, family, host, port, callback, errback):
        def finishAccept():
            eventloop.remove_read_callback(self.socket)
            (self.socket, addr) = self.socket.accept()
            trap_call(self, callback, self)
            self.connectionErrback = None

        self.name = "Incoming %s:%s" % (host, port)
        self.connectionErrback = errback

        try:
            self.socket = socket.socket(family, socket.SOCK_STREAM)
            self.socket.bind((host, port))
        except socket.error, e:
예제 #8
0
파일: net.py 프로젝트: kfatehi/miro
 def onSocketOpen(self):
     self.socket.setblocking(1)
     eventloop.call_in_thread(onSSLOpen, handleSSLError, convert_to_ssl,
                            "AsyncSSL onSocketOpen()",
                            self.socket)
예제 #9
0
파일: net.py 프로젝트: kfatehi/miro
        def onWriteReady():
            eventloop.remove_write_callback(self.socket)
            self.socketConnectTimeout.cancel()
            rv = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
            if rv == 0:
                trap_call(self, callback, self)
            else:
                msg = errno.errorcode.get(rv, _('Unknown Error code'))
                trap_call(self, errback, ConnectionError(msg))
            self.connectionErrback = None
        def onWriteTimeout():
            eventloop.remove_write_callback(self.socket)
            trap_call(self, errback, ConnectionTimeout(host))
            self.connectionErrback = None
        eventloop.call_in_thread(onAddressLookup, handleGetAddrInfoException,
                                 socket.getaddrinfo,
                                 "getAddrInfo - %s:%s" % (host, port),
                                 host, port)

    def accept_connection(self, family, host, port, callback, errback):
        def finishAccept():
            eventloop.remove_read_callback(self.socket)
            (self.socket, addr) = self.socket.accept()
            trap_call(self, callback, self)
            self.connectionErrback = None

        self.name = "Incoming %s:%s" % (host, port)
        self.connectionErrback = errback

        try:
            self.socket = socket.socket(family, socket.SOCK_STREAM)
            self.socket.bind((host, port))