def on_platformio_start(ctx, force, caller): ensure_python3(raise_exception=True) app.set_session_var("command_ctx", ctx) app.set_session_var("force_option", force) set_caller(caller) telemetry.on_command() if PlatformioCLI.in_silence(): return after_upgrade(ctx)
def on_platformio_start(ctx, force, caller): app.set_session_var("command_ctx", ctx) app.set_session_var("force_option", force) set_caller(caller) telemetry.on_command() if PlatformioCLI.in_silence(): return after_upgrade(ctx) if not ensure_python3(raise_exception=False): click.secho( """ Python 2 and Python 3.5 are not compatible with PlatformIO Core 5.0. Please check the migration guide on how to fix this warning message: """, fg="yellow", ) click.secho( "https://docs.platformio.org/en/latest/core/migration.html" "#drop-support-for-python-2-and-3-5", fg="blue", ) click.echo("")
def cli(port, host, no_open, shutdown_timeout, session_id): ensure_python3() # Ensure PIO Home mimetypes are known mimetypes.add_type("text/html", ".html") mimetypes.add_type("text/css", ".css") mimetypes.add_type("application/javascript", ".js") # hook for `platformio-node-helpers` if host == "__do_not_start__": return home_url = "http://%s:%d%s" % ( host, port, ("/session/%s/" % session_id) if session_id else "/", ) click.echo("\n".join([ "", " ___I_", " /\\-_--\\ PlatformIO Home", "/ \\_-__\\", "|[]| [] | %s" % home_url, "|__|____|__%s" % ("_" * len(home_url)), ])) click.echo("") click.echo("Open PlatformIO Home in your browser by this URL => %s" % home_url) if is_port_used(host, port): click.secho( "PlatformIO Home server is already started in another process.", fg="yellow") if not no_open: click.launch(home_url) return # pylint: disable=import-outside-toplevel from platformio.commands.home.run import run_server run_server( host=host, port=port, no_open=no_open, shutdown_timeout=shutdown_timeout, home_url=home_url, )
def package_publish(package, owner, released_at, private, notify): assert ensure_python3() with tempfile.TemporaryDirectory() as tmp_dir: # pylint: disable=no-member with fs.cd(tmp_dir): p = PackagePacker(package) archive_path = p.pack() response = RegistryClient().publish_package( archive_path, owner, released_at, private, notify ) os.remove(archive_path) click.secho(response.get("message"), fg="green")
def package_publish(package, owner, released_at, private, notify): assert ensure_python3() # publish .tar.gz instantly without repacking if not os.path.isdir(package) and isinstance( FileUnpacker.new_archiver(package), TARArchiver): response = RegistryClient().publish_package(package, owner, released_at, private, notify) click.secho(response.get("message"), fg="green") return with tempfile.TemporaryDirectory() as tmp_dir: # pylint: disable=no-member with fs.cd(tmp_dir): p = PackagePacker(package) archive_path = p.pack() response = RegistryClient().publish_package( archive_path, owner, released_at, private, notify) os.remove(archive_path) click.secho(response.get("message"), fg="green")
def __init__(self, package, manifest_uri=None): assert ensure_python3() self.package = package self.manifest_uri = manifest_uri
def get_mdns_services(): compat.ensure_python3() # pylint: disable=import-outside-toplevel import zeroconf class mDNSListener(object): def __init__(self): self._zc = zeroconf.Zeroconf(interfaces=zeroconf.InterfaceChoice.All) self._found_types = [] self._found_services = [] def __enter__(self): zeroconf.ServiceBrowser( self._zc, [ "_http._tcp.local.", "_hap._tcp.local.", "_services._dns-sd._udp.local.", ], self, ) return self def __exit__(self, etype, value, traceback): self._zc.close() def add_service(self, zc, type_, name): try: assert zeroconf.service_type_name(name) assert str(name) except (AssertionError, UnicodeError, zeroconf.BadTypeInNameException): return if name not in self._found_types: self._found_types.append(name) zeroconf.ServiceBrowser(self._zc, name, self) if type_ in self._found_types: s = zc.get_service_info(type_, name) if s: self._found_services.append(s) def remove_service(self, zc, type_, name): pass def update_service(self, zc, type_, name): pass def get_services(self): return self._found_services items = [] with mDNSListener() as mdns: time.sleep(3) for service in mdns.get_services(): properties = None if service.properties: try: properties = { k.decode("utf8"): v.decode("utf8") if isinstance(v, bytes) else v for k, v in service.properties.items() } json.dumps(properties) except UnicodeDecodeError: properties = None items.append( { "type": service.type, "name": service.name, "ip": ", ".join(service.parsed_addresses()), "port": service.port, "properties": properties, } ) return items
def cli(ctx, agent): assert ensure_python3() ctx.obj = agent inject_contrib_pysite(verify_openssl=True)