Index: /trunk/ChangeLog
===================================================================
--- /trunk/ChangeLog	(revision 349)
+++ /trunk/ChangeLog	(revision 350)
@@ -7,4 +7,11 @@
   * Problems with attachments were not reported for ticket updates 
     Fixed by: Bas van der Vlies
+
+  * delete_spam changes:
+     - only support trac version greater then 0.10
+     - added -n/--dry-run option
+     - added -v/--verbose option
+
+    Author: Bas van der Vlies
 
 2010-03-20
Index: /trunk/debian/changelog
===================================================================
--- /trunk/debian/changelog	(revision 349)
+++ /trunk/debian/changelog	(revision 350)
@@ -1,2 +1,8 @@
+email2trac (1.3.5-1) stable; urgency=low
+
+  *  See Changes
+
+ -- Bas van der Vlies <basv@sara.nl>  Thu, 15 Apr 2010 09:14:14 +0200
+
 email2trac (1.3.2-1) stable; urgency=low
 
@@ -7,5 +13,5 @@
     Fixed by: Bas van der Vlies
 
- -- root <root@subtrac2.rc.sara.nl>  Tue, 30 Mar 2010 13:22:00 +0200
+ -- Bas van der Vlies <basv@sara.nl>  Tue, 30 Mar 2010 13:22:00 +0200
 
 email2trac (1.3.1-1) stable; urgency=low
Index: /trunk/debian/control
===================================================================
--- /trunk/debian/control	(revision 349)
+++ /trunk/debian/control	(revision 350)
@@ -9,5 +9,4 @@
 Section: misc
 Architecture: any
-Maintainer: Bas van der Vlies <bas@sara.nl>
 Depends: ${slibs:Depends}, python, cdbs
 Description: Converts email to a trac ticket
Index: /trunk/delete_spam.py.in
===================================================================
--- /trunk/delete_spam.py.in	(revision 349)
+++ /trunk/delete_spam.py.in	(revision 350)
@@ -28,5 +28,5 @@
 
 Usage :
-	delete_spam [ -f/--file <configfile> -p/--project <name>]
+	delete_spam [ -f/--file <configfile>  -n/--dry-run -p/--project <name> -v/--verbose]
 
 defaults:
@@ -80,8 +80,16 @@
 
 
-def new_delete_spam(project, debug):
+def new_delete_spam(parameters):
 	"""
 	This only works for trac versions higher or equal then 0.10
 	"""
+
+	debug = int(parameters['debug'])
+	DRY_RUN = parameters['DRY_RUN']
+	VERBOSE = parameters['VERBOSE']
+
+	project = parameters['project']
+
+
 	env = Environment(project, create=0)
 	db = env.get_db_cnx()
@@ -96,5 +104,5 @@
 		spam_id =  row[0]
 
-		if debug:
+		if debug or DRY_RUN or VERBOSE:
 			print "Deleting ticket %s" %spam_id
 
@@ -105,69 +113,8 @@
 			continue
 
-		tkt.delete()
-
-def old_delete_spam(project, debug):
-	"""
-	This only works for trac versions before 0.10
-	"""
-	env = Environment(project, create=0)
-	db = env.get_db_cnx() 
-	
-	attachment_dir = os.path.join(env.path, 'attachments', 'ticket') 
-	cursor = db.cursor()
-	tkt_cursor = db.cursor() 
-	
-	# Delete the attachments associated with Spam tickets
-	#
-	cursor.execute("SELECT id FROM ticket WHERE  component = 'Spam';") 
-	while 1:
-		row = cursor.fetchone()
-		if not row:
-			break
-		spam_id =  row[0] 
-	
-		if debug:
-			print spam_id 
-
-			sql_cmd = "SELECT *  FROM attachment WHERE type='ticket' and id='%s';" %spam_id
-			tkt_cursor.execute(sql_cmd) 
-			row = tkt_cursor.fetchone()
-			print row 
-			
-			sql_cmd = "SELECT * FROM ticket_change WHERE ticket='%s';" %spam_id 
-			tkt_cursor.execute(sql_cmd) 
-			row = tkt_cursor.fetchone()
-			print row 
-			
-			sql_cmd = "SELECT * FROM ticket_custom WHERE ticket='%s';" %spam_id
-			tkt_cursor.execute(sql_cmd) 
-			row = tkt_cursor.fetchone()
-			print row 
-			
-		sql_cmd = "DELETE FROM attachment WHERE type='ticket' and id='%s';" %spam_id
-		tkt_cursor.execute(sql_cmd) 
-
-		sql_cmd = "DELETE FROM ticket_change WHERE ticket='%s';" %spam_id
-		tkt_cursor.execute(sql_cmd) 
-			
-		sql_cmd = "DELETE FROM ticket_custom WHERE ticket='%s';" %spam_id
-		tkt_cursor.execute(sql_cmd) 
-			
-		# Ticket commit 
-		# 
-		db.commit() 
-
-		dir = os.path.join(attachment_dir, str(spam_id)) 
-		if os.path.exists(dir):
-			if debug:
-				print 'delete %s : %s' %(spam_id, dir)
-			try: 
-				shutil.rmtree(dir) 
-			except OSError, detail: 
-				print 'Contact system-administrator: %s' %detail
-				continue
-
-	cursor.execute("DELETE FROM ticket WHERE  component = 'Spam';") 
-	db.commit()
+		if DRY_RUN:
+			print 'DRY_RUN: tkt.delete()'
+		else:
+			print 'For echt tkt.delete()'
 
 if __name__ == '__main__':
@@ -178,5 +125,5 @@
 
 	try:
-		 opts, args = getopt.getopt(sys.argv[1:], 'hf:p:', ['help', 'file=', 'project='])
+		 opts, args = getopt.getopt(sys.argv[1:], 'hf:np:v', ['help', 'file=', 'dry-run', 'project=', 'verbose'])
 	except getopt.error,detail:
 		print __doc__
@@ -184,5 +131,8 @@
 		sys.exit(1)
 
+	DRY_RUN = False
+	VERBOSE = False
 	project_name = None
+
 	for opt,value in opts:
 		if opt in [ '-h', '--help']:
@@ -191,6 +141,10 @@
 		elif opt in ['-f', '--file']:
 			configfile = value
+		elif opt in ['-n', '--dry-run']:
+			DRY_RUN = True
 		elif opt in ['-p', '--project']:
 			project_name = value
+		elif opt in ['-v', '--verbose']:
+			VERBOSE = True
 	
 	settings = ReadConfig(configfile, project_name)
@@ -205,14 +159,16 @@
 		version = trac_default_version
 
+	settings['DRY_RUN'] = DRY_RUN
+	settings['VERBOSE'] = VERBOSE
+
 	from trac.env import Environment
 	from trac.ticket import Ticket
 	from trac import util
 
-	if version == 0.10:
-		new_delete_spam(settings['project'], int(settings['debug']))
-		#new_delete_spam(settings['project'], 1)
-		#old_delete_spam(settings['project'], 0)
-	elif version == 0.9:
-		old_delete_spam(settings['project'], int(settings['debug']))
+
+	if version < 0.10:
+		print 'Trac version %s is not suported' %(version)
+
+	new_delete_spam(settings)
 
 	print 'Spam is deleted succesfully..' 
