import os.path
-import traceback
import time
import sys
-#import socket for handling socket exceptions
-import socket
import logging
import logging.handlers
'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"
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))
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
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
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
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
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
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
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
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
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
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))
#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)
-#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
+""" 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):
-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?