File: utils.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (29 lines) | stat: -rw-r--r-- 863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import subprocess
import sys

from azure.core import PipelineClient
from azure.core.pipeline import policies


def run_command(command, exit_on_failure=True) -> str:
    try:
        result = subprocess.check_output(command, stderr=subprocess.STDOUT).decode("utf-8").strip()
        return result
    except subprocess.CalledProcessError as ex:
        result = ex.output.decode("utf-8").strip()
        if exit_on_failure:
            print(result)
            sys.exit(1)
        return result


def get_pipeline_client(base_url: str) -> PipelineClient:
    policy_list = [
        policies.RetryPolicy(),
        policies.ContentDecodePolicy(),
    ]
    return PipelineClient(base_url, policies=policy_list)