Ejemplo n.º 1
0
def main():
    """The same as execfile()ing the btconsole.py script. Set the
    application title and run run() with the default banner."""
    if e32.is_ui_thread():
        import appuifw
        old_app_title=appuifw.app.title
        appuifw.app.title=u'syncandrun'
    try:
        run()
    finally:
        if e32.is_ui_thread():
            appuifw.app.title=old_app_title
Ejemplo n.º 2
0
def main(names=None):
    """The same as execfile()ing the btconsole.py script. Set the
    application title and run run() with the default banner."""
    if _s60_UI and e32.is_ui_thread():
        old_app_title = appuifw.app.title
        appuifw.app.title = u'BTConsole'
    try:
        run(None, names)
    finally:
        if _s60_UI and e32.is_ui_thread():
            appuifw.app.title = old_app_title
    print "Done."
Ejemplo n.º 3
0
def main(names=None):
    """The same as execfile()ing the btconsole.py script. Set the
    application title and run run() with the default banner."""
    if _s60_UI and e32.is_ui_thread():
        old_app_title=appuifw.app.title
        appuifw.app.title=u'BTConsole'
    try:
        run(None, names)
    finally:
        if _s60_UI and e32.is_ui_thread():
            appuifw.app.title=old_app_title
    print "Done."
Ejemplo n.º 4
0
def main():
    """The same as execfile()ing the btconsole.py script. Set the
    application title and run run() with the default banner."""
    if e32.is_ui_thread():
        import appuifw
        old_app_title = appuifw.app.title
        appuifw.app.title = u'syncandrun'
    try:
        run()
    finally:
        if e32.is_ui_thread():
            appuifw.app.title = old_app_title
Ejemplo n.º 5
0
 def readline(self):
     if not e32.is_ui_thread():
         raise IOError('Cannot call readline from non-UI thread')
     pos = self.text.get_pos()
     len = self.text.len()
     save_exit_key_handler = appuifw.app.exit_key_handler
     appuifw.app.exit_key_handler = self.stop_input
     self.input_wait_lock.wait()
     appuifw.app.exit_key_handler = save_exit_key_handler
     if self.input_stopped:
         self.text.add(u'\n')
         self.input_stopped = False
         raise EOFError
     new_pos = self.text.get_pos()
     new_len = self.text.len()
     if ((new_pos <= pos) | ((new_len - len) != (new_pos - pos))):
         new_pos = self.text.len()
         self.text.set_pos(new_pos)
         self.text.add(u'\n')
         user_input = ''
     else:
         user_input = (self.text.get(pos, new_pos - pos - 1))
     # Python 2.2's raw_input expects a plain string, not
     # a unicode object. Here we just assume utf8 encoding.
     return user_input.encode('utf8')
Ejemplo n.º 6
0
 def flush(self):
     if len(self.writebuf) > 0:
         if e32.is_ui_thread():
             self._doflush()
         else:
             self._flushgate()
         pass
Ejemplo n.º 7
0
def run_with_redirected_io(sock, func, *args, **kwargs):
    """Call func with sys.stdin, sys.stdout and sys.stderr redirected
    to the given socket, using a wrapper that implements a rudimentary
    line editor with command history. The streams are restored when
    the function exits. If this function is called from the UI thread,
    an exit key handler is installed for the duration of func's
    execution to close the socket.

    Any extra arguments are passed to the function. Return whatever
    the function returns."""
    # Redirect input and output to the socket.
    sockio=socket_stdio(sock)        
    real_io=(sys.stdin,sys.stdout,sys.stderr)
    real_rawinput=__builtins__['raw_input']
    if e32.is_ui_thread():
        import appuifw
        old_exit_key_handler=appuifw.app.exit_key_handler
        def my_exit_key_handler():
            # The standard output and standard error are redirected to
            # previous values already at this point so that we don't
            # miss any messages that the dying program may print.
            sys.stdout=real_io[1]
            sys.stderr=real_io[2]
            # Shutdown the socket to end any reads from stdin and make
            # them raise an EOFError.
            sock.shutdown(2)
            sock.close()
            if e32.is_ui_thread():
                appuifw.app.exit_key_handler=old_exit_key_handler
        appuifw.app.exit_key_handler=my_exit_key_handler
    try:
        (sys.stdin,sys.stdout,sys.stderr)=(sockio,sockio,sockio)
        # Replace the Python raw_input implementation with our
        # own. For some reason the built-in raw_input doesn't flush
        # the output stream after writing the prompt, and The Powers
        # That Be refuse to fix this. See Python bug 526382.
        __builtins__['raw_input']=_readfunc
        return func(*args,**kwargs)
    finally:
        (sys.stdin,sys.stdout,sys.stderr)=real_io
        __builtins__['raw_input']=real_rawinput
        if e32.is_ui_thread():
            appuifw.app.exit_key_handler=old_exit_key_handler
