def write_cpp(code_s): path = CORE.relative_build_path('src', 'main.cpp') if os.path.isfile(path): try: with codecs.open(path, 'r', encoding='utf-8') as f_handle: text = f_handle.read() except OSError: raise EsphomeyamlError(u"Could not read C++ file at {}".format(path)) prev_file = text code_format = find_begin_end(text, CPP_AUTO_GENERATE_BEGIN, CPP_AUTO_GENERATE_END) code_format_ = find_begin_end(code_format[0], CPP_INCLUDE_BEGIN, CPP_INCLUDE_END) code_format = (code_format_[0], code_format_[1], code_format[1]) else: prev_file = None mkdir_p(os.path.dirname(path)) code_format = CPP_BASE_FORMAT include_s = get_include_text() full_file = code_format[0] + CPP_INCLUDE_BEGIN + u'\n' + include_s + CPP_INCLUDE_END full_file += code_format[1] + CPP_AUTO_GENERATE_BEGIN + u'\n' + code_s + CPP_AUTO_GENERATE_END full_file += code_format[2] if prev_file == full_file: return with codecs.open(path, 'w+', encoding='utf-8') as f_handle: f_handle.write(full_file)
def write_platformio_project(): mkdir_p(CORE.build_path) platformio_ini = CORE.relative_build_path('platformio.ini') content = get_ini_content() write_gitignore() write_platformio_ini(content, platformio_ini)
def write_platformio_project(): mkdir_p(CORE.build_path) platformio_ini = CORE.relative_build_path('platformio.ini') content = get_ini_content() if 'esp32_ble_beacon' in CORE.config or 'esp32_ble_tracker' in CORE.config: content += 'board_build.partitions = partitions.csv\n' partitions_csv = CORE.relative_build_path('partitions.csv') if not os.path.isfile(partitions_csv): with open(partitions_csv, "w") as f: f.write("nvs, data, nvs, 0x009000, 0x005000,\n") f.write("otadata, data, ota, 0x00e000, 0x002000,\n") f.write("app0, app, ota_0, 0x010000, 0x190000,\n") f.write("app1, app, ota_1, 0x200000, 0x190000,\n") f.write("eeprom, data, 0x99, 0x390000, 0x001000,\n") f.write("spiffs, data, spiffs, 0x391000, 0x00F000\n") write_gitignore() write_platformio_ini(content, platformio_ini)
def symlink_esphomelib_version(esphomelib_version): lib_path = CORE.relative_build_path('lib') dst_path = CORE.relative_build_path('lib', 'esphomelib') if CORE.is_local_esphomelib_copy: src_path = CORE.relative_path(esphomelib_version[CONF_LOCAL]) do_write = True if os.path.islink(dst_path): old_path = os.path.join(os.readlink(dst_path), lib_path) if old_path != lib_path: os.unlink(dst_path) else: do_write = False if do_write: mkdir_p(lib_path) os.symlink(src_path, dst_path) else: # Remove symlink when changing back from local version if os.path.islink(dst_path): os.unlink(dst_path)
def save(self, path): mkdir_p(os.path.dirname(path)) with codecs.open(path, 'w', encoding='utf-8') as f_handle: f_handle.write(self.to_json())
def start_web_server(args): global CONFIG_DIR global PASSWORD_DIGEST global USING_PASSWORD global ON_HASSIO global USING_HASSIO_AUTH global COOKIE_SECRET CONFIG_DIR = args.configuration mkdir_p(CONFIG_DIR) mkdir_p(os.path.join(CONFIG_DIR, ".esphomeyaml")) ON_HASSIO = args.hassio if ON_HASSIO: USING_HASSIO_AUTH = not bool(os.getenv('DISABLE_HA_AUTHENTICATION')) USING_PASSWORD = False else: USING_HASSIO_AUTH = False USING_PASSWORD = args.password if USING_PASSWORD: PASSWORD_DIGEST = hmac.new(args.password).digest() if USING_HASSIO_AUTH or USING_PASSWORD: path = esphomeyaml_storage_path(CONFIG_DIR) storage = EsphomeyamlStorageJSON.load(path) if storage is None: storage = EsphomeyamlStorageJSON.get_default() storage.save(path) COOKIE_SECRET = storage.cookie_secret app = make_app(args.verbose) if args.socket is not None: _LOGGER.info( "Starting dashboard web server on unix socket %s and configuration dir %s...", args.socket, CONFIG_DIR) server = tornado.httpserver.HTTPServer(app) socket = tornado.netutil.bind_unix_socket(args.socket, mode=0o666) server.add_socket(socket) else: _LOGGER.info( "Starting dashboard web server on port %s and configuration dir %s...", args.port, CONFIG_DIR) app.listen(args.port) if args.open_ui: import webbrowser webbrowser.open('localhost:{}'.format(args.port)) ping_thread = PingThread() ping_thread.start() try: tornado.ioloop.IOLoop.current().start() except KeyboardInterrupt: _LOGGER.info("Shutting down...") STOP_EVENT.set() PING_REQUEST.set() ping_thread.join() if args.socket is not None: os.remove(args.socket)