Return a string result with out breaking loop
Andrew
nobody at yahoo.com
Tue Aug 26 12:46:34 EDT 2008
Hi I have done this without error
:D
Yield returns the result I am looking for... however it does not
continue looping. It does the same thing as return would
any suggestions
my code is as follows
serveraddr = ('', 8888)
srvr = ThreadingServer(serveraddr, SimpleXMLRPCRequestHandler,
allow_none=True)
srvr.register_instance(theApp())
srvr.register_introspection_functions()
def watchos(path_to_watch="C:\\"):
#get path or maintain current path of app
FILE_LIST_DIRECTORY = 0x0001
try: path_to_watch or "."
except: path_to_watch = "."
path_to_watch = os.path.abspath(path_to_watch)
out1 = "Watching %s at %s" % (path_to_watch, time.asctime()) + "\n\n"
# FindFirstChangeNotification sets up a handle for watching
# file changes.
while 1:
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
)
change_handle = win32file.ReadDirectoryChangesW (
hDir,
1024,
True,#Heap Size include_subdirectories,
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
)
# Loop forever, listing any file changes. The WaitFor... will
# time out every half a second allowing for keyboard interrupts
# to terminate the loop.
ACTIONS = {
1 : "Created",
2 : "Deleted",
3 : "Updated",
4 : "Renamed from something",
5 : "Renamed to something"
}
results = change_handle
for action, files in results:
full_filename = os.path.join(path_to_watch, files)
theact = ACTIONS.get(action, "Unknown")
out2 = str(full_filename) + " " + str(theact)
yield str(out2)
servg = watchos()
srvr.register_function(servg.next, 'watchos')
srvr.register_multicall_functions()
srvr.serve_forever()
More information about the Python-list
mailing list