python - PyGTK/GIO: monitor directory for changes recursively -


Take the following demo code (from this question), which uses GIO to track a directory: Import Gio Def directory_changed (monitor, file1, do2, evt_type): print "changed:", file1, 2, evt_type, gfile = gio.file (".") Monitor = Gfile.monitor_directory (Gio .FILE_MONITOR_NONE, none) monitor.connect ("revenge", directory_changed) import slipper mlitter = glib.MainLoop () ml.run ()

to run this code After that, I can create and modify the hair nodes. To switch to and informed about the changes. However, it only works for immediate children (I know that Docs does not say otherwise) The end result of the following shell commands will not be in a notification:

  An MKDIR two touch two / three The easiest way to touch  

is this recurring? I would rather not manually code such a code that I see for directory construction and connects to a monitor, removed on removal etc.

Intentional VCS file is for browser extension, which can be able to cache the status of the files in the copy and update them on different changes so that anywhere from tens of thousands to thousands (or More) To monitor directories, I just want to find the root of the copy of the work and I'll add the file monitor there.

I know, but I'm avoiding this so that it is non-Linux kernel like FreeBSD or ... to others as far as I know where the GOO file monitor is available, where available below , And I can not understand the emphasis on implementing some digital retention, but I suggested that it should be possible.

(If this is the case, then I originally posted it.)

I'm not sure that GIO allows you to get more than one monitor in one go, but if it does not happen, then you can not do anything like this:

  Import import os def directory_changed (monitor, file1, file2, evt_type): if os.path.isdir (file2): # should it be file1? Add_monitor (make 2) print "changed:", file1, do2, evt_type def add_monitor (dir): monitor gfile = gio.file (dir) = gfile.monitor_directory (gio.FILE_MONITOR_NONE, none) monitor.connect (" Change ", directory_changed) add_monitor ('.') Import slipper ml = glib.MainLoop () ml.run ()  

* When I say that there is no reason, there is possibility It could become a resource hog that is, although I could not really say with almost zero knowledge of GIO. It is also possible to roll your own self into dragon with some commands (with oslistdir among others). It may seem like something

  import time imported OS class See (object): def __init __ (self): self.dirs = [] self.snapshots = {} def add_dir (self, dir): self.dirs.append (dir) def check_for_changes (auto, dir): snapshot = Self.snapshots.get (dir) curstate = os.listdir (dir) if not snapshot: self.snapshots [dir] = rest curstate: if not snapshot == curstate: print 'change:', change in set (curstate) Symmetric_difference (set (snapshot)) : If os.path.isdir (change): print "isdir" self.add_dir (change) print changes, auto Snapshots [Dior] = Curtust Print Diff Menloof (Self): If Lane (Self Divers) & lt; 1: print "error: please add a directory with add_dir ()" is correct, while return: DIR for self: self.check_for_changes (dir) time.sleep (4) # want to not be a source hog w = Watcher ( ) W.add_dir ('.') W.mainloop ()  

Comments