(command)
| 1 | import subprocess, threading, sys, re, time |
| 2 | |
| 3 | def 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 |
| 39 | url = run_cloudpub("./clo publish http 8080") |
no test coverage detected