Hi,
I have made another fuse file system with tracker engine and it use
keyword dbus interface to retrive the filelist.
Usage: trackerfs.py /mount/point tag=tag1+tag2
When file 's moved to mounted dir the fs move it in ~/.documents and tag it
with used tag.
In future I will be implement a better support for a rdf file and simple
search and maybe merge
my fs with this http://code.google.com/p/trackerfs/
Sorry for my English but I'm Italian :-)
Bye
#!/usr/bin/env python
[EMAIL PROTECTED]
[EMAIL PROTECTED]:@file xmp.py
#@@first
#
# Copyright (C) 2001 Jeff Epler <[EMAIL PROTECTED]>
#
# This program can be distributed under the terms of the GNU LGPL.
# See the file COPYING.
#
[EMAIL PROTECTED]
[EMAIL PROTECTED]:imports
from fuse import Fuse
from optparse import OptionParser
from errno import *
from stat import *
import os,statvfs,thread,logging,dbus
###
# Set up logging
###
log = logging.getLogger("trackerfs")
log.setLevel(logging.ERROR)
fh = logging.StreamHandler()
fh.setLevel(logging.ERROR)
#create formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
fh.setFormatter(formatter)
log.addHandler(fh)
class TrackerFs (Fuse):
def __init__(self,*args, **kw):
Fuse.__init__(self,*args,**kw)
#Initialize dbus session and tracker interfaces
bus = dbus.SessionBus()
obj = bus.get_object('org.freedesktop.Tracker','/org/freedesktop/tracker')
self.tracker = dbus.Interface(obj, 'org.freedesktop.Tracker')
self.keywords = dbus.Interface(obj, 'org.freedesktop.Tracker.Keywords')
self.filesdb = dbus.Interface(obj, 'org.freedesktop.Tracker.Files')
print "Trackerfs:mountpoint: %s" % repr(self.mountpoint)
print "Trackerfs:unnamed mount options: %s" % self.optlist
print "Trackerfs:named mount options: %s" % self.optdict
self.filelist = []
self.tmplist = []
self._refresh_filelist()
pass
def mythread(self):
print "start thread"
#while 1:
# time.sleep(120)
# self.getdir()
def _refresh_filelist(self):
if self.optdict.has_key("tag"):
print "Use Tag"
self.filelist = self.keywords.Search(-1,'Files',self.optdict['tag'].split("+"),-1,-1)
self.filelist = map(lambda x: str(x),self.filelist)
#elif self.optdict.has_key("query"):
# print "Use Query"
# self.filelist = os.popen("/usr/bin/tracker-query "+self.optdict['query'],"r").readlines();
# self.filelist = map(lambda x:(x.split(' : ')),self.filelist)
# self.filelist = map(lambda x:(x[0].strip(' \t\r\n')),self.filelist)
#elif self.optdict.has_key("key"):
# print "Use key"
# self.filelist = os.popen("/usr/bin/tracker-search "+self.optdict['tag'].replace("+",","),"r").readlines();
# self.filelist = map(lambda x:(x.strip(' \t\r\n')),self.filelist)
#else:
# print 'You must specifi a tag or a query'
# return 0
#self.filelist.extend(self.tmplist)
print self.filelist
#self.filelist.pop()
def _get_file_path(self,filename):
if os.path.dirname(filename) == "/":
for file in self.filelist:
if filename== "/"+os.path.basename(file):
return file
else:
path = filename.split("/")
relpath = filename.replace("/"+path[1],"")
for file in self.filelist:
if path[1] == os.path.basename(file):
return file+relpath
return filename
def getattr(self,path):
print 'File:'+path+'Attr:'+self._get_file_path(path)
return os.lstat(self._get_file_path(path))
def readlink(self, path):
return os.readlink(path)
def getdir(self, path):
if path == "/":
self._refresh_filelist()
return map(lambda x: (os.path.basename(x),0),self.filelist)
else:
return map(lambda x: (os.path.basename(x),0),os.listdir(self._get_file_path(path)))
def unlink(self, path):
print 'unlink'
return os.unlink(path)
def rmdir(self, path):
return os.rmdir(path)
def symlink(self, path, path1):
return os.symlink(path, path1)
def rename(self, path, path1):
return os.rename(path, path1)
def link(self, path, path1):
return os.link(path, path1)
def chmod(self, path, mode):
return os.chmod(self._get_file_path(path), mode)
def chown(self, path, user, group):
return os.chown(self._get_file_path(path), user, group)
def truncate(self, path, size):
f = open(self._get_file_path(path), "w+")
return f.truncate(size)
def mknod(self, path, mode, dev):
if os.path.dirname(path) == "/":
path = "~/.documents/"+os.path.basename(path)
print 'MkNod:'+path+'....'
if S_ISREG(mode):
self.tmplist.append(path)
self._refresh_filelist()
self.getdir("/")
res = os.open(path, os.O_CREAT | os.O_WRONLY,mode);
#restat = os.fstat(res);
#self.filesdb.Create(path,False,'image/png',dbus.Int32(restat[ST_SIZE]),restat[ST_MTIME])
else:
return -EINVAL
def mkdir(self, path, mode):
path = "~/.documents/"+os.path.basename(path)
res = os.mkdir(path,mode)
self.tmplist.append(path)
self._refresh_filelist()
self.getdir("/")
return res
def utime(self, path, times):
return os.utime(self._get_file_path(path), times)
def open(self, path, flags):
path = self._get_file_path(path)
res = os.open(path,flags)
print "Trackerfs:open: %s" % path
os.close(res)
return 0
def read(self, path, length, offset):
path = self._get_file_path(path)
print "Trackerfs:read: %s" % path
f = open(self._get_file_path(path), "r")
f.seek(offset)
return f.read(length)
def write(self, path, buf, off):
path = self._get_file_path(path)
print "Trackerfs:write: %s" % path
f = open(path, "w")
f.seek(off)
f.write(buf)
return len(buf)
return 0
def release(self, path, flags):
print "Trackerfs:release: %s %s" % (self._get_file_path(path), flags)
return 0
def statfs(self):
self.sysconst = os.statvfs("/home/eugenio/.documents")
print "Trackerfs:statfs: returning fictitious values"
print self.sysconst[statvfs.F_BLOCKS]
block_size = self.sysconst[statvfs.F_BSIZE]
blocks = self.sysconst[statvfs.F_BLOCKS]
blocks_free = self.sysconst[statvfs.F_BFREE]
blocks_avail = self.sysconst[statvfs.F_BAVAIL]
files = self.sysconst[statvfs.F_FILES]
files_free = self.sysconst[statvfs.F_FFREE]
namelen = self.sysconst[statvfs.F_NAMEMAX]
return (block_size, blocks, blocks_free, blocks_avail, files, files_free, namelen)
def fsync(self, path, isfsyncfile):
print "Trackerfs:fsync: path=%s, isfsyncfile=%s" % (path, isfsyncfile)
return 0
if __name__ == '__main__':
server = TrackerFs()
server.multithreaded = 0;
server.main()
_______________________________________________
tracker-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/tracker-list