You are not logged in.

#1 2010-05-27 18:59:24

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

tagger: tag any file from the console

Hi,

   I've been coding two python scripts to acces files using tags:

   The scripts are tag.py and tagcd.py

Get it

   you may download the scripts from http://code.google.com/p/tuxtagger together with an small install script using mercurial

hg clone https://tuxtagger.googlecode.com/hg/ tuxtagger

to start *testing* it you should run the install.sh script as not-root. This will create a .tagger directry at your
   home folder and some more files inside it.

Example usage:

Tagging some files:

First of all, this is a very beta version (better 50% fetures now than 100% never).

1. make sure that both tag.py and tagcd.py are in your path or cwd

enter a directory with some files you want to tag, for example

A.txt   B.txt   C.txt

as they are all plain text files you might want to tag them with the "plain" tag, in order to do so you type:

tag.py * - plain

if you want to tag the files A.txt and B.txt with the "foo" and
the files B.txt and C.txt with the tag "bar":

tag.py A.txt B.txt - foo
tag.py B.txt C.txt - bar

NOTE: The files A,B or C don't need to be in the same directory
NOTE: If you make a mistake running this example, i'm afraid there is no way to undo yet, start over

Accesing the tags:

For this version, in order to use your recently created tags system, you should change dir to the *work* directory:

cd ~/.tagger/.WORKDIR

