def main(): """Run all relevant aspects of ok.py.""" args = parse_input() log.setLevel(logging.DEBUG if args.debug else logging.ERROR) log.debug(args) if args.version: print("okpy=={}".format(client.__version__)) exit(0) elif args.update: print("Current version: {}".format(client.__version__)) software_update.check_version(args.server, client.__version__, client.FILE_NAME, timeout=10) exit(0) assign = None try: if args.authenticate: auth.authenticate(True) # Instantiating assignment assign = assignment.load_config(args.config, args) assign.load() if args.tests: print('Available tests:') for name in assign.test_map: print(' ' + name) exit(0) msgs = messages.Messages() for name, proto in assign.protocol_map.items(): log.info('Execute {}.run()'.format(name)) proto.run(msgs) msgs['timestamp'] = str(datetime.now()) except ex.LoadingException as e: log.warning('Assignment could not load', exc_info=True) print('Error loading assignment: ' + str(e)) except ex.OkException as e: log.warning('General OK exception occurred', exc_info=True) print('Error: ' + str(e)) except KeyboardInterrupt: log.info('KeyboardInterrupt received.') finally: if not args.no_update: try: software_update.check_version(args.server, client.__version__, client.FILE_NAME) except KeyboardInterrupt: pass if assign: assign.dump_tests()
def testUpToDate(self): self.createVersionApiJson(self.CURRENT_VERSION, self.CURRENT_DOWNLOAD_LINK) self.assertTrue(software_update.check_version(self.SERVER, self.CURRENT_VERSION, self.FILE_NAME)) self.assertFalse(self.mockWriteZip.called)
def testUpToDate(self): self.createVersionApiJson(self.CURRENT_VERSION, self.CURRENT_DOWNLOAD_LINK) self.assertTrue( software_update.check_version(self.SERVER, self.CURRENT_VERSION, self.FILE_NAME)) self.assertFalse(self.mockWriteZip.called)
def testWriteZip_IOError(self): self.createVersionApiJson(self.CURRENT_VERSION, self.CURRENT_DOWNLOAD_LINK) self.mockWriteZip.side_effect = IOError self.assertFalse(software_update.check_version(self.SERVER, self.PREVIOUS_VERSION, self.FILE_NAME)) self.assertTrue(self.mockWriteZip.called)
def testNeedsUpdate(self): self.createVersionApiJson(self.CURRENT_VERSION, self.CURRENT_DOWNLOAD_LINK) self.assertTrue(software_update.check_version(self.SERVER, self.PREVIOUS_VERSION, self.FILE_NAME)) expected_zip_call = ((self.FILE_NAME, self.mockRead.return_value),) self.assertEqual(expected_zip_call, self.mockWriteZip.call_args)
def testWriteZip_IOError(self): self.createVersionApiJson(self.CURRENT_VERSION, self.CURRENT_DOWNLOAD_LINK) self.mockWriteZip.side_effect = IOError self.assertFalse( software_update.check_version(self.SERVER, self.PREVIOUS_VERSION, self.FILE_NAME)) self.assertTrue(self.mockWriteZip.called)
def testNeedsUpdate(self): self.createVersionApiJson(self.CURRENT_VERSION, self.CURRENT_DOWNLOAD_LINK) self.assertTrue( software_update.check_version(self.SERVER, self.PREVIOUS_VERSION, self.FILE_NAME)) expected_zip_call = ((self.FILE_NAME, self.mockRead.return_value), ) self.assertEqual(expected_zip_call, self.mockWriteZip.call_args)
def main(): """Run all relevant aspects of ok.py.""" args = parse_input() log.setLevel(logging.DEBUG if args.debug else logging.ERROR) log.debug(args) # Checking user's Python bit version bit_v = (8 * struct.calcsize("P")) log.debug("Python {} ({}bit)".format(sys.version, bit_v)) if args.version: print("okpy=={}".format(client.__version__)) exit(0) elif args.update: print("Current version: {}".format(client.__version__)) did_update = software_update.check_version( args.server, client.__version__, client.FILE_NAME, timeout=10) exit(not did_update) # exit with error if ok failed to update assign = None try: if args.get_token: access_token = auth.authenticate(args, force=True) print("Token: {}".format(access_token)) exit(not access_token) # exit with error if no access_token # Instantiating assignment assign = assignment.load_assignment(args.config, args) if args.authenticate: # Authenticate and check for success if not assign.authenticate(force=True): exit(1) if args.tests: print('Available tests:') for name in assign.test_map: print(' ' + name) exit(0) msgs = messages.Messages() for name, proto in assign.protocol_map.items(): log.info('Execute {}.run()'.format(name)) proto.run(msgs) msgs['timestamp'] = str(datetime.now()) except ex.LoadingException as e: log.warning('Assignment could not load', exc_info=True) print('Error loading assignment: ' + str(e)) except ex.AuthenticationException as e: log.warning('Authentication exception occurred', exc_info=True) print('Authentication error: {0}'.format(e)) except ex.OkException as e: log.warning('General OK exception occurred', exc_info=True) print('Error: ' + str(e)) except KeyboardInterrupt: log.info('KeyboardInterrupt received.') finally: if not args.no_update and not args.local: try: software_update.check_version(args.server, client.__version__, client.FILE_NAME) except KeyboardInterrupt: pass if assign: assign.dump_tests()
def main(): """Run all relevant aspects of ok.py.""" args = parse_input() log.setLevel(logging.DEBUG if args.debug else logging.ERROR) log.debug(args) # Checking user's Python bit version bit_v = (8 * struct.calcsize("P")) log.debug("Python {} ({}bit)".format(sys.version, bit_v)) if args.version: print("okpy=={}".format(client.__version__)) exit(0) elif args.update: print("Current version: {}".format(client.__version__)) did_update = software_update.check_version(args.server, client.__version__, client.FILE_NAME, timeout=10) exit(not did_update) # exit with error if ok failed to update assign = None try: if args.get_token: if args.nointeract: print_error( "Cannot pass in --get-token and --nointeract, the only way to get a token is by interaction" ) exit(1) access_token = auth.authenticate(args, force=True) print("Token: {}".format(access_token)) exit(not access_token) # exit with error if no access_token # Instantiating assignment assign = assignment.load_assignment(args.config, args) if assign.decryption_keypage: # do not allow running locally if decryption keypage is provided args.local = False if args.autobackup_actual_run_sync: assign.autobackup(run_sync=True) # do not dump tests back out, this overwrites any changes that may have been made assign = None exit(0) if args.generate_encryption_key: assign.generate_encryption_key(args.generate_encryption_key) exit(0) if args.encrypt: assign.encrypt(args.encrypt, args.encrypt_padding) # do not dump tests back out, this overwrites any changes that may have been made assign = None exit(0) if args.decrypt is not None: raise ex.ForceDecryptionException(args.decrypt) if args.tests: print('Available tests:') for name in assign.test_map: print(' ' + name) exit(0) if args.autobackup: assign.autobackup(run_sync=False) exit(0) force_authenticate = args.authenticate retry = True while retry: retry = False if force_authenticate: if args.nointeract: print_error( "Cannot pass in --authenticate and --nointeract") exit(1) # Authenticate and check for success if not assign.authenticate(force=True): exit(1) try: msgs = messages.Messages() for name, proto in assign.protocol_map.items(): log.info('Execute {}.run()'.format(name)) proto.run(msgs) msgs['timestamp'] = str(datetime.now()) except ex.AuthenticationException as e: if not force_authenticate: force_authenticate = True retry = True elif not args.no_browser: args.no_browser = True retry = True if retry: msg = "without a browser" if args.no_browser else "with a browser" log.warning( 'Authentication exception occurred; will retry {0}'. format(msg), exc_info=True) print_error( 'Authentication error; will try to re-authenticate {0}...' .format(msg)) else: raise # outer handler will be called except ex.ForceDecryptionException as e: assign.decrypt(e.keys) # begin an autobackup assign.autobackup(run_sync=False) # do not dump tests back out, this could overwrite any changes that may have been made assign = None exit(0) except ex.LoadingException as e: log.warning('Assignment could not load', exc_info=True) print_error('Error loading assignment: ' + str(e)) except ex.AuthenticationException as e: log.warning('Authentication exception occurred', exc_info=True) print_error('Authentication error: {0}'.format(e)) except ex.EarlyExit as e: log.warning('OK exited early (non-error)') print_error(str(e)) except ex.OkException as e: log.warning('General OK exception occurred', exc_info=True) print_error('Error: ' + str(e)) except KeyboardInterrupt: log.info('KeyboardInterrupt received.') finally: if not args.no_update and not args.local: try: software_update.check_version(args.server, client.__version__, client.FILE_NAME) except KeyboardInterrupt: pass if assign: assign.dump_tests()
def testMalformedApiResponse(self): self.mockDecode.return_value = json.dumps({'data': []}) self.assertFalse(software_update.check_version(self.SERVER, self.CURRENT_VERSION, self.FILE_NAME))
def testMalformedApiResponse(self): self.mockDecode.return_value = json.dumps({'data': []}) self.assertFalse( software_update.check_version(self.SERVER, self.CURRENT_VERSION, self.FILE_NAME))
def main(): """Run all relevant aspects of ok.py.""" args = parse_input() log.setLevel(logging.DEBUG if args.debug else logging.ERROR) log.debug(args) # Checking user's Python bit version bit_v = (8 * struct.calcsize("P")) log.debug("Python {} ({}bit)".format(sys.version, bit_v)) if args.version: print("okpy=={}".format(client.__version__)) exit(0) elif args.update: print("Current version: {}".format(client.__version__)) did_update = software_update.check_version( args.server, client.__version__, client.FILE_NAME, timeout=10) exit(not did_update) # exit with error if ok failed to update assign = None try: if args.get_token: access_token = auth.authenticate(args, force=True) print("Token: {}".format(access_token)) exit(not access_token) # exit with error if no access_token # Instantiating assignment assign = assignment.load_assignment(args.config, args) if args.authenticate: # Authenticate and check for success if not assign.authenticate(force=True): exit(1) if args.tests: print('Available tests:') for name in assign.test_map: print(' ' + name) exit(0) msgs = messages.Messages() for name, proto in assign.protocol_map.items(): log.info('Execute {}.run()'.format(name)) proto.run(msgs) msgs['timestamp'] = str(datetime.now()) except ex.LoadingException as e: log.warning('Assignment could not load', exc_info=True) print('Error loading assignment: ' + str(e)) except ex.AuthenticationException as e: log.warning('Authentication exception occurred', exc_info=True) print('Authentication error: {0}'.format(e)) except ex.EarlyExit as e: log.warning('OK exited early (non-error)') print(str(e)) except ex.OkException as e: log.warning('General OK exception occurred', exc_info=True) print('Error: ' + str(e)) except KeyboardInterrupt: log.info('KeyboardInterrupt received.') finally: if not args.no_update and not args.local: try: software_update.check_version(args.server, client.__version__, client.FILE_NAME) except KeyboardInterrupt: pass if assign: assign.dump_tests()