forgot password?


   
 
Listing/editing/deleting tags?
Posted: 07 July 2011 04:11 PM   [ Ignore ]  
Newbie
Rank
Total Posts:  4
Joined  2011-07-07

Hi,

I’d like to be able to list, edit, and delete my tags but I can’t find any way of doing so. Am I missing something? Is there a way to see a list of all my tags or, e.g., rename my “trips” tag to “travel” or to delete my “research” tag? I’m using Tracks 2.0 with the sqlite3 database, running on Ubuntu Lucid.

Thanks,
Hanna

Profile
 
 
Posted: 07 July 2011 08:52 PM   [ Ignore ]   [ # 1 ]  
Sr. Member
RankRankRankRank
Total Posts:  882
Joined  2006-10-05

no, that has not been implemented. If you like you can add an enhancement request on Assembla.

Profile
 
 
Posted: 07 July 2011 09:15 PM   [ Ignore ]   [ # 2 ]  
Newbie
Rank
Total Posts:  4
Joined  2011-07-07

Okay, great. I’ll do that (if I can work out how). In the meantime, I worked out that I can do the following from bash to list my tags:

sqlite3 $DATABASE 'select * from tags' awk 'BEGIN { FS="|" }; { print $2 }' 

(where $DATABASE is the path to my tracks db) and do the following to rename a particular tag, e.g., from “trips” to “travel”:

sqlite3 $DATABASE 'update tags set name="travel" where name="trips"' 

Haven’t worked out what happens if I delete a tag though—presumably other tables refer to tag IDs so if the tag table doesn’t contain a particular tag ID that is referenced elsewhere things will break horribly….?

Profile
 
 
Posted: 08 July 2011 07:12 AM   [ Ignore ]   [ # 3 ]  
Sr. Member
RankRankRankRank
Total Posts:  882
Joined  2006-10-05

renaming is no problem, but deleting is more difficult because of the taggings table. The tag could be used by more than one tag. If you don’t mind the all todos and/or recurring todos that are referencing that tag to have this tag removed, just delete the corresponding records from the taggings table.

Of course, you should make backups to be safe grin

Profile
 
 
Posted: 08 July 2011 06:30 PM   [ Ignore ]   [ # 4 ]  
Newbie
Rank
Total Posts:  4
Joined  2011-07-07

Got it!! I wrote a Python script to do everything I want:

import resqlite3sys

def 
list(c):

    
c.execute('select tags.name from tags')
    
    print 
'Current tags:',

    
tag_list []
    
    
for row in c:
        
tag_list.append(row[0])

    print 
', '.join(tag_list)

def rename(cold, new):

    
c.execute('select tags.name from tags')

    
tag_list []
    
    
for row in c:
        
tag_list.append(row[0])

    if new 
in tag_list:
        print 
'Cannot rename "' old '" to "' + new + '" -- tag exists'
        
sys.exit(0)

    print 
'Renaming "' old '" to "' + new + '" ...'

    
# rename tag in all projects' default tags

    
c.execute('select * from projects where default_tags like "%' old '%"')

    for 
row in c:

        
project_id row[0]
        default_tags 
row[10]

        match 
re.search('(^|(, ))' old '((, )|$)'default_tags)

        if 
match:

            
default_tags default_tags.replace(match.group(), match.group().replace(old, new)) # form new default tags

            
c.execute('update projects set default_tags="' default_tags '" where id="' str(project_id) + '"'# update default tags

    
c.execute('update tags set name="' + new + '" where name="' old '"')

def remove(ctag):
    print 
'Removing tag "' tag '" ...'

    
# delete all taggings involving tag

    
c.execute('delete from taggings where id in (select taggings.id from tags,taggings where tags.id=taggings.tag_id and tags.name="' tag '")');

    
# delete tag from all projects' default tags

    
c.execute('select * from projects where default_tags like "%' tag '%"')

    for 
row in c:

        
project_id row[0]
        default_tags 
row[10]

        match 
re.search('(^|(, ))' tag '((, )|$)'default_tags)

        if 
match:

            if 
match.group().startswith(', ') and match.group().endswith(', '):
                
default_tags default_tags.replace(match.group(), ', ')
            else:
                
default_tags default_tags.replace(match.group(), '')

            
c.execute('update projects set default_tags="' default_tags '" where id="' str(project_id) + '"'# update default tags

    
c.execute('delete from tags where name="' tag '"'# delete tag

if __name__ == '__main__':

    if 
len(sys.argv) < 2:
        
sys.exit(0)

    
conn sqlite3.connect('/home/hanna/tracks/db/tracks-20-blank.sqlite3.db'# open the database

    
if sys.argv[1] == 'list':
    
        if 
len(sys.argv) != 2:
            
sys.exit(0)

        list(
conn.cursor())

    
elif sys.argv[1] == 'rename':

        if 
len(sys.argv) != 4:
            
sys.exit(0)

        
rename(conn.cursor(), sys.argv[2]sys.argv[3])

    
elif sys.argv[1] == 'remove':

        if 
len(sys.argv) != 3:
            
sys.exit(0)

        
remove(conn.cursor(), sys.argv[2])

    else:
        
sys.exit(0)

    
# commit changes so other connections can see them and close the db

    
conn.commit()
    
conn.close() 

 

Profile
 
 
Posted: 08 July 2011 08:44 PM   [ Ignore ]   [ # 5 ]  
Sr. Member
RankRankRankRank
Total Posts:  882
Joined  2006-10-05

impressive! thanks for posting so others can reuse.

Profile
 
 
Posted: 11 July 2011 02:11 PM   [ Ignore ]   [ # 6 ]  
Newbie
Rank
Total Posts:  4
Joined  2011-07-07

Thanks grin

I actually cleaned up the code a bit and posted a new version here, in case anyone’s interested: https://github.com/hannawallach/Utilities/blob/master/tracks-tags.py

Profile