예제 #1
0
def receiver(sock):
    """ Receives stuff from the client, forwards it to either the watcher or the listener """
    try:
        rpdb2.settrace()
        while True:
            message = []
            byte = sock.recv(1)
            if byte in ('L','W'): #header
                while byte != chr(255):
                    byte = sock.recv(1)
                    message.append(byte)
            else: #raw data
                n = struct.unpack("H",sock.recv(2))[0]
                while len(message) < n:
                    message.extend(list(sock.recv(n-len(message))))
                
            if byte in ('W','w'): #for watcher
                g.watchersockbuffer.extend(message)
                g.wrecv.extend(list(byte+struct.pack("H",n))+message)
            else: #for listener
                g.listenersockbuffer.extend(message)
                g.lrecv.extend(list(byte+struct.pack("H",n))+message)
    except:
        traceback.print_exc()
        thread.interrupt_main()
예제 #2
0
def watcher():
    try:
        rpdb2.settrace()
        #print "watcher invoked"
        #Thanks to Tim Golden for most of this code: http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
        ACTIONS = {
        1 : "C",  #CREATED
        2 : "D",  #DELETED
        3 : "U",  #UPDATED
        4 : "F",  #RENAMED FROM
        5 : "T"   #RENAMED TO
        }
        
        FILE_LIST_DIRECTORY = 0x0001

        path_to_watch = g.watchpath
        hDir = win32file.CreateFile (
        path_to_watch,
        FILE_LIST_DIRECTORY,
        win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
        None,
        win32con.OPEN_EXISTING,
        win32con.FILE_FLAG_BACKUP_SEMANTICS,
        None
        )
        while True:
            #
            # ReadDirectoryChangesW takes a previously-created
            #  handle to a directory, a buffer size for results,
            #  a flag to indicate whether to watch subtrees and
            #  a filter of what changes to notify.
            results = win32file.ReadDirectoryChangesW (
            hDir,
            2048,
            True,
            win32con.FILE_NOTIFY_CHANGE_FILE_NAME |
            win32con.FILE_NOTIFY_CHANGE_DIR_NAME |
            win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES |
            win32con.FILE_NOTIFY_CHANGE_SIZE |
            win32con.FILE_NOTIFY_CHANGE_LAST_WRITE |
            win32con.FILE_NOTIFY_CHANGE_SECURITY,
            None,
            None
            )
            results = [(ACTIONS[action],os.path.join(g.watchpath,str(path))) for action, path in results]
            #                                                     ^ (paths are in unicode by default)
            results = [event for event in results if not event[1] in g.ignorefiles]
            if not results:
                continue #the events were all things we should ignore
            g.timeline.append((time.clock(),results))
            if not g.events:
                thread.start_new_thread(timer,())
            g.events.extend(results)
    except:
        traceback.print_exc()
        thread.interrupt_main()
예제 #3
0
def listener(sock):
    """ Listens for updates from the server """
    try:
        rpdb2.settrace()
        while True:
            print
            ##print "Listener is listening..."
            TYPE, args = receive_header(sock)
            ##print "got header", TYPE, args
            handlers[TYPE](sock,*args)
            ##print "dealt with it"
    except:
        traceback.print_exc()
        thread.interrupt_main()
예제 #4
0
 def __call__(self, oargs=(), nargs={}):
     rpdb2.settrace()
     return self.runnable(*oargs, **nargs)
예제 #5
0
import rpdb2
#rpdb2.start_embedded_debugger("abc")

import time

for i in xrange(1024):
    print i

rpdb2.settrace()

for j in xrange(5):
    time.sleep(1)
    print j


예제 #6
0
 def __call__(self, oargs=(), nargs={}):
     rpdb2.settrace()
     return self.runnable(*oargs, **nargs)