Changeset 8da69de7c06c68aed453c8a97d49f4e64bd41711
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rd82238a
|
r8da69de
|
|
| | 1 | 2008-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 | |
| 1 | 6 | 2008-03-24 ookoi <ookoi@sundae> |
| 2 | 7 | |
-
|
r9b43851
|
r8da69de
|
|
| 56 | 56 | __author__ = "seb@dbzteam.org (Sebastien Martini)" |
| 57 | 57 | |
| 58 | | __version__ = "0.8.0p" |
| | 58 | __version__ = "0.8.0q" |
| 59 | 59 | |
| 60 | 60 | __metaclass__ = type # Use new-style classes by default |
| … |
… |
|
| 865 | 865 | poll is blocking waiting for something to read. |
| 866 | 866 | @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 |
| 868 | 868 | read is >= treshold. If != 0, you likely want to |
| 869 | 869 | use it in combination with read_freq because |
| … |
… |
|
| 1063 | 1063 | seconds at best and only if the size to read is >= treshold. |
| 1064 | 1064 | |
| 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. |
| 1066 | 1067 | @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. |
| 1068 | 1069 | @type daemonize: boolean |
| 1069 | 1070 | """ |
| … |
… |
|
| 1124 | 1125 | max(0, read_freq - timeout) seconds. |
| 1125 | 1126 | @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 |
| 1127 | 1128 | read is >= treshold. If != 0, you likely want to |
| 1128 | 1129 | use it in combination with read_freq because |
| … |
… |
|
| 1226 | 1227 | |
| 1227 | 1228 | |
| | 1229 | class 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 | |
| 1228 | 1248 | class WatchManager: |
| 1229 | 1249 | """ |
| … |
… |
|
| 1248 | 1268 | wd_ = LIBC.inotify_add_watch(self._fd, path, mask) |
| 1249 | 1269 | if wd_ < 0: |
| 1250 | | log.error('add_watch: cannot watch %s (WD=%d)' % (path, wd_)) |
| 1251 | 1270 | return wd_ |
| 1252 | 1271 | watch_ = Watch(wd=wd_, path=os.path.normpath(path), mask=mask, |
| … |
… |
|
| 1263 | 1282 | |
| 1264 | 1283 | 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): |
| 1266 | 1285 | """ |
| 1267 | 1286 | Add watch(s) on given path(s) with the specified mask and |
| … |
… |
|
| 1285 | 1304 | @param do_glob: Do globbing on pathname. |
| 1286 | 1305 | @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 |
| 1287 | 1309 | @return: dict of paths associated to watch descriptors. A wd value |
| 1288 | 1310 | is positive if the watch has been sucessfully added, |
| … |
… |
|
| 1299 | 1321 | # recursively list subdirs according to rec param |
| 1300 | 1322 | 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_) |
| 1303 | 1332 | return ret_ |
| 1304 | 1333 | |
| … |
… |
|
| 1339 | 1368 | |
| 1340 | 1369 | def update_watch(self, wd, mask=None, proc_fun=None, rec=False, |
| 1341 | | auto_add=False): |
| | 1370 | auto_add=False, quiet=True): |
| 1342 | 1371 | """ |
| 1343 | 1372 | Update existing watch(s). Both the mask and the processing |
| … |
… |
|
| 1358 | 1387 | directories in the watch's path. |
| 1359 | 1388 | @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 |
| 1360 | 1392 | @return: dict of watch descriptors associated to booleans values. |
| 1361 | 1393 | True if the corresponding wd has been successfully |
| … |
… |
|
| 1371 | 1403 | apath = self.get_path(awd) |
| 1372 | 1404 | 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_) |
| 1375 | 1410 | |
| 1376 | 1411 | if mask: |
| … |
… |
|
| 1378 | 1413 | if wd_ < 0: |
| 1379 | 1414 | 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 | |
| 1383 | 1422 | assert(awd == wd_) |
| 1384 | 1423 | |
| … |
… |
|
| 1459 | 1498 | yield root |
| 1460 | 1499 | |
| 1461 | | def rm_watch(self, wd, rec=False): |
| | 1500 | def rm_watch(self, wd, rec=False, quiet=True): |
| 1462 | 1501 | """ |
| 1463 | 1502 | Removes watch(s). |
| … |
… |
|
| 1469 | 1508 | subdirectories and subfiles. |
| 1470 | 1509 | @type rec: bool |
| | 1510 | @param quiet: if True raise an WatchManagerError exception on |
| | 1511 | error. See example not_quiet.py |
| | 1512 | @type quiet: bool |
| 1471 | 1513 | @return: dict of watch descriptors associated to booleans values. |
| 1472 | 1514 | True if the corresponding wd has been successfully |
| … |
… |
|
| 1484 | 1526 | if wd_ < 0: |
| 1485 | 1527 | 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_) |
| 1488 | 1533 | |
| 1489 | 1534 | ret_[awd] = True |