thisisabout
The first script allows adding a keyword. It is a simple script and allows adding one keyword per call. Syntax: thisisabout [tag] [file]. The code:
#!/usr/bin/ruby
# Copyright (C) 2006 Egon Willighagen
# License: GPL
require 'xattr'
tag = ARGV[0]
file = ARGV[1]
if (file == nil)
p "syntax: thisisabout [TAG] [FILE]"
exit
else
description = File.get_attr(file, "keywords")
if (description != nil)
words = description.split
if (words.include?(tag))
p file + " already has the tag " + tag
else
description = description + " " + tag
end
else
description = tag
end
File.set_attr(file, "keywords", description)
end
thisisnotabout
Removing a tag is done with a similar script:
#!/usr/bin/ruby
# Copyright (C) 2006 Egon Willighagen
# License: GPL
require 'xattr'
tag = ARGV[0]
file = ARGV[1]
if (file == nil)
p "syntax: thisisnotabout [TAG] [FILE]"
exit
else
description = File.get_attr(file, "keywords")
newdescription = ""
if (description != nil)
words = description.split
words.each do |word|
if (word == tag)
# skip word
else
if (newdescription.length > 0)
newdescription = newdescription + " "
end
newdescription = newdescription + word
end
end
else
description = tag
end
File.set_attr(file, "keywords", newdescription)
end
whatsthisabout
The third script is where KDE comes in. It has a --nogui option if you don't want to GUI too show up. The code:
#!/usr/bin/ruby
# Copyright (C) 2006 Egon Willighagen
# License: GPL
require 'getoptlong'
require 'rdoc/usage'
require 'Korundum'
require '/home/egonw/bin/whatsthisabout'
class MainWindow < KDE::MainWindow
def initialize( name, counts )
super(nil, name)
setCaption("What's This About??")
vbox = Qt::VBox.new( self )
@browser = KDE::HTMLPart.new( vbox )
setCentralWidget(vbox)
@browser.begin()
counts.each {|key, value|
fontSize = (6*value)/2
@browser.write("");
@browser.write( key )
@browser.write(" ");
}
@browser.end()
end
end
opts = GetoptLong.new(
[ '--nogui', '-n', GetoptLong::NO_ARGUMENT ],
[ '--help', '-h', GetoptLong::NO_ARGUMENT ]
)
startPath = nil
gui = "yes"
opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage
when '--nogui'
gui = "no"
end
end
if ARGV.length == 1
startPath = ARGV[0]
elsif ARGV.length == 0
startPath = '.'
else
RDoc::usage
exit 0
end
wat = WhatsThisAbout.new
counts = wat.getKeywords(startPath)
if (gui == "yes")
about = KDE::AboutData.new("whatsthisabout", "What's This About??", "0.1")
KDE::CmdLineArgs.init(about)
a = KDE::Application.new()
window = MainWindow.new( "What's This About??", counts )
window.resize( 600, 300 )
a.mainWidget = window
window.show
a.exec
else
counts.each do |bla, bla2|
puts bla + " " + bla2.to_s
end
end
The obligatory screenshot:
In due time I will put this in KDE SVN, but I need to make a reasonable cmake script yet. Anyone who can tell me how I can have cmake check wether the required Ruby libraries are installed? There are other things to do too:
- make a backup/restore facility
- use a database instead of recursively finding tags
Because I have my PDFs in a SVN repository and share them between some work places, the first todo would mean I could share my tags too. The second would just mean a serious speedup.
2 comments:
for a storage system, have you thought about using strigi?
(seems liquidat had a similar idea =)
styxman: yes, that's one of the things I want to do.
liquidat: yes, I plan to upload these things to trunk/playground, and start better KDE integration from there. Need to make the cmake files first.
liquidat, aaron: I'm in good contact with Jos, and I have some patches in Strigi. The current situation is that Strigi will not do persistent keyword tagging, but a db backend is not unlikely.
BTW, Strigi does already index the xattr one adds, so Strigi integration is already present. When you have an inotify-enabled Strigi installed, added keywords should automatically be indexed, though I have not practically tried this.
Post a Comment