Ejemplo n.º 8
0
    def test_is_ui_thread(self):
        def modify_if_in_ui_thread():
            if e32.is_ui_thread():
                self.modify_test_data(changed_val)
            lock.signal()

        self.failUnless(e32.is_ui_thread())
        thread.start_new_thread(modify_if_in_ui_thread, ())
        lock.wait()
        self.failIfEqual(self.test_data, changed_val)
Ejemplo n.º 9
0
def run_with_redirected_io(sock, func, *args, **kwargs):
    """Call func with sys.stdin, sys.stdout and sys.stderr redirected
    to the given socket, using a wrapper that implements a rudimentary
    line editor with command history. The streams are restored when
    the function exits. If this function is called from the UI thread,
    an exit key handler is installed for the duration of func's
    execution to close the socket.

    Any extra arguments are passed to the function. Return whatever
    the function returns."""
    # Redirect input and output to the socket.
    sockio=socket_stdio(sock)        
    real_io=(sys.stdin,sys.stdout,sys.stderr)
    real_rawinput=__builtins__['raw_input']
    if _s60_UI and e32.is_ui_thread():
        old_exit_key_handler=appuifw.app.exit_key_handler
        def my_exit_key_handler():
            # The standard output and standard error are redirected to
            # previous values already at this point so that we don't
            # miss any messages that the dying program may print.
            sys.stdout=real_io[1]
            sys.stderr=real_io[2]
            # Shutdown the socket to end any reads from stdin and make
            # them raise an EOFError.
            sock.shutdown(2)
            sock.close()
            appuifw.app.exit_key_handler=old_exit_key_handler

        appuifw.app.exit_key_handler=my_exit_key_handler
    try:
        (sys.stdin,sys.stdout,sys.stderr)=(sockio,sockio,sockio)
        # Replace the Python raw_input implementation with our
        # own. For some reason the built-in raw_input doesn't flush
        # the output stream after writing the prompt, and The Powers
        # That Be refuse to fix this. See Python bug 526382.
        __builtins__['raw_input']=_readfunc
        return func(*args,**kwargs)
    finally:
        (sys.stdin,sys.stdout,sys.stderr)=real_io
        __builtins__['raw_input']=real_rawinput
        if _s60_UI and e32.is_ui_thread():
            appuifw.app.exit_key_handler=old_exit_key_handler
Ejemplo n.º 10
0
 def my_exit_key_handler():
     # The standard output and standard error are redirected to
     # previous values already at this point so that we don't
     # miss any messages that the dying program may print.
     sys.stdout=real_io[1]
     sys.stderr=real_io[2]
     # Shutdown the socket to end any reads from stdin and make
     # them raise an EOFError.
     sock.shutdown(2)
     sock.close()
     if e32.is_ui_thread():
         appuifw.app.exit_key_handler=old_exit_key_handler
Ejemplo n.º 11
0
 def readline(self):
     if not e32.is_ui_thread():
         raise IOError('Cannot call readline from non-UI thread')
     pos = self.text.get_pos()
     len = self.text.len()
     save_exit_key_handler = appuifw.app.exit_key_handler
     appuifw.app.exit_key_handler = self.stop_input
     self.input_wait_lock.wait()
     appuifw.app.exit_key_handler = save_exit_key_handler
     if self.input_stopped:
         self.text.add(u'\n')
         self.input_stopped = False
         raise EOFError
     new_pos = self.text.get_pos()
     new_len = self.text.len()
     if ((new_pos <= pos) | ((new_len - len) != (new_pos - pos))):
         new_pos = self.text.len()
         self.text.set_pos(new_pos)
         self.text.add(u'\n')
         user_input = ''
     else:
         user_input = (self.text.get(pos, new_pos - pos - 1))
     return (user_input)
