def on_any_event(self, event): is_contracts_json_file = os.path.samefile( event.src_path, get_compiled_contract_destination_path(self.project_dir) ) if not is_contracts_json_file: return click.echo("============ Detected Change ==============") click.echo("> {0} => {1}".format(event.event_type, event.src_path)) click.echo("> Recreating 'contracts.js' ...") compile_js_contracts(self.project_dir) click.echo("> watching...")
def on_any_event(self, event): is_contracts_json_file = os.path.samefile( event.src_path, get_compiled_contract_destination_path(self.project_dir), ) if not is_contracts_json_file: return click.echo("============ Detected Change ==============") click.echo("> {0} => {1}".format(event.event_type, event.src_path)) click.echo("> Recreating 'contracts.js' ...") compile_js_contracts(self.project_dir) click.echo("> watching...")
def web_runserver(debug): """ Run the development server. """ project_dir = os.getcwd() # Do initial setup click.echo("Compiling contracts...") compile_and_write_contracts(project_dir) click.echo("Compiling contracts.js...") compile_js_contracts(project_dir) click.echo("Collectind static assets...") collect_static_assets(project_dir) all_threads = [] # Contract Builder Thread contracts_observer_thread = get_contracts_observer(project_dir) contracts_observer_thread.daemon = True # Contract JS Builder Thread contracts_code_observer_thread = get_contracts_code_observer(project_dir) contracts_code_observer_thread.daemon = True # Assets Collector Thread static_assets_observer_thread = get_static_assets_observer(project_dir) static_assets_observer_thread.daemon = True # Webserver Thread flask_app = get_flask_app(project_dir) webserver_thread = multiprocessing.Process( target=flask_app.run, kwargs={'use_reloader': False, 'debug': debug}, ) webserver_thread.daemon = True # Start all the threads contracts_observer_thread.start() contracts_code_observer_thread.start() static_assets_observer_thread.start() webserver_thread.start() try: all_threads = ( contracts_observer_thread, contracts_code_observer_thread, static_assets_observer_thread, webserver_thread, ) while any(t.is_alive() for t in all_threads): if not all(t.is_alive() for t in all_threads): raise click.Abort("Some threads died!") time.sleep(1) except KeyboardInterrupt: for t in all_threads: if hasattr(t, 'stop'): t.stop() elif hasattr(t, 'terminate'): t.terminate() else: raise ValueError("wat") for t in all_threads: t.join()
def web_collect(): """ Compile the contracts.js file and collect static assets. """ compile_js_contracts(os.getcwd()) collect_static_assets(os.getcwd())