def doLogin(name): profileManager = ProfileManager() _setSession(profileManager.doLogin(name))
def checkUserName(value): profileManager = ProfileManager() if value not in profileManager.getProfileNames(): raise ValueError,"Profile [%s] not currently stored!\n" % (value)
if __name__ == "__main__": usage = "usage: %prog [options] username matchname" parser = optparse.OptionParser(usage) parser.add_option('-e','--error',help="error on failure",action="store_true",default=False) options, args = parser.parse_args() if len(args) == 1: userName = args[0] matchName = args[0] elif len(args) == 2: userName = args[0] matchName = args[1] else: parser.print_help() sys.exit() profileManager = ProfileManager() session = profileManager.doLogin(userName) if userName == matchName: profile = UserProfile() else: profile = MatchProfile() if profile.loadFromSession(session,matchName,options.error): sys.stderr.write(profile.saveToString()) else: sys.stderr.write("Profile failed to load\n")
if (options.examine) and len(args) != 1 and len(args) != 2: sys.stderr.write("Examine takes one or two arguments\n") sys.exit() if options.list and len(args) != 0: sys.stderr.write("List takes no arguments\n") sys.exit() if (options.save or options.restore or options.diff) and len(args) != 2: sys.stderr.write("Save, Restore and Diff take two arguments\n") sys.exit() setManager = SetManager() if (options.save or options.restore or options.examine or options.clear or options.diff): profileManager = ProfileManager() userName = args[0] if len(args) == 2: setName = args[1] if userName not in profileManager.getProfileNames(): sys.stderr.write("No such profile stored\n") sys.exit(0) if options.examine: session = profileManager.doLogin(userName) profile = UserProfile() if len(args) == 2: answer = profile.getAnswerFromSession(session,int(args[1])) sys.stderr.write("Answer [%s]\n" % answer) setManager.printSet({answer.Id : answer}) else: profile.loadFromSession(session,userName)