Minor tweak to cleanup. Using shutil instead of iterating file objects

This commit is contained in:
David Sauve 2009-08-05 16:44:12 -04:00
parent 8e5fcfafed
commit a6a1859029
2 changed files with 5 additions and 11 deletions

View file

@ -17,6 +17,7 @@
import cPickle as pickle
import datetime
import os
import shutil
import xapian
from django.conf import settings
@ -70,13 +71,8 @@ class XapianSearchBackendTestCase(TestCase):
def tearDown(self):
if os.path.exists(settings.HAYSTACK_XAPIAN_PATH):
index_files = os.listdir(settings.HAYSTACK_XAPIAN_PATH)
for index_file in index_files:
os.remove(os.path.join(settings.HAYSTACK_XAPIAN_PATH, index_file))
os.removedirs(settings.HAYSTACK_XAPIAN_PATH)
shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH)
settings.HAYSTACK_XAPIAN_PATH = self.old_xapian_path
super(XapianSearchBackendTestCase, self).tearDown()

View file

@ -18,6 +18,7 @@ import datetime
import cPickle as pickle
import os
import re
import shutil
import warnings
from django.conf import settings
@ -350,10 +351,7 @@ class SearchBackend(BaseSearchBackend):
This removes all indexes files and the `HAYSTACK_XAPIAN_PATH` folder.
"""
if os.path.exists(settings.HAYSTACK_XAPIAN_PATH):
index_files = os.listdir(settings.HAYSTACK_XAPIAN_PATH)
for index_file in index_files:
os.remove(os.path.join(settings.HAYSTACK_XAPIAN_PATH, index_file))
os.removedirs(settings.HAYSTACK_XAPIAN_PATH)
shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH)
def document_count(self):
"""