• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#coding=utf-8
3
4#
5# Copyright (c) 2022 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import sys
21import string
22
23DEBUG_NORMAL  = 1
24DEBUG_VERBOSE = 2
25DEBUG_SPAM	= 3
26
27debuglevel = DEBUG_NORMAL
28
29def debug(level, *msg):
30	if debuglevel >= level:
31		print(' '.join(msg))
32
33# return a list of lines of output of the command
34def command(command, *args):
35	debug(DEBUG_SPAM, "calling", command, ' '.join(args))
36	pipe = os.popen(command + ' ' + ' '.join(args), 'r')
37	output = pipe.read().strip()
38	status = pipe.close()
39	if status is not None and os.WEXITSTATUS(status) != 0:
40		print("Command failed with status", os.WEXITSTATUS(status),  ":", \
41			   command, ' '.join(args))
42		print("With output:", output)
43		sys.exit(1)
44	return [i for i in output.split('\n') if i]
45