improving our pylint scores
authorRyan Campbell <campbellr@gmail.com>
Fri, 30 Apr 2010 01:15:40 +0000 (19:15 -0600)
committerRyan Campbell <campbellr@gmail.com>
Fri, 30 Apr 2010 01:15:40 +0000 (19:15 -0600)
package/src/mevemon.py

index d138978..602f3b1 100755 (executable)
@@ -31,12 +31,15 @@ import gnome.gconf
 #ugly hack to check maemo version. any better way?
 if hasattr(hildon, "StackableWindow"):
     from ui.fremantle import gui
-    is_fremantle = True
 else:
     from ui.diablo import gui
-    is_fremantle = False
 
 class mEveMon():
+    """
+    The controller class for mEvemon. The intent is to help
+    abstract the EVE API and settings code from the UI code.
+
+    """
     def __init__(self):
         self.program = hildon.Program()
         self.program.__init__()
@@ -52,6 +55,9 @@ class mEveMon():
         gtk.main_quit()
 
     def get_accounts(self):
+        """
+        Returns a dictionary containing uid:api_key pairs gathered from gconf
+        """
         accounts = {}
         entries = self.gconf.all_entries("/apps/maemo/mevemon/accounts")
 
@@ -63,65 +69,97 @@ class mEveMon():
         return accounts
         
     def get_api_key(self, uid):
+        """
+        Returns the api key associated with the given uid.
+        """
         return self.gconf.get_string("/apps/maemo/mevemon/accounts/%s" % uid) or ''
 
     def remove_account(self, uid):
+        """
+        Removes the provided uid key from gconf
+        """
         self.gconf.unset("/apps/maemo/mevemon/accounts/%s" % uid)
 
     def add_account(self, uid, api_key):
+        """
+        Adds the provided uid:api_key pair to gconf.
+        """
         self.gconf.set_string("/apps/maemo/mevemon/accounts/%s" % uid, api_key)
 
     def get_auth(self, uid):
+        """
+        Returns an authentication object to be used for eveapi calls
+        that require authentication.
+        """
         api_key = self.get_api_key(uid)
 
         try:
             auth = self.cached_api.auth(userID=uid, apiKey=api_key)
-        except eveapi.Error, e:
+        except eveapi.Error:
             return None
 
         return auth
 
-    def get_char_sheet(self, uid, charID):
+    def get_char_sheet(self, uid, char_id):
+        """
+        Returns an object containing information about the character specified
+        by the provided character ID.
+        """
         try:
-            sheet = self.get_auth(uid).character(charID).CharacterSheet()
-        except eveapi.Error, e:
-            # we should really have a logger that logs this error somewhere
+            sheet = self.get_auth(uid).character(char_id).CharacterSheet()
+        except eveapi.Error:
+            # TODO: we should really have a logger that logs this error somewhere
             return None
 
         return sheet
 
-    def charid2uid(self, charID):
+    def charid2uid(self, char_id):
+        """
+        Takes a character ID and returns the user ID of the account containing
+        the character.
+
+        Returns None if the character isn't found in any of the registered accounts.
+
+        """
         acct_dict = self.get_accounts()
         
-        for uid, apiKey in acct_dict.items():
-            auth = self.cached_api.auth(userID=uid, apiKey=apiKey)
+        for uid, api_key in acct_dict.items():
+            auth = self.cached_api.auth(userID=uid, apiKey=api_key)
             api_char_list = auth.account.Characters()
             
             for character in api_char_list.characters:
-                if character.characterID== charID:
+                if character.characterID == char_id:
                     return uid
 
         
         return None
     
-    def char_id2name(self, charID):
-        # the api can take a comma-seperated list of ids, but we'll just take
-        # a single id for now
+    def char_id2name(self, char_id):
+        """
+        Takes a character ID and returns the character name associated with
+        that ID.
+        The EVE API accepts a comma-separated list of IDs, but for now we
+        will just handle a single ID.
+        """
         try:
-            chars = self.cached_api.eve.CharacterName(ids=charID).characters
+            chars = self.cached_api.eve.CharacterName(ids=char_id).characters
             name = chars[0].characterName
-        except eveapi.Error, e:
+        except eveapi.Error:
             return None
 
         return name
 
     def char_name2id(self, name):
-        # the api can take a comma-seperated list of names, but we'll just take
-        # a single name for now
+        """
+        Takes the name of an EVE character and returns the characterID.
+        
+        The EVE api accepts a comma separated list of names, but for now
+        we will just handle single names/
+        """
         try:
             chars = self.cached_api.eve.CharacterID(names=name).characters
             char_id = chars[0].characterID
-        except eveapi.Error, e:
+        except eveapi.Error:
             return None
 
         return char_id
@@ -129,8 +167,12 @@ class mEveMon():
     
     def get_characters(self):
         """
-        returns a list containing a single character with an error message for a
-        name, if there's a problem. FIXME --danny
+        Returns a list of (character_name, image_path) pairs from all the
+        accounts that are registered to mEveMon.
+        
+        If there is an authentication issue, then instead of adding a valid
+        pair to the list, it appends an 'error message' 
+
         """
         ui_char_list = []
         err_img = "/usr/share/mevemon/imgs/error.jpg"
@@ -141,41 +183,46 @@ class mEveMon():
         if not acct_dict:
             return [placeholder_chars]
 
-        for uid, apiKey in acct_dict.items():
-            auth = self.cached_api.auth(userID=uid, apiKey=apiKey)
+        for uid, api_key in acct_dict.items():
+            auth = self.cached_api.auth(userID=uid, apiKey=api_key)
             try:
                 api_char_list = auth.account.Characters()
                 # append each char we get to the list we'll return to the
                 # UI --danny
                 for character in api_char_list.characters:
                     ui_char_list.append( ( character.name, fetchimg.portrait_filename( character.characterID, 64 ), uid) )
-            except eveapi.Error, e:
-                # again, we need to handle this... --danny
+            except eveapi.Error:
                 ui_char_list.append(placeholder_chars)
 
         return ui_char_list
 
     def get_portrait(self, char_name, size):
         """
-        returns the relative path of the retrieved portrait
+        Returns the relative path of the retrieved portrait
         """
-        charID = self.char_name2id(char_name)
-        return fetchimg.portrait_filename(charID, size)
+        char_id = self.char_name2id(char_name)
+        return fetchimg.portrait_filename(char_id, size)
 
     def get_skill_tree(self):
+        """
+        Returns an object from eveapi containing skill tree info
+        """
         try:
             tree = self.cached_api.eve.SkillTree()
-        except eveapi.Error, e:
-            print e
+        except eveapi.Error:
             return None
         
         return tree
 
-    def get_skill_in_training(self, uid, charID):
+    def get_skill_in_training(self, uid, char_id):
+        """
+        Returns an object from eveapi containing information about the
+        current skill in training
+
+        """
         try:
-            skill = self.get_auth(uid).character(charID).SkillInTraining()
-        except:
-            print e
+            skill = self.get_auth(uid).character(char_id).SkillInTraining()
+        except eveapi.Error:
             return None
 
         return skill