פרטי תוכנה:
Watchdog הוא API Python לעקוב אחר המתרחשים במערכת הקבצים.
כלב שמירה מאפשרת תוכניות פייתון לעקוב אחר המתרחשות במערכת הקבצים כportably כמו שימוש אפשרי:
* Inotify על לינוקס
* FSEvents ב- Mac OS X
* API של Windows ב- Windows
* קלפי כמנגנון חלופי
שימוש דוגמא:
sys יבוא
זמן יבוא
מאובזרוור יבוא כלב השמירה, FileSystemEventHandler
רישום יבוא
logging.basicConfig (רמה = logging.DEBUG)
MyEventHandler כיתה (FileSystemEventHandler):
& Nbsp; & nbsp; & nbsp; catch_all_handler def (עצמי, אירוע):
& Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; logging.debug (אירוע)
& Nbsp; & nbsp; & nbsp; on_moved def (עצמי, אירוע):
& Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; self.catch_all_handler (אירוע)
& Nbsp; & nbsp; & nbsp; on_created def (עצמי, אירוע):
& Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; self.catch_all_handler (אירוע)
& Nbsp; & nbsp; & nbsp; on_deleted def (עצמי, אירוע):
& Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; self.catch_all_handler (אירוע)
& Nbsp; & nbsp; & nbsp; on_modified def (עצמי, אירוע):
& Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; self.catch_all_handler (אירוע)
event_handler = MyEventHandler ()
משקיף = אובזרוור ()
observer.schedule ('א-ייחודי-שם ", event_handler, * sys.argv [1:])
observer.start ()
לנסות:
& Nbsp; & nbsp; & nbsp; בעוד אמיתי:
& Nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; time.sleep (1)
מלבד KeyboardInterrupt:
& Nbsp; & nbsp; & nbsp; observer.unschedule ('א-ייחודי-שם ")
& Nbsp; & nbsp; & nbsp; (Observer.stop)
observer.join ()
דרישות :
- Python
- pyinotify
תגובות לא נמצא