Exemplo n.º 1
0
 def get_current_revision(self):
     output = self.get_cmd_output(
         ["info", "--non-interactive", "--trust-server-cert", "-r", "HEAD"])
     for line in output.split("\n"):
         line = line.strip()
         if line.startswith("Revision:"):
             return line.split(":", 1)[1].strip()
     raise PlatformioException("Could not detect current SVN revision")
Exemplo n.º 2
0
 def run_cmd(self, args, **kwargs):
     args = [self.command] + args
     if "cwd" not in kwargs:
         kwargs["cwd"] = self.src_dir
     try:
         check_call(args, **kwargs)
         return True
     except CalledProcessError as e:
         raise PlatformioException("VCS: Could not process command %s" % e.cmd)
Exemplo n.º 3
0
 def check_client(self):
     try:
         assert self.command
         assert self.run_cmd(["--version"])
     except (AssertionError, OSError):
         raise PlatformioException(
             "VCS: `%s` client is not installed in your system" %
             self.command)
     return True
Exemplo n.º 4
0
 def get_cmd_output(self, args, **kwargs):
     args = [self.command] + args
     if "cwd" not in kwargs:
         kwargs["cwd"] = self.src_dir
     result = exec_command(args, **kwargs)
     if result["returncode"] == 0:
         return result["out"].strip()
     raise PlatformioException(
         "VCS: Could not receive an output from `%s` command (%s)" % (args, result)
     )
Exemplo n.º 5
0
 def newClient(src_dir, remote_url):
     result = urlparse(remote_url)
     type_ = result.scheme
     if not type_ and remote_url.startswith("git@"):
         type_ = "git"
     elif "+" in result.scheme:
         type_, _ = result.scheme.split("+", 1)
         remote_url = remote_url[len(type_) + 1:]
     if result.fragment:
         remote_url = remote_url.rsplit("#", 1)[0]
     if not type_:
         raise PlatformioException("VCS: Unknown repository type %s" %
                                   remote_url)
     obj = getattr(modules[__name__], "%sClient" % type_.title())(
         src_dir, remote_url, result.fragment)
     assert isinstance(obj, VCSClientBase)
     return obj
Exemplo n.º 6
0
def run_server(host, port, no_open, shutdown_timeout, home_url):
    contrib_dir = get_core_package_dir("contrib-piohome")
    if not os.path.isdir(contrib_dir):
        raise PlatformioException("Invalid path to PIO Home Contrib")

    ws_rpc_factory = WebSocketJSONRPCServerFactory(shutdown_timeout)
    ws_rpc_factory.addHandler(AccountRPC(), namespace="account")
    ws_rpc_factory.addHandler(AppRPC(), namespace="app")
    ws_rpc_factory.addHandler(IDERPC(), namespace="ide")
    ws_rpc_factory.addHandler(MiscRPC(), namespace="misc")
    ws_rpc_factory.addHandler(OSRPC(), namespace="os")
    ws_rpc_factory.addHandler(PIOCoreRPC(), namespace="core")
    ws_rpc_factory.addHandler(ProjectRPC(), namespace="project")

    path = urlparse(home_url).path
    routes = [
        WebSocketRoute(path + "wsrpc", ws_rpc_factory, name="wsrpc"),
        Route(path + "__shutdown__", shutdown_server, methods=["POST"]),
        Mount(path,
              StaticFiles(directory=contrib_dir, html=True),
              name="static"),
    ]
    if path != "/":
        routes.append(Route("/", protected_page))

    uvicorn.run(
        Starlette(
            middleware=[Middleware(ShutdownMiddleware)],
            routes=routes,
            on_startup=[
                lambda: click.echo(
                    "PIO Home has been started. Press Ctrl+C to shutdown."),
                lambda: None if no_open else click.launch(home_url),
            ],
        ),
        host=host,
        port=port,
        log_level="warning",
    )