import sys
import logging
import logging.handlers
-import shutil
+import util
import hildon
import gtk
def clear_cache(self):
""" Clears all cached data (images and eveapi cache) """
try:
- shutil.rmtree(IMG_CACHE_PATH)
- shutil.rmtree(APICACHE_PATH)
+ util.clean_dir(IMG_CACHE_PATH)
+ util.clean_dir(APICACHE_PATH)
except OSError, e:
logging.getLogger('mevemon').exception("Failed to clear cache")
""" this module tests the util.py module """
import unittest
+import tempfile
+import shutil
+import os
import util
for number in NUMBERS.keys():
self.assertEqual(util.comma(number), NUMBERS[number])
+ def test_clean_dir(self):
+ self._setup_files()
+ try:
+ self.assertEqual(len(os.listdir(self.basedir)), 3)
+ util.clean_dir(self.basedir)
+ self.assertTrue(os.path.exists(self.basedir))
+ self.assertEqual(len(os.listdir(self.basedir)), 0)
+ finally:
+ if os.path.exists(self.basedir):
+ shutil.rmtree(self.basedir)
+ def _setup_files(self):
+ self.basedir = os.path.join(tempfile.gettempdir(), "mevemontest")
+ os.mkdir(self.basedir)
+ os.mkdir(os.path.join(self.basedir, "testdir"))
+ os.system("touch %s" % os.path.join(self.basedir, "testfile1"))
+ os.system("touch %s" % os.path.join(self.basedir, "testfile2"))
"""Random helpful functions for mevemon """
-
+import os
+import shutil
+
def comma(number):
"""Converts a number in the format 1234567 to 1,234,567
"""
else:
return ','.join(thousands) + '.' + fractional_part
+def clean_dir(path):
+ """ Removes the contents of a directory, but not the directory itself
+ """
+ names = os.listdir(path)
+ for name in names:
+ fullname = os.path.join(path, name)
+ if os.path.isdir(fullname):
+ shutil.rmtree(fullname)
+ else:
+ os.remove(fullname)