我可以使用 nautilus 标记文件,但目前还没有找到通过标记查找文件的解决方案。Tracker-search-tool 不提供标记搜索功能,Nautilus 也不提供,我所知道的其他任何应用程序也不提供。刚刚升级到 11.04。
答案1
它被称为跟踪器标签:
http://manpages.ubuntu.com/manpages/natty/man1/tracker-tag.1.html
它由 tracker-utils 包提供,该包是跟踪器工具的命令行版本。
-s -- lists all files associated with a tag
-a -- Add a tag to a file
例子
要添加标签:
tracker-tag -a TAG file
按标签搜索:
tracker-tag -s TAG
Result: 1
/home/sean/file
来自我的系统的真实世界示例
<sean@mymachine:~> tracker-tag -a TAG exten
<sean@mymachine:~> tracker-tag -a testing atreides master.ldif php_error.log TrainingUpdates.otl
<sean@mymachine:~> tracker-tag -s testing
Results: 5
/home/sean/TrainingUpdates.otl
/home/sean/atreides
/home/sean/exten
/home/sean/master.ldif
/home/sean/php_error.log
<sean@mymachine:~> tracker-tag -a myTagExample TrainingUpdates.otl atreides exten master.ldif php_error.log
<sean@mymachine:~> tracker-tag -s myTagExample
Results: 5
/home/sean/TrainingUpdates.otl
/home/sean/atreides
/home/sean/exten
/home/sean/master.ldif
/home/sean/php_error.log
<sean@mymachine:~> tracker-tag -s TAG
Result: 1
/home/sean/exten
答案2
gnome-team ppa 中的 Nautilus 有一个用于添加和删除标签的插件,bun nof 用于搜索。当我向 nautilus 团队请求新的面板视图时 (https://bugzilla.gnome.org/show_bug.cgi?id=670163)得到了这个答案。
- the interface that allows to add tracker tags from Nautilus is not part of
Nautilus, but it's an extension
- we will not add any additional side pane, since we intentionally trimmed them
down to Places and Tree for Nautilus 3.0
- I think the best way to do what you want is from Tracker itself; if the UI
utilities shipped with Tracker don't allow you to do this, you should file a
bug against Tracker for it
所以我专门为此制作了一个 nautilus-python 扩展。安装 python-nautilus 并提交到跟踪器https://bugzilla.gnome.org/show_bug.cgi?id=670643
sudo apt-get install python nautilus
然后复制下一个代码并保存在 .local/share/nautilus-python/extensions/[filename].py 下
#[email protected]
#nautilus etiketa bilatzaile
#v 0.1
from gi.repository import Nautilus, GObject
from gi.repository import Gtk as gtk
from gi.repository.GdkPixbuf import Pixbuf
from subprocess import Popen, PIPE, STDOUT,call
from os import path,environ
from sys import platform
from urllib import unquote
from mimetypes import guess_type
import locale
class TagsManager:
def __init__(self):
self.d={}
self.dtag={}
cmd='tracker-tag -t'
p=Popen(cmd,shell=True,stdin=PIPE, stdout=PIPE, stderr=STDOUT,close_fds=True)
output = p.stdout.read()
l=output.split('\n')
while('' in l): l.remove('')
if len(l)>3:
for i in range(2,len(l),3):
if i+2<len(l):self.d[l[i].strip()]=int(l[i+2][:l[i+2].find('f')])
original_list=[i for i in self.d.keys()]
#lk.sort()
decorated = [(s.lower(), s) for s in original_list]
decorated.sort()
lk = [s[1] for s in decorated]
print lk
for tag in lk:
if self.d[tag]<>0:
cmd='tracker-tag -t -s'
p=Popen(cmd,shell=True,stdin=PIPE, stdout=PIPE, stderr=STDOUT,close_fds=True)
output = p.stdout.read()
l=output.split('\n')
ll= [unquote(i.strip()).decode('utf-8') for i in l]
ini=ll.index(tag)
lkini=lk.index(unicode(tag))
if tag==lk[-1]:
resp=ll[ini+1:]
while('' in resp): resp.remove('')
else:
fin=ll.index(lk[lkini+1])
resp=[ll[i] for i in range(ini+1,fin)]
self.dtag[tag]=resp
class Ventana:
def clic(self, widget, event, data=None):
l=[]
lista_nueva=[]
for i in self.todas.get_selection().get_selected_rows()[1]:
t= self.todas.get_model().get_value(self.todas.get_model().get_iter(i), 0)
l.append(t)
if len(l)==1:
lista_nueva=[i for i in self.tm.dtag[l[0]]]
elif len(l)>1:
lista_nueva=[i for i in self.tm.dtag[l[0]]]
for i in l[1:]:
ll=[]
for f in self.tm.dtag[i]:
if f in lista_nueva: ll.append(f)
lista_nueva=[f for f in ll]
else:lista_nueva=[]
self.files.get_model().clear()
lista=[f.encode('utf-8')[7:] for f in lista_nueva]
lf=[i for i in lista if path.isfile(i)]
ld=[i for i in lista if not path.isfile(i)]
lista_nueva=ld+lf
for f in lista_nueva:
mime_type= guess_type(path.basename(f))
if mime_type[0]<>None:
icon= 'gnome-mime-'+mime_type[0].replace('/','-')
else:
print f.encode('utf-8'),path.isfile(f)
if path.isfile(f):icon='gtk-file'
else:icon='folder'
pixbuf = gtk.IconTheme.get_default().load_icon(icon, 48, 0)
self.files.get_model().append([pixbuf,path.basename(f),f])
return False
def open_file(self, iconview, ipath):
model = iconview.get_model()
iter = model.get_iter(ipath)
filename = model.get_value(iter, 2)
if platform == 'linux2':
call(["xdg-open", filename])
return
def __init__(self):
self.tm=TagsManager()
self.paned = gtk.HPaned()
self.existentags = gtk.ListStore(str)
tags=[i for i in self.tm.d.keys()]
tags.sort()
for t in tags:
self.existentags.append([t])
self.todas = gtk.TreeView(self.existentags)
self.todas.get_selection().set_mode(gtk.SelectionMode.MULTIPLE)
cell = gtk.CellRendererText()
self.todas.connect("button_release_event", self.clic, None)
column0=gtk.TreeViewColumn("Tags",cell, text=0)
self.todas.append_column(column0)
scrolled_window = gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC)
scrolled_window.add_with_viewport (self.todas)
self.paned.add1(scrolled_window)
self.listfiles = gtk.ListStore(Pixbuf,str,str)
self.files = gtk.IconView.new()
self.files.set_model(self.listfiles)
self.files.set_pixbuf_column(0)
self.files.set_text_column(1)
self.files.connect('item-activated', self.open_file)
scrolled_window2 = gtk.ScrolledWindow()
scrolled_window2.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC)
scrolled_window2.add_with_viewport (self.files)
self.paned.add2(scrolled_window2)
self.paned.set_position(150)
self.paned.show_all()
class PApplication(gtk.Application):
def __init__(self,window):
self.dialog = gtk.Dialog ("Etiketa iragazkia", window, gtk.DialogFlags.MODAL,
(gtk.STOCK_CLOSE, gtk.ResponseType.CLOSE,))
self.dialog.set_icon_name (gtk.STOCK_EDIT)
self.dialog.set_size_request(600, 400)
TS=Ventana()
self.dialog.vbox.pack_start (TS.paned,expand=True, fill=True, padding=0)
class Pr(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
def ojo(self,menu,window):
d=PApplication(window)
r=d.dialog.run()
d.dialog.destroy()
return
def get_background_items(self, window, files):
return self.menuItem(window)
def get_file_items(self, window, files):
return self.menuItem(window)
def menuItem(self, window):
self.window=window
P = Nautilus.MenuItem(
name="Etiketa iragazkia::Etiketa iragazkia",
label="Etiketa iragazkia",
tip="Etiketa iragazkia"
)
P.connect('activate', self.ojo, window)
return [P]
最后重新启动 nautilus
nautilus -q
当您右键单击任何文件或在后台时,会出现一个新菜单项“Etiketa iragazkia”(巴斯克语标签过滤器)。
答案3
使用 tracker-tag 从命令行搜索标签。上述搜索语法在我的系统 (12.04) 上不起作用。“-s”选项仅适用于“--list”:
tracker-tag --list -s [tag]
这更像是对第一个答案的评论,但我仍然缺少一些能够发表评论的代表 :-(