示例#1
0
def check_files():
    '''
    Check that all the necessary images exist in the images folder and that the
    administrator specified in the config file exists.
    '''
    try:
        f = open('.config', 'r')
        admin = f.readline().split('=')[1]
        f.close()
        
        um = db.get_user_manager()
        
        # If the specified admin is not in the database, delete the config.
        # This will cause the logon screen to re-prompt user to create an admin
        # account.
        if not um.retrieve_user(admin):
            os.remove('.config')
    except IOError:
        # If the config doesn't exist, we don't care because the logon screen
        # will prompt the user to create an admin account.
        pass
    
    for image in files['images']:
        # Check that each image exists
        try:
            f = open('images/' + image, 'r')
            f.close()
        except IOError:
            tkMessageBox.showerror('Error', 'You are missing the file ' +
                                   image + '. Please reinstall.')
            return False
        
    return True
示例#2
0
 def end(self):
     '''Ends the spelling session.'''
     # Add the score for the session to the user object.
     self.user.add_score(self.wordlist.name, self.score)
     
     # Update the user record in the database.
     um = database.get_user_manager()
     um.update_user(self.user)
     um.commit()
     
     # Tell the interface the score the user achieved so that it can display
     # a score window.
     self.interface.session_ended(str(self.score) + '/' + str(self.list_length), str(self.highscore) + '/' + str(self.list_length), self.newhighscore, self.attempts)