minor pylint cleanup
authorRyan Campbell <campbellr@gmail.com>
Sat, 1 Jan 2011 22:13:18 +0000 (15:13 -0700)
committerRyan Campbell <campbellr@gmail.com>
Sat, 1 Jan 2011 22:13:18 +0000 (15:13 -0700)
package/src/mevemon.py
package/src/ui/diablo/gui.py
package/src/ui/fremantle/dialogs.py
package/src/ui/fremantle/gui.py
package/src/util.py
package/src/validation.py

index af2e701..c4f5c50 100755 (executable)
 
 
 import os.path
-import traceback
 import time
 import sys
-#import socket for handling socket exceptions
-import socket
 import logging
 import logging.handlers
 
@@ -60,7 +57,7 @@ class mEveMon():
                      'Danny Campbell <danny.campbell@gmail.com>']
 
     about_website = 'http://mevemon.garage.maemo.org'
-    app_version = '0.4-8'
+    app_version = '0.5-1'
 
 
     GCONF_DIR = "/apps/maemo/mevemon"
@@ -69,8 +66,6 @@ class mEveMon():
         self.program = hildon.Program()
         self.program.__init__()
         self.gconf = gnome.gconf.client_get_default()
-        #NOTE: remove this after a few releases
-        self.update_settings()
         self.connect_to_network()
         self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \
                 apicache.cache_handler(debug=False))
@@ -83,18 +78,6 @@ class mEveMon():
     def quit(self, *args):
         gtk.main_quit()
 
-    def update_settings(self):
-        """ Update from the old pre 0.3 settings to the new settings layout.
-            We should remove this eventually, once no one is using pre-0.3 mEveMon
-        """
-        uid = self.gconf.get_string("%s/eve_uid" % self.GCONF_DIR)
-        
-        if uid:
-            key = self.gconf.get_string("%s/eve_api_key" % self.GCONF_DIR)
-            self.add_account(uid, key)
-            self.gconf.unset("%s/eve_uid" % self.GCONF_DIR)
-            self.gconf.unset("%s/eve_api_key" % self.GCONF_DIR)
-
 
     def get_accounts(self):
         """ Returns a dictionary containing uid:api_key pairs gathered from gconf
@@ -135,7 +118,7 @@ class mEveMon():
             auth = self.cached_api.auth(userID=uid, apiKey=api_key)
         except Exception, e:
             self.gui.report_error(str(e))
-            traceback.print_exc()
+            logging.getLogger('meEveMon').exception("Failed to get character name")
             return None
 
         return auth
@@ -148,8 +131,7 @@ class mEveMon():
             sheet = self.get_auth(uid).character(char_id).CharacterSheet()
         except Exception, e:
             self.gui.report_error(str(e))
-            # TODO: we should really have a logger that logs this error somewhere
-            traceback.print_exc()
+            logging.getLogger('meEveMon').exception("Failed to get character name")
             return None
 
         return sheet
@@ -175,8 +157,6 @@ class mEveMon():
                 if character.characterID == char_id:
                     return uid
 
-        
-        return None
     
     def char_id2name(self, char_id):
         """ Takes a character ID and returns the character name associated with
@@ -189,7 +169,7 @@ class mEveMon():
             name = chars[0].characterName
         except Exception, e:
             self.gui.report_error(str(e))
-            traceback.print_exc()
+            logging.getLogger('meEveMon').exception("Failed to get character name")
             return None
 
         return name
@@ -206,7 +186,7 @@ class mEveMon():
             char_name = chars[0].name
         except Exception, e:
             self.gui.report_error(str(e))
-            traceback.print_exc()
+            logging.getLogger('meEveMon').exception("Failed to get ID")
             return None
 
         return char_id
@@ -223,7 +203,7 @@ class mEveMon():
                 char_list = [char.name for char in api_char_list.characters]
             except Exception, e:
                 self.gui.report_error(str(e))
-                traceback.print_exc()
+                logging.getLogger('meEveMon').exception("Failed to get character list")
                 return None
 
         return char_list
@@ -273,7 +253,7 @@ class mEveMon():
             tree = self.cached_api.eve.SkillTree()
         except Exception, e:
             self.gui.report_error(str(e))
-            traceback.print_exc()
+            logging.getLogger('meEveMon').exception("Failed to get skill-in-training:")
             return None
         
         return tree
@@ -286,7 +266,7 @@ class mEveMon():
             skill = self.get_auth(uid).character(char_id).SkillInTraining()
         except Exception, e:
             self.gui.report_error(str(e))
-            traceback.print_exc()
+            logging.getLogger('meEveMon').exception("Failed to get skill-in-training:")
             return None
 
         return skill
