def __init__(self): self.handler = MappingItemsManager() Log.ok("Server started successfully at {0}:{1}".format( "http://" + socket.gethostbyname(socket.gethostname()), cherrypy.config["server.socket_port"], ))
def on_any_event(self, event): Log.info("Directory changed, rebuilding mapping settings...\n" "Path: %s" % event.src_path + "\nEvent type: %s" % event.event_type) Config.reload_sys_path_list() self.mapping_manager.parse_yaml_files() Log.ok("Mapping settings rebuilt successfully")
def run(args): if args.update_scenario: scenario = args.update_scenario if not scenario: scenario = Constants.DEFAULT_SCENARIO Log.info("Changing to scenario {0}...".format(scenario)) try: r = requests.get( "{0}/pymocky/update-scenario?scenario={1}".format( args.server_host, scenario, )) if r.status_code == 200: Log.ok("Scenario updated") else: Log.failed("Scenario not updated: {0:d}".format( r.status_code)) except requests.exceptions.RequestException as e: Log.error("Scenario update error: {0}".format(e)) elif args.reload: Log.info("Reloading...") try: r = requests.get("{0}/pymocky/reload".format(args.server_host)) if r.status_code == 200: Log.ok("Reloaded") else: Log.failed("Reload failed: {0:d}".format(r.status_code)) except requests.exceptions.RequestException as e: Log.error("Reload error: {0}".format(e)) elif args.version: Log.normal("Version: {0}".format(__version__)) else: if not args.path: Log.error("Path argument is required (--path or -p)") Config.sys_path_list = sys.path.copy() CherryPyServer.start()
def test_ok(self): with patch("sys.stdout", new=StringIO()) as output: Log.ok("ok message") self.assertIn("ok message", output.getvalue().strip())
def signal_handler(signal, frame): Log.info("Shutting down server...") cherrypy.engine.exit() Log.ok("Server shutdown successfully")