I've set up iwatch to monitor some directory. Instead off emailing me, i want to execute my own script. Everything went well, until some special characters showed up.
iwatch -f iwatch.xml where iwatch.xml is
[...]
<path type="recursive" alert="off" events="close_write" exec="commit '%f'">/user/Desktop/test</path>
[...]
commit programm:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import chardet,sys
print 40*"-"
print chardet.detect(sys.argv[1])
print type(sys.argv[1]), sys.argv[1]
uni = unicode(sys.argv[1], sys.getfilesystemencoding())
print type(uni), uni
So, when i run "commit ÄÖÜäöüß", everything is fine
----------------------------------------
{'confidence': 0.99, 'encoding': 'utf-8'}
<type 'str'> ÄÖÜäöüß
<type 'unicode'> ÄÖÜäöüß
But, when it get fired from iwatch (touch ÄÖÜäöüß), i get
----------------------------------------
{'confidence': 0.99, 'encoding': 'utf-8'}
<type 'str'> /root/Desktop/test/ÃÃÃäöüÃ
<type 'unicode'> /root/Desktop/test/ÃÃÃäöüÃ
I don't know so much about encoding :/
How do I get my readable stuff here?
I've tried everything I could find (encoding/decoding in thousand ways) but didn't figuered it out. Can somebody help me? Every suggest would be appreciated! Thank you very much!
New:
This dude wrote a patch for iwatch.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=608843
Both provided patches are working for me.
Patch 2 gives a ...pragma is deprecated... warning.
Old:
Changed strategy, I'll rebuild around pyinotify. This works great!
import pyinotify
wm = pyinotify.WatchManager()
mask = pyinotify.IN_CLOSE_WRITE
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
print "Wrote:", event.pathname
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch('/root/Desktop/test', mask, rec=True)
notifier.loop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.