I have this piece of code that has been handed to me.
My question is can anyone tell me what language it is written in? Is it Python? or C++?? I think it is something along those lines?
Also, if anyone can quickly tell me roughly what the code is doing that would be EXCELLENT! I dont need a lot of details, i can look into once i know kinda what its doing...... :-/
Code:
from __future__ import nested_scopes
import os, time
def watch_directories (paths, func, delay=0.2):
all_files = {}
def f (unused, dirname, files):
for filename in files:
path = os.path.join(dirname, filename)
try:
t = os.stat(path)
except os.error:
# A file has been deleted between os.path.walk()
continue
mtime = remaining_files.get(path)
if mtime:
# Record this file as having been seen
del remaining_files[path]
# File's mtime has been changed since we last looked at it.
if t.st_mtime > mtime:
changed_list.append(path)
else:
# No recorded modification time, so it must be
# a brand new file.
changed_list.append(path)
all_files[path] = t.st_mtime
# Main loop
rescan = False
while True: #scan forever
changed_list = []
remaining_files = all_files.copy()
all_files = {}
for path in paths:
os.path.walk(path, f, None)
removed_list = remaining_files.keys()
if rescan:
rescan = False
elif changed_list or removed_list:
rescan = func(changed_list, removed_list)
print 'Changed Files', changed_list
print 'Removed', removed_list
time.sleep(delay)
import os
if __name__ == '__main__':
def f (changed_files, removed_files):
os.nice(10)
print 'Changed Files', changed_files
print 'Removed', removed_files
while True:
try:
watch_directories('/home/crmpicco/', f, 1)
##watch_directories('.', f, 1)
except KeyboardInterrupt:
print "I cant be stopped (unless you try a lot)"
Many Thanks,
Picco
www.crmpicco.co.uk
www.ie7.com