Only remove contents of directory when clicking 'clear cache'
[mevemon] / package / src / mevemon.py
index 1cc6179..f8036e4 100755 (executable)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-import os.path
+import os
 import time
 import sys
 import logging
 import logging.handlers
+import util
 
 import hildon
 import gtk
@@ -31,7 +32,9 @@ import conic
 from eveapi import eveapi
 import fetchimg
 import apicache
-import settings
+import file_settings as settings
+from constants import LOGPATH, MAXBYTES, LOGCOUNT, CONFIG_DIR, IMG_CACHE_PATH
+from constants import APICACHE_PATH
 
 #ugly hack to check maemo version. any better way?
 if hasattr(hildon, "StackableWindow"):
@@ -39,23 +42,10 @@ if hasattr(hildon, "StackableWindow"):
 else:
     from ui.diablo import gui
 
-LOGNAME = "mevemon.log"
-CONFIG_DIR = os.path.expanduser("~/.mevemon/")
-LOGPATH = os.path.join(CONFIG_DIR, LOGNAME)
-
 class mEveMon:
     """ The controller class for mEvemon. The intent is to help
         abstract the EVE API and settings code from the UI code.
     """
-
-    about_name = 'mEveMon'
-    about_text = ('Mobile character monitor for EVE Online')
-    about_authors = ['Ryan Campbell <campbellr@gmail.com>',
-                     'Danny Campbell <danny.campbell@gmail.com>']
-
-    about_website = 'http://mevemon.garage.maemo.org'
-    app_version = '0.5-1'
-
     def __init__(self):
         self.program = hildon.Program()
         self.connect_to_network()
@@ -181,7 +171,7 @@ class mEveMon:
 
         ui_char_list = []
         err_img = "/usr/share/mevemon/imgs/error.jpg"
-        err_txt = "Problem fetching info for account"
+        err_txt = "Problem fetching info for account (or no accounts added)"
 
         placeholder_chars = (err_txt, err_img, None)
         
@@ -295,6 +285,13 @@ class mEveMon:
 
         return (spps * time_diff) 
 
+    def clear_cache(self):
+        """ Clears all cached data (images and eveapi cache) """
+        try:
+            util.clean_dir(IMG_CACHE_PATH)
+            util.clean_dir(APICACHE_PATH)
+        except OSError, e:
+            logging.getLogger('mevemon').exception("Failed to clear cache")
 
 def excepthook(ex_type, value, tb):
     """ a replacement for the default exception handler that logs errors"""
@@ -303,8 +300,8 @@ def excepthook(ex_type, value, tb):
 
 def setupLogger():
     """ sets up the logging """
-    MAXBYTES = 1 * 1000 * 1000 # 1MB
-    LOGCOUNT = 10
+    if not os.path.exists(CONFIG_DIR):
+        os.makedirs(CONFIG_DIR)
 
     logger = logging.getLogger("mevemon")
     logger.setLevel(logging.DEBUG)