you may go there later, but the effects of tagcd.py will only affect that directory. (for security reasons ( i didn't want to erase my files while hacking with this ))

To get all files with the tag "foo", type:

$ tagcd.py foo
...verbose...
$ ls
A.txt

links will be creted in the workdir pointing to your original files.

NOTE: in this beta version you should run rm * in the workdir in order to clean it up

some logical operations are available, for example

$tagcd.py foo AND bar
$ls
B.txt

OR, and XOR are available.

Currently tagcd.py does't take into account what was previously in the workdir, but i'll change that soon (i think i'll run the rm * from the script)

Syntax

$tag.py filelist - tagslist
$tagcd.py tag1 X tag2 X tag3 ...

where X is AND,OR, or XOR, order of evaluation is from left to right

-------

Ok, i hope it is enought explanation. Please let me know if you find this useful. In its current state i'm using this to group some music files. This and the Source code, are all the docs available. Ask me if you have any questions or comments (or just to say hi big_smile)

Last edited by pepeapepepe (2010-05-27 21:48:06)


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

#2 2010-05-27 19:23:34

livibetter
Member
From: Taipei
Registered: 2008-05-14
Posts: 95
Website

Re: tagger: tag any file from the console

I still didn't get it from your example usage. Could you write a complete command history?

But I have few suggestions about coding.

1.

home = os.getenv("HOME")
taggerDir = home + '/.tagger/'

You may want to use os.path.expanduser, so you can use os.path.expanduser('~/.tagger/'). The benefit is it also works on Windows. (Not sure about the rest of your code)

2.

dataBase = eval(db.read())

This doesn't sound good. I think the dataBase is a dict type. Maybe you should consider to use simplejson/json, the output with prettified result is still human readable.

3.
listsAND, etc. I think those A,B parameters are lists, right? Have your considered to use set type to get results after set operations?

Offline

#3 2010-05-27 19:38:47

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

Re: tagger: tag any file from the console

Thanks for your suggestions, i'll check them soon

Complete commnd history:

user@host:~ [0,922,344]$ mkdir test
user@host:~ [0,923,345]$ cd test
user@host:test [0,924,347]$ touch {A,B,C,D}.txt
user@host:test [0,925,348]$ ls
A.txt  B.txt  C.txt  D.txt
user@host:test [0,925,349]$ tag.py * - plain
Tagging A.txt
....
user@host:test [0,927,351]$ tag.py A.txt B.txt - foo
....
user@host:test [0,928,352]$ tag.py C.txt B.txt - bar
....
user@host:test [0,929,353]$ cd ~/.tagger/.WORKDIR/
user@host:.WORKDIR [0,930,354]$ ls
user@host:.WORKDIR [0,930,356]$ tagcd.py foo
.....
user@host:.WORKDIR [0,931,357]$ ls
A.txt  B.txt
user@host:.WORKDIR [0,931,358]$ rm *
user@host:.WORKDIR [0,931,359]$ tagcd.py foo AND bar
.....
user@host:.WORKDIR [0,932,360]$ ls
B.txt
user@host:.WORKDIR [0,932,361]$ rm *

i hope it helps, and thanks again for thhe comments


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

#4 2010-05-27 20:04:07

livibetter
Member
From: Taipei
Registered: 2008-05-14
Posts: 95
Website

Re: tagger: tag any file from the console

pepeapepepe wrote:

Thanks for your suggestions, i'll check them soon

Complete commnd history:

user@host:~ [0,922,344]$ mkdir test
user@host:~ [0,923,345]$ cd test
user@host:test [0,924,347]$ touch {A,B,C,D}.txt
user@host:test [0,925,348]$ ls
A.txt  B.txt  C.txt  D.txt
user@host:test [0,925,349]$ tag.py * - plain
Tagging A.txt
....
user@host:test [0,927,351]$ tag.py A.txt B.txt - foo
....
user@host:test [0,928,352]$ tag.py C.txt B.txt - bar
....
user@host:test [0,929,353]$ cd ~/.tagger/.WORKDIR/
user@host:.WORKDIR [0,930,354]$ ls
user@host:.WORKDIR [0,930,356]$ tagcd.py foo
.....
user@host:.WORKDIR [0,931,357]$ ls
A.txt  B.txt
user@host:.WORKDIR [0,931,358]$ rm *
user@host:.WORKDIR [0,931,359]$ tagcd.py foo AND bar
.....
user@host:.WORKDIR [0,932,360]$ ls
B.txt
user@host:.WORKDIR [0,932,361]$ rm *

i hope it helps, and thanks again for thhe comments

Ah.. now I see. I got confused by `tag*cd*.py`, I assumed "cd" stands for change directory. Since it make symbolic links (I checked the source), I think it's better to have another name.

Offline

#5 2010-05-27 20:42:05

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

Re: tagger: tag any file from the console

I updted the code, and now i uses sets where it should (i think i invented some wheels again)
I'm using expanduser now, altought i haven't test it with windows
with respect to JSON and the dic file, i have to think further. The dic file is used only when there is a collison. where collision means two files with the same name.

In the future i have to think of a way to create files while working with tags, I think I will store them in one single directory.


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

#6 2010-05-27 20:56:32

livibetter
Member
From: Taipei
Registered: 2008-05-14
Posts: 95
Website

Re: tagger: tag any file from the console

pepeapepepe wrote:

I updted the code, and now i uses sets where it should (i think i invented some wheels again)
I'm using expanduser now, altought i haven't test it with windows
with respect to JSON and the dic file, i have to think further. The dic file is used only when there is a collison. where collision means two files with the same name.

In the future i have to think of a way to create files while working with tags, I think I will store them in one single directory.

After I realized what your code does, it doesn't matter if expanduser works on Windows, because afaik Windows doesn't have symbolic links.

When I suggested JSON, I have two reasons: 1) eval usage should be avoided if that is not necessary, 2) I assume human readable is expected for your data file. If the second one isn't the case, then you should use shelve module.

Last edited by livibetter (2010-05-27 20:59:46)

Offline

#7 2010-05-28 18:49:54

solstice
Member
Registered: 2006-10-27
Posts: 237
Website

Re: tagger: tag any file from the console

this made me think of Extended Attributes wikipedia page

Last edited by solstice (2010-05-28 18:51:27)

Offline

#8 2010-05-28 19:39:58

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

Re: tagger: tag any file from the console

Instresting, extended attributes could be of use for this application, but afaik extended attributes are not suppourted in my archbox. How popular do you think their are? (excuse my lack of knowledge).

I would say that tagcd.py is like CDPATH but with more flexibility. I started to write it because some times i would
like to work with files wich are located at different directories with more ease.

I'll add some capabilities to "store" files in the weekend, and try to use it during the whole next week.


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

Board footer

Powered by FluxBB