MCPcopy Create free account
hub / github.com/ermak-dev/cloudpub / run_cloudpub

Function run_cloudpub

client/cloudpub.py:3–36  ·  view source on GitHub ↗
(command)

Source from the content-addressed store, hash-verified

1import subprocess, threading, sys, re, time
2
3def run_cloudpub(command):
4 process = subprocess.Popen(
5 command,
6 stdout=subprocess.PIPE,
7 stderr=subprocess.PIPE,
8 text=True,
9 shell=True,
10 bufsize=1,
11 )
12
13 # Variable to store the extracted URL
14 extracted_url = [None]
15
16 def monitor(stream_in, stream_out, extract_url=False):
17 def reader():
18 with stream_in:
19 for line in stream_in:
20 stream_out.write(line)
21
22 # Check for the publication message and extract URL
23 if extract_url:
24 match = re.search(r'.+ -> (.+)', line)
25 if match:
26 extracted_url[0] = match.group(1)
27 return reader
28
29 threading.Thread(target=monitor(process.stdout, sys.stdout, True), daemon=True).start()
30 threading.Thread(target=monitor(process.stderr, sys.stderr), daemon=True).start()
31
32 # Wait for the process to complete or timeout
33 while True:
34 if extracted_url[0]:
35 return extracted_url[0]
36 time.sleep(1)
37
38# Run the command and get the URL
39url = run_cloudpub("./clo publish http 8080")

Callers 1

cloudpub.pyFile · 0.85

Calls 2

monitorFunction · 0.85
startMethod · 0.45

Tested by

no test coverage detected