[英](Linux) iwatch executing python with special chars in filename
我已经设置了iwatch来监视某些目录。 而不是通过电子邮件发送给我,我想执行自己的脚本。 一切顺利,直到出现一些特殊字符为止。
iwatch -f iwatch.xml,其中iwatch.xml是
[...]
<path type="recursive" alert="off" events="close_write" exec="commit '%f'">/user/Desktop/test</path>
[...]
提交程序:
#!/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
因此,当我运行“ commitÄÖÜäöüß”时,一切都很好
----------------------------------------
{'confidence': 0.99, 'encoding': 'utf-8'}
<type 'str'> ÄÖÜäöüß
<type 'unicode'> ÄÖÜäöüß
但是,当它从iwatch(触摸ÄÖÜäöüß)发射时,我得到了
----------------------------------------
{'confidence': 0.99, 'encoding': 'utf-8'}
<type 'str'> /root/Desktop/test/ÃÃÃäöüÃ
<type 'unicode'> /root/Desktop/test/ÃÃÃäöüÃ
我对编码不是很了解:/
我如何在这里获得可读性?
我已经尝试了所有可能的方法(以千种方式进行编码/解码),但并未弄清楚。 有人可以帮我吗? 每个建议将不胜感激! 非常感谢你!
新:
这个家伙为iwatch编写了一个补丁。
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=608843
提供的两个补丁都对我有用。
补丁2给出了...不建议使用杂项...警告。
旧:
更改策略后,我将围绕pyinotify进行重建。 这很棒!
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.