Changeset 350
- Timestamp:
- 04/15/10 09:18:47 (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r349 r350 7 7 * Problems with attachments were not reported for ticket updates 8 8 Fixed by: Bas van der Vlies 9 10 * delete_spam changes: 11 - only support trac version greater then 0.10 12 - added -n/--dry-run option 13 - added -v/--verbose option 14 15 Author: Bas van der Vlies 9 16 10 17 2010-03-20 -
trunk/debian/changelog
r345 r350 1 email2trac (1.3.5-1) stable; urgency=low 2 3 * See Changes 4 5 -- Bas van der Vlies <basv@sara.nl> Thu, 15 Apr 2010 09:14:14 +0200 6 1 7 email2trac (1.3.2-1) stable; urgency=low 2 8 … … 7 13 Fixed by: Bas van der Vlies 8 14 9 -- root <root@subtrac2.rc.sara.nl> Tue, 30 Mar 2010 13:22:00 +020015 -- Bas van der Vlies <basv@sara.nl> Tue, 30 Mar 2010 13:22:00 +0200 10 16 11 17 email2trac (1.3.1-1) stable; urgency=low -
trunk/debian/control
r213 r350 9 9 Section: misc 10 10 Architecture: any 11 Maintainer: Bas van der Vlies <bas@sara.nl>12 11 Depends: ${slibs:Depends}, python, cdbs 13 12 Description: Converts email to a trac ticket -
trunk/delete_spam.py.in
r180 r350 28 28 29 29 Usage : 30 delete_spam [ -f/--file <configfile> -p/--project <name>]30 delete_spam [ -f/--file <configfile> -n/--dry-run -p/--project <name> -v/--verbose] 31 31 32 32 defaults: … … 80 80 81 81 82 def new_delete_spam(p roject, debug):82 def new_delete_spam(parameters): 83 83 """ 84 84 This only works for trac versions higher or equal then 0.10 85 85 """ 86 87 debug = int(parameters['debug']) 88 DRY_RUN = parameters['DRY_RUN'] 89 VERBOSE = parameters['VERBOSE'] 90 91 project = parameters['project'] 92 93 86 94 env = Environment(project, create=0) 87 95 db = env.get_db_cnx() … … 96 104 spam_id = row[0] 97 105 98 if debug :106 if debug or DRY_RUN or VERBOSE: 99 107 print "Deleting ticket %s" %spam_id 100 108 … … 105 113 continue 106 114 107 tkt.delete() 108 109 def old_delete_spam(project, debug): 110 """ 111 This only works for trac versions before 0.10 112 """ 113 env = Environment(project, create=0) 114 db = env.get_db_cnx() 115 116 attachment_dir = os.path.join(env.path, 'attachments', 'ticket') 117 cursor = db.cursor() 118 tkt_cursor = db.cursor() 119 120 # Delete the attachments associated with Spam tickets 121 # 122 cursor.execute("SELECT id FROM ticket WHERE component = 'Spam';") 123 while 1: 124 row = cursor.fetchone() 125 if not row: 126 break 127 spam_id = row[0] 128 129 if debug: 130 print spam_id 131 132 sql_cmd = "SELECT * FROM attachment WHERE type='ticket' and id='%s';" %spam_id 133 tkt_cursor.execute(sql_cmd) 134 row = tkt_cursor.fetchone() 135 print row 136 137 sql_cmd = "SELECT * FROM ticket_change WHERE ticket='%s';" %spam_id 138 tkt_cursor.execute(sql_cmd) 139 row = tkt_cursor.fetchone() 140 print row 141 142 sql_cmd = "SELECT * FROM ticket_custom WHERE ticket='%s';" %spam_id 143 tkt_cursor.execute(sql_cmd) 144 row = tkt_cursor.fetchone() 145 print row 146 147 sql_cmd = "DELETE FROM attachment WHERE type='ticket' and id='%s';" %spam_id 148 tkt_cursor.execute(sql_cmd) 149 150 sql_cmd = "DELETE FROM ticket_change WHERE ticket='%s';" %spam_id 151 tkt_cursor.execute(sql_cmd) 152 153 sql_cmd = "DELETE FROM ticket_custom WHERE ticket='%s';" %spam_id 154 tkt_cursor.execute(sql_cmd) 155 156 # Ticket commit 157 # 158 db.commit() 159 160 dir = os.path.join(attachment_dir, str(spam_id)) 161 if os.path.exists(dir): 162 if debug: 163 print 'delete %s : %s' %(spam_id, dir) 164 try: 165 shutil.rmtree(dir) 166 except OSError, detail: 167 print 'Contact system-administrator: %s' %detail 168 continue 169 170 cursor.execute("DELETE FROM ticket WHERE component = 'Spam';") 171 db.commit() 115 if DRY_RUN: 116 print 'DRY_RUN: tkt.delete()' 117 else: 118 print 'For echt tkt.delete()' 172 119 173 120 if __name__ == '__main__': … … 178 125 179 126 try: 180 opts, args = getopt.getopt(sys.argv[1:], 'hf: p:', ['help', 'file=', 'project='])127 opts, args = getopt.getopt(sys.argv[1:], 'hf:np:v', ['help', 'file=', 'dry-run', 'project=', 'verbose']) 181 128 except getopt.error,detail: 182 129 print __doc__ … … 184 131 sys.exit(1) 185 132 133 DRY_RUN = False 134 VERBOSE = False 186 135 project_name = None 136 187 137 for opt,value in opts: 188 138 if opt in [ '-h', '--help']: … … 191 141 elif opt in ['-f', '--file']: 192 142 configfile = value 143 elif opt in ['-n', '--dry-run']: 144 DRY_RUN = True 193 145 elif opt in ['-p', '--project']: 194 146 project_name = value 147 elif opt in ['-v', '--verbose']: 148 VERBOSE = True 195 149 196 150 settings = ReadConfig(configfile, project_name) … … 205 159 version = trac_default_version 206 160 161 settings['DRY_RUN'] = DRY_RUN 162 settings['VERBOSE'] = VERBOSE 163 207 164 from trac.env import Environment 208 165 from trac.ticket import Ticket 209 166 from trac import util 210 167 211 if version == 0.10: 212 new_delete_spam(settings['project'], int(settings['debug'])) 213 #new_delete_spam(settings['project'], 1) 214 #old_delete_spam(settings['project'], 0) 215 elif version == 0.9: 216 old_delete_spam(settings['project'], int(settings['debug'])) 168 169 if version < 0.10: 170 print 'Trac version %s is not suported' %(version) 171 172 new_delete_spam(settings) 217 173 218 174 print 'Spam is deleted succesfully..'
Note: See TracChangeset
for help on using the changeset viewer.