Ejemplo n.º 12
0
        while not self.finished:
            cmdline = self.readline().rstrip()
            print "Received: " + cmdline
            words = cmdline.split()
            if len(words) > 0:
                cmd = words[0]
                DEBUGLOG("Running command: " + cmdline)
                self.commands.get(cmd, self.cmd_invalid)(cmdline)


if __name__ == "__main__":
    import sys
    from e32socket import *
    import e32

    if not e32.is_ui_thread():
        f = open("c:/pythonout.txt", "at")
        sys.stdout = f
        sys.stderr = f

    print "Starting server"
    use_tcp = 0

    if use_tcp:
        s = socket(AF_INET, SOCK_STREAM)
        addr = ("127.0.0.1", 1025)
        s.bind(addr)
        s.listen(1)

        while 1:
            print "Waiting"
Ejemplo n.º 13
0
    def run(self):
        self.finished=False
        while not self.finished:
            cmdline=self.readline().rstrip()
            print "Received: "+cmdline
            words=cmdline.split()
            if len(words)>0:
                cmd=words[0]
                DEBUGLOG("Running command: "+cmdline)
                self.commands.get(cmd,self.cmd_invalid)(cmdline)

if __name__ == '__main__':
    import sys
    from e32socket import *
    import e32
    if not e32.is_ui_thread():
        f=open('c:/pythonout.txt','at')
        sys.stdout=f
        sys.stderr=f

    print "Starting server"
    use_tcp=0
    
    if use_tcp:
        s=socket(AF_INET,SOCK_STREAM)
        addr=('127.0.0.1',1025)
        s.bind(addr)
        s.listen(1)
    
        while 1:
            print "Waiting"
def tell(string):
    logwrite(string)
    if e32.is_ui_thread():
        print string
        e32.ao_yield()
Ejemplo n.º 15
0
 def modify_if_in_ui_thread():
     if e32.is_ui_thread():
         self.modify_test_data(changed_val)
     lock.signal()
Ejemplo n.º 16
0
sys.stdout.write("Free/total RAM (MB): %.2f / %.2f\n" % (sysinfo.free_ram()/1024/1024,sysinfo.total_ram()/1024/1024))
 
sys.stdout.write("Total ROM (MB): %.2f \n" % (sysinfo.total_rom()/1024/1024))
 
sys.stdout.write("Free disk space C/E (MB): %.2f / %.2f\n" % (sysinfo.free_drivespace()['C:']/1024/1024,sysinfo.free_drivespace()['E:']/1024/1024))

sys.stdout.write("Python version: %s (%s, %s)\n" % (e32.pys60_version,e32.pys60_version_info[0],e32.pys60_version_info[1]))
 
sys.stdout.write("Symbian version: (%s, %s)\n" % (e32.s60_version_info[0],e32.s60_version_info[1]))
 
sys.stdout.write("Available drives: \n")
print(e32.drive_list())
 
sys.stdout.write("Inactivity time: %s\n" % e32.inactivity())
 
sys.stdout.write("Platf. sec. capabilities: \n")
print(e32.get_capabilities())

sys.stdout.write("Check WriteUserData: %s\n" % e32.has_capabilities(['WriteUserData']))
 
sys.stdout.write("Check WriteUserData and ReadUserData: "+str(e32.has_capabilities(['WriteUserData','ReadUserData']))+"\n")
 
sys.stdout.write("Check if UI thread: %s\n" % e32.is_ui_thread())
 
sys.stdout.write("Check if in emulator: %s\n" % e32.in_emulator())

sys.stdout.write("Current time: %s\n" % time.strftime("%a, %d %b %Y, %H:%M:%S", time.localtime()))

sys.stdout.write("Curent dir: %s\n" % os.getcwd())
Ejemplo n.º 17
0
def tell(string):
    logwrite(string)
    if e32.is_ui_thread():
        print string
        e32.ao_yield()