ffmmx's Blog

Happy coding

[蛋疼][备忘] pynepomukindexer 简单封装,手动的文件索引.

ffmmx posted @ 2012年10月04日 16:32 in kde with tags python kde nepomuk , 1400 阅读

其实没啥什么好说的,我kde环境里面的nepomukfilewatch 服务进程启动会crash,暂时没有找到错误的原因,这样会造成文件改动以后触发的somethingChange 信号无法被正确的捕捉,并且调用对应索引程序来重新丢该资源进行处理.所以只要弄个手动的,暂时应急一下.

pynepomukindexer.py

#!/usr/bin/env python2
#coding:utf8
#filename:pynepomukindexer.py
#description:一个支持多文件和文件夹递归的nepomukindexer的封装.

'''
一个支持多文件和文件夹递归的nepomukindexer文件索引的封装.
'''
import os
import sys
from PyKDE4.nepomuk import Nepomuk


class PyNepomukIndexer(object):
    def __init__(self,currentPath):
        self.currentPath = currentPath
        self.indexerCmd = 'nepomukindexer'

    def index(self,path):
        if os.path.isdir(path):
            for f in [ os.path.realpath(path)+'/'+tf for tf in os.listdir(path) if tf[0] != '.' ]:
                self.index(f)
        else:
            print path
            os.system(self.indexerCmd+" '"+path+"'")


if __name__ == '__main__':
    pyindexer = PyNepomukIndexer(os.path.realpath('.'))
    
    if len(sys.argv) == 1:
        pyindexer.index(os.path.realpath('.'))
    else:
        for file in sys.argv[1:]:
            pyindexer.index(file)


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter