def get_identifier(self): return auth.get_identifier(self.cmd_args, endpoint=self.endpoint)
def start_firebase(self, messages): access_token = auth.authenticate(False) email = auth.get_student_email(access_token) identifier = auth.get_identifier(token=access_token, email=email) firebase = pyrebase.initialize_app(self.FIREBASE_CONFIG) self.fire_auth = firebase.auth() self.fire_db = firebase.database() self.user_email = email self.hostname = platform.node() data = { 'access_token': access_token, 'email': email, 'identifier': identifier, 'assignment': self.assignment.endpoint, 'file_contents': messages.get('file_contents'), 'analytics': messages.get('analytics'), } # Check for existing sessions first - TBD Future # existing_sessions = self.send_messages(data, endpoint='/collab/list') # response = self.prompt_for_existing_session(existing_sessions.get('sessions')) # if response: # data['desired_session'] = response # Send data to collaborate server response_data = self.send_messages(data, self.LONG_TIMEOUT) if 'error' in response_data or 'session' not in response_data: print("There was an error while starting the session: {} Try again later" .format(response_data.get('error'))) log.warning("Error: {}".format(response_data.get('error'))) return self.session_id = response_data['session'] self.short_url = response_data['short_url'] self.login_user = response_data.get('login_user') # Login as the firebase user email, password = response_data.get('login_user'), response_data.get('password') try: self.fire_user = self.fire_auth.sign_in_with_email_and_password(email, password) self.fire_uid = self.fire_user['localId'] except (ValueError, KeyError) as e: log.warning("Could not login", exc_info=True) print("Could not login to the collaboration server.") return self.stream = (self.get_firebase() .child('actions').stream(self.stream_listener, self.fire_user['idToken'])) self.presence = (self.get_firebase() .child('clients').push({'computer': platform.node(), 'uid': self.fire_uid, 'owner': self.user_email, 'email': self.user_email}, self.fire_user['idToken'])) # Parse response_url if response_data: open_url = response_data['url'] if 'access_token' not in open_url: open_url = open_url + "?access_token={}".format(access_token) could_open = webbrowser.open_new(open_url) if not could_open: print("Could not open browser. Go to {}".format(open_url)) else: log.error("There was an error with the server. Please try again later!") return print("Tell your group members or course staff to go to {}" .format(self.short_url)) while True: data = input("[{}] Type exit to disconnect: ".format(self.short_url)) if data.strip().lower() == 'exit': raise ValueError('Done with session')
def run(self, messages): if not self.args.style: log.info("Autostyle not enabled.") return elif self.args.local: log.info("Autostyle requires network access.") return if not messages.get('analytics'): log.warning("Autostyle needs to be after analytics") return if not messages.get('grading'): log.warning("Autostyle needs to be after grading") return if not self.args.question: log.warning("Autostyle requires a specific question") return messages['autostyle'] = {} grading = messages['grading'] if not self.args.question: log.info("-q flag was not specified") print("*" * 69) print("To use AutoStyle you must specify the -q flag!") print("*" * 69) return for question in self.args.question: if question in AutoStyleProtocol.ALLOW_QUESTIONS: # Ensure that all tests have passed results = grading.get(question) if not results: log.warning("No grading info") return elif results['failed'] or results['locked']: log.warning("Has not passed all tests") print("*" * 69) print( "To use AutoStyle you must have a correct solution for {0}!" .format(question)) print("*" * 69) return else: log.info("Not an autostyle question") print("*" * 69) print( "Make sure the question you are using is an AutoStyle question!" ) print("*" * 69) return print( "Once you begin you must finish the experiment in one sitting. This will take at most 2 hours." ) confirm = input("Do you wish to continue to AutoStyle? (y/n): ") if confirm.lower().strip() != 'y': return messages['analytics']['identifier'] = auth.get_identifier() # Send data to autostyle response_url = self.send_messages(messages, self.SHORT_TIMEOUT) # Parse response_url if response_url: webbrowser.open_new(response_url) else: log.error( "There was an error with AutoStyle. Please try again later!")