Changeset 8da69de7c06c68aed453c8a97d49f4e64bd41711

Show
Ignore:
Timestamp:
03/31/08 19:54:30 (9 months ago)
Author:
Sebastien Martini <ookoi@…>
Parents:
9b43851fd710e7a621e8b31f157e50c23720cd53
Children:
53d2896aa1f94c5967209749f0d272412496f447
git-committer:
Sebastien Martini <ookoi@mars.(none)> / 2008-03-31T19:54:30Z+0200
Message:

New parameter 'quiet' for methods add_watch, update_watch
and rm_watch.

Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rd82238a r8da69de  
     12008-03-31  ookoi  <ookoi@mars> 
     2 
     3        * ChangeLog is now maintained directly with git: 
     4          See http://git.dbzteam.org/?p=pyinotify.git;a=log;h=HEAD 
     5 
    162008-03-24  ookoi  <ookoi@sundae> 
    27 
  • pyinotify.py

    r9b43851 r8da69de  
    5656__author__ = "seb@dbzteam.org (Sebastien Martini)" 
    5757 
    58 __version__ = "0.8.0p" 
     58__version__ = "0.8.0q" 
    5959 
    6060__metaclass__ = type  # Use new-style classes by default 
     
    865865                          poll is blocking waiting for something to read. 
    866866        @type read_freq: int 
    867         @param treshold: file descriptor will be read only if its size to 
     867        @param treshold: File descriptor will be read only if its size to 
    868868                         read is >= treshold. If != 0, you likely want to 
    869869                         use it in combination with read_freq because 
     
    10631063        seconds at best and only if the size to read is >= treshold. 
    10641064 
    1065         @param callback: functor called after each event processing. 
     1065        @param callback: Functor called after each event processing. Expects 
     1066                         to receive notifier object (self) as first parameter. 
    10661067        @type callback: callable 
    1067         @param daemonize: this thread is daemonized if set to True. 
     1068        @param daemonize: This thread is daemonized if set to True. 
    10681069        @type daemonize: boolean 
    10691070        """ 
     
    11241125                          max(0, read_freq - timeout) seconds. 
    11251126        @type read_freq: int 
    1126         @param treshold: file descriptor will be read only if its size to 
     1127        @param treshold: File descriptor will be read only if its size to 
    11271128                         read is >= treshold. If != 0, you likely want to 
    11281129                         use it in combination with read_freq because 
     
    12261227 
    12271228 
     1229class WatchManagerError(Exception): 
     1230    """ 
     1231    WatchManager Exception. Raised on error encountered on watches 
     1232    operations. 
     1233 
     1234    """ 
     1235    def __init__(self, msg, wmd): 
     1236        """ 
     1237        @param msg: Exception string's description. 
     1238        @type msg: string 
     1239        @param wmd: Results of previous operations made by the same function 
     1240                    on previous wd or paths. It also contains the item which 
     1241                    raised this exception. 
     1242        @type wmd: dict 
     1243        """ 
     1244        self.wmd = wmd 
     1245        Exception.__init__(self, msg) 
     1246 
     1247 
    12281248class WatchManager: 
    12291249    """ 
     
    12481268        wd_ = LIBC.inotify_add_watch(self._fd, path, mask) 
    12491269        if wd_ < 0: 
    1250             log.error('add_watch: cannot watch %s (WD=%d)' % (path, wd_)) 
    12511270            return wd_ 
    12521271        watch_ = Watch(wd=wd_, path=os.path.normpath(path), mask=mask, 
     
    12631282 
    12641283    def add_watch(self, path, mask, proc_fun=None, rec=False, 
    1265                   auto_add=False, do_glob=False): 
     1284                  auto_add=False, do_glob=False, quiet=True): 
    12661285        """ 
    12671286        Add watch(s) on given path(s) with the specified mask and 
     
    12851304        @param do_glob: Do globbing on pathname. 
    12861305        @type do_glob: bool 
     1306        @param quiet: if True raise an WatchManagerError exception on 
     1307                      error. See example not_quiet.py 
     1308        @type quiet: bool 
    12871309        @return: dict of paths associated to watch descriptors. A wd value 
    12881310                 is positive if the watch has been sucessfully added, 
     
    12991321                # recursively list subdirs according to rec param 
    13001322                for rpath in self.__walk_rec(apath, rec): 
    1301                     ret_[rpath] = self.__add_watch(rpath, mask, 
    1302                                                    proc_fun, auto_add) 
     1323                    wd = ret_[rpath] = self.__add_watch(rpath, mask, 
     1324                                                        proc_fun, auto_add) 
     1325                    if wd < 0: 
     1326                        err = 'add_watch: cannot watch %s (WD=%d)' % (rpath, 
     1327                                                                      wd) 
     1328                        if quiet: 
     1329                            log.error(err) 
     1330                        else: 
     1331                            raise WatchManagerError(err, ret_) 
    13031332        return ret_ 
    13041333 
     
    13391368 
    13401369    def update_watch(self, wd, mask=None, proc_fun=None, rec=False, 
    1341                      auto_add=False): 
     1370                     auto_add=False, quiet=True): 
    13421371        """ 
    13431372        Update existing watch(s). Both the mask and the processing 
     
    13581387                         directories in the watch's path. 
    13591388        @type auto_add: bool 
     1389        @param quiet: if True raise an WatchManagerError exception on 
     1390                      error. See example not_quiet.py 
     1391        @type quiet: bool 
    13601392        @return: dict of watch descriptors associated to booleans values. 
    13611393                 True if the corresponding wd has been successfully 
     
    13711403            apath = self.get_path(awd) 
    13721404            if not apath or awd < 0: 
    1373                 log.error('update_watch: invalid WD=%d' % awd) 
    1374                 continue 
     1405                err = 'update_watch: invalid WD=%d' % awd 
     1406                if quiet: 
     1407                    log.error(err) 
     1408                    continue 
     1409                raise WatchManagerError(err, ret_) 
    13751410 
    13761411            if mask: 
     
    13781413                if wd_ < 0: 
    13791414                    ret_[awd] = False 
    1380                     log.error(('update_watch: cannot update WD=%d (%s)'% 
    1381                                (wd_, apath))) 
    1382                     continue 
     1415                    err = 'update_watch: cannot update WD=%d (%s)' % (wd_, 
     1416                                                                      apath) 
     1417                    if quiet: 
     1418                        log.error(err) 
     1419                        continue 
     1420                    raise WatchManagerError(err, ret_) 
     1421 
    13831422                assert(awd == wd_) 
    13841423 
     
    14591498                yield root 
    14601499 
    1461     def rm_watch(self, wd, rec=False): 
     1500    def rm_watch(self, wd, rec=False, quiet=True): 
    14621501        """ 
    14631502        Removes watch(s). 
     
    14691508                    subdirectories and subfiles. 
    14701509        @type rec: bool 
     1510        @param quiet: if True raise an WatchManagerError exception on 
     1511                      error. See example not_quiet.py 
     1512        @type quiet: bool 
    14711513        @return: dict of watch descriptors associated to booleans values. 
    14721514                 True if the corresponding wd has been successfully 
     
    14841526            if wd_ < 0: 
    14851527                ret_[awd] = False 
    1486                 log.error('rm_watch: cannot remove WD=%d' % awd) 
    1487                 continue 
     1528                err = 'rm_watch: cannot remove WD=%d' % awd 
     1529                if quiet: 
     1530                    log.error(err) 
     1531                    continue 
     1532                raise WatchManagerError(err, ret_) 
    14881533 
    14891534            ret_[awd] = True