Changeset 128 for emailtotracscript
- Timestamp:
- 10/19/06 10:58:38 (18 years ago)
- Location:
- emailtotracscript/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
emailtotracscript/trunk/ChangeLog
r126 r128 3 3 an exception in the syslog if we use sys.exit(0), replaced by 4 4 return. 5 Fixed by: Bas van der Vlies 5 6 6 7 * run_email2trac.c. Setgid() must be called before setuid(). … … 9 10 10 11 * email2trac.py, Fixed an error in Ticket Update. When ticket 11 does not exists, threat it like a new ticket. 12 does not exists, proceed as if it is a new ticket 13 Fixed by: Bas van der Vlies 14 15 * delete_spam.py. Trac version 0.10 made it easier to delete 16 tickets. 17 Fixed by: Bas van der Vlies 12 18 13 19 2006-10-10 -
emailtotracscript/trunk/debian/changelog
r127 r128 1 email2trac (0.8.1-5) stable; urgency=low 2 3 * Adjust delete_spam.py for version 0.10 4 5 -- root <root@rc.sara.nl> Thu, 19 Oct 2006 10:57:30 +0200 6 1 7 email2trac (0.8.1-4) stable; urgency=low 2 8 3 9 * Fixed an error in ticket update, when a ticket does not exists 4 threat it like a new ticket10 proceed if it is a new ticket. 5 11 6 12 -- root <root@rc.sara.nl> Wed, 18 Oct 2006 09:50:36 +0200 -
emailtotracscript/trunk/delete_spam.py.in
r116 r128 3 3 # Copyright (C) 2002 4 4 # 5 # This file is part of the pxeconfigutils5 # This file is part of the email2trac utils 6 6 # 7 7 # This program is free software; you can redistribute it and/or modify it … … 19 19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 20 20 # 21 # vi: 22 # set ts=4 21 23 """ 22 24 Author: Bas van der Vlies … … 76 78 return project 77 79 78 def delete_spam(project, debug): 79 env = Environment(project, create=0) 80 db = env.get_db_cnx() 81 82 attachment_dir = os.path.join(env.path, 'attachments', 'ticket') 83 84 cursor = db.cursor() 85 tkt_cursor = db.cursor() 86 87 # Delete the attachments associated with Spam tickets 88 # 89 cursor.execute("SELECT id FROM ticket WHERE component = 'Spam';") 90 while 1: 91 row = cursor.fetchone() 92 if not row: 93 break 94 spam_id = row[0] 95 96 if debug: 97 sql_cmd = "SELECT * FROM attachment WHERE type='ticket' and id='%s';" %spam_id 98 tkt_cursor.execute(sql_cmd) 99 row = tkt_cursor.fetchone() 100 print row 101 102 sql_cmd = "SELECT * FROM ticket_change WHERE ticket='%s';" %spam_id 103 tkt_cursor.execute(sql_cmd) 104 row = tkt_cursor.fetchone() 105 print row 106 107 sql_cmd = "SELECT * FROM ticket_custom WHERE ticket='%s';" %spam_id 108 tkt_cursor.execute(sql_cmd) 109 row = tkt_cursor.fetchone() 110 print row 111 112 sql_cmd = "DELETE FROM attachment WHERE type='ticket' and id='%s';" %spam_id 113 tkt_cursor.execute(sql_cmd) 114 115 sql_cmd = "DELETE FROM ticket_change WHERE ticket='%s';" %spam_id 116 tkt_cursor.execute(sql_cmd) 117 118 sql_cmd = "DELETE FROM ticket_custom WHERE ticket='%s';" %spam_id 119 tkt_cursor.execute(sql_cmd) 120 121 # Ticket commit 122 # 123 db.commit() 124 125 dir = os.path.join(attachment_dir, str(spam_id)) 126 if os.path.exists(dir): 127 if debug: 128 print 'delete %s : %s' %(spam_id, dir) 129 try: 130 shutil.rmtree(dir) 131 except OSError, detail: 132 print 'Contact system-administrator: %s' %detail 133 continue 134 135 cursor.execute("DELETE FROM ticket WHERE component = 'Spam';") 136 db.commit() 80 81 82 def new_delete_spam(project, debug): 83 """ 84 This only works for trac versions higher or equal then 0.10 85 """ 86 env = Environment(project, create=0) 87 db = env.get_db_cnx() 88 89 cursor.execute("SELECT id FROM ticket WHERE component = 'Spam';") 90 while 1: 91 row = cursor.fetchone() 92 if not row: 93 break 94 95 spam_id = row[0] 96 97 try: 98 tkt = Ticket(env, spam_id, db) 99 except TracError, detail: 100 continue 101 102 if debug: 103 print "Deleting ticket %s" %spam_id 104 105 tkt.delete() 106 107 def old_delete_spam(project, debug): 108 """ 109 This only works for trac versions before 0.10 110 """ 111 env = Environment(project, create=0) 112 db = env.get_db_cnx() 113 114 attachment_dir = os.path.join(env.path, 'attachments', 'ticket') 115 cursor = db.cursor() 116 tkt_cursor = db.cursor() 117 118 # Delete the attachments associated with Spam tickets 119 # 120 cursor.execute("SELECT id FROM ticket WHERE component = 'Spam';") 121 while 1: 122 row = cursor.fetchone() 123 if not row: 124 break 125 spam_id = row[0] 126 127 if debug: 128 sql_cmd = "SELECT * FROM attachment WHERE type='ticket' and id='%s';" %spam_id 129 tkt_cursor.execute(sql_cmd) 130 row = tkt_cursor.fetchone() 131 print row 132 133 sql_cmd = "SELECT * FROM ticket_change WHERE ticket='%s';" %spam_id 134 tkt_cursor.execute(sql_cmd) 135 row = tkt_cursor.fetchone() 136 print row 137 138 sql_cmd = "SELECT * FROM ticket_custom WHERE ticket='%s';" %spam_id 139 tkt_cursor.execute(sql_cmd) 140 row = tkt_cursor.fetchone() 141 print row 142 143 sql_cmd = "DELETE FROM attachment WHERE type='ticket' and id='%s';" %spam_id 144 tkt_cursor.execute(sql_cmd) 145 146 sql_cmd = "DELETE FROM ticket_change WHERE ticket='%s';" %spam_id 147 tkt_cursor.execute(sql_cmd) 148 149 sql_cmd = "DELETE FROM ticket_custom WHERE ticket='%s';" %spam_id 150 tkt_cursor.execute(sql_cmd) 151 152 # Ticket commit 153 # 154 db.commit() 155 dir = os.path.join(attachment_dir, str(spam_id)) 156 if os.path.exists(dir): 157 if debug: 158 print 'delete %s : %s' %(spam_id, dir) 159 try: 160 shutil.rmtree(dir) 161 except OSError, detail: 162 print 'Contact system-administrator: %s' %detail 163 continue 164 165 cursor.execute("DELETE FROM ticket WHERE component = 'Spam';") 166 db.commit() 137 167 138 168 if __name__ == '__main__': … … 140 170 # 141 171 configfile = '@email2trac_conf@' 172 142 173 143 174 try: … … 169 200 version = trac_default_version 170 201 171 172 202 if version == 0.8: 173 203 from trac.Environment import Environment 174 204 else: 175 205 from trac.env import Environment 176 177 delete_spam(settings['project'], int(settings['debug'])) 206 from trac.ticket import Ticket 207 208 if version == 0.10: 209 new_delete_spam(settings['project'], int(settings['debug'])) 210 elif version == 0.9: 211 old_delete_spam(settings['project'], int(settings['debug'])) 212 elif version == 0.8: 213 old_delete_spam(settings['project'], int(settings['debug'])) 214 178 215 print 'Spam is deleted succesfully..' 179 180 216 # EOB
Note: See TracChangeset
for help on using the changeset viewer.