@@ -355,8 +335,6 @@ class mEveMon():
 
 def excepthook(ex_type, value, tb):
     """ a replacement for the default exception handler that logs errors"""
-    #tb2 = "".join(traceback.format_exception(ex_type, value, tb))
-    #print tb2
     logging.getLogger('meEveMon').error('Uncaught exception:', 
                       exc_info=(ex_type, value, tb))
 
@@ -376,8 +354,6 @@ def setupLogger():
     #create console handler
     console = logging.StreamHandler()
     console.setLevel(logging.DEBUG)
-    #formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
-    #console.setFormatter(formatter)
     logger.addHandler(console)
 
 
index e3235c9..cbc2b4c 100644 (file)
@@ -187,8 +187,8 @@ class BaseUI():
                 api_key = apiEntry.get_text()
             
                 try:
-                    validation.uid(uid)
-                    validation.api_key(api_key)
+                    validation.validate_uid(uid)
+                    validation.validate_api_key(api_key)
                 except validation.ValidationError, e:
                     self.report_error(e.message)
                     result = dialog.run()
index af1ce18..6fbb527 100644 (file)
@@ -82,8 +82,8 @@ class NewAccountDialog(gtk.Dialog):
                 uid = self.uidEntry.get_text()
                 api_key = self.apiEntry.get_text()
                 try:
-                    validation.uid(uid)
-                    validation.api_key(api_key)
+                    validation.validate_uid(uid)
+                    validation.validate_api_key(api_key)
                 except validation.ValidationError, e:
                     self.report_error(e.message)
                     result = self.run()
index 7e4a4f7..8c8d045 100644 (file)
@@ -22,7 +22,6 @@ import gobject
 
 from ui.fremantle.characterSheet import CharacterSheetUI
 import ui.models as models
-import validation
 from ui.fremantle.menu import Menu
 
 class mEveMonUI:
index f2c7955..8a2c26f 100644 (file)
@@ -1,21 +1,21 @@
-#Random helpful functions for mevemon
+"""Random helpful functions for mevemon """
  
-def comma(d):
+def comma(number):
+    """Converts a number in the format 1234567 to 1,234,567
     """
-    Converts a number in the format 1234567 to 1,234,567
-    """
-    s = '%0.2f' % d
+    num_string = '%0.2f' % number
     
-    a,b = s.split('.')
-    l = []
-    while len(a) > 3:
-        l.insert(0,a[-3:])
-        a = a[0:-3]
-    if a:
-        l.insert(0,a)
+    #a,b = num_string.split('.')
+    decimal_part, fractional_part = num_string.split('.')
+    thousands = []
+    while len(decimal_part) > 3:
+        thousands.insert(0, decimal_part[-3:])
+        decimal_part = decimal_part[0:-3]
+    if decimal_part:
+        thousands.insert(0, decimal_part)
 
-    if type(d) is int:
-        return ','.join(l)
+    if type(number) is int:
+        return ','.join(thousands)
     else:
-        return ','.join(l)+'.'+b
+        return ','.join(thousands) + '.' + fractional_part
 
index cf37fd7..76cfb9e 100644 (file)
@@ -1,6 +1,12 @@
+""" This module contains all our input validation functions """
+
+KEY_SIZE = 64
 
 class ValidationError(StandardError):
+    """ Exception that is raised if input validation fails
+    """
     def __init__(self, message):
+        StandardError.__init__(self)
         self.message = message
 
     def __str__(self):
@@ -8,30 +14,22 @@ class ValidationError(StandardError):
 
 
 
-def api_key(api_key):
-    """
-    validates an EVE api key. throws ValidationError exception if the
-    format is invalid.
+def validate_api_key(api_key):
+    """ Validates an EVE api key. throws ValidationError exception if the
+        format is invalid.
     """
-    KEY_SIZE = 64 
-
     #TODO: anything else we can do to validate the api key?
     
     if len(api_key) != KEY_SIZE:
         raise ValidationError("API Key must be %s characters" % KEY_SIZE)
     elif not api_key.isalnum():
-        raise ValidationError("API Key must only contain alphanumeric characters")
-    # apparently the api key CAN contain lower case characters...
-    #elif not api_key.isupper():
-    #    raise ValidationError("API Key must only contain upper-case characters")
-
-    return True
+        raise ValidationError("API Key must only contain alphanumeric " +\
+                              "characters")
 
 
-def uid(uid):
-    """
-    validates an EVE Online uid, throws ValidationError exception if the
-    format is invalid.
+def validate_uid(uid):
+    """ Validates an EVE Online uid, throws ValidationError exception if the
+        format is invalid.
     """
     #TODO: anything else we can do to validate the uid?