Skip to content

Commit e7082e2

Browse files
authored
[Tizen] Forward stderr from Tizen Studio CLI tool (#36976)
* [Tizen] Forward stderr from Tizen Studio CLI tool * Fix process management * Use shlex for joining command arguments
1 parent 3f62505 commit e7082e2

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

scripts/tools/bouffalolab/generate_factory_data.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import os
2323
import random
2424
import secrets
25+
import shlex
2526
import subprocess
2627
import sys
2728
from datetime import datetime, timedelta
@@ -185,7 +186,7 @@ def verify_certificates(chip_cert, paa_cert, pai_cert, dac_cert):
185186
"--pai", pai_cert,
186187
"--paa", paa_cert,
187188
]
188-
log.info("Verify Certificate Chain: {}".format(" ".join(cmd)))
189+
log.info("Verify Certificate Chain: {}".format(shlex.join(cmd)))
189190
subprocess.run(cmd)
190191

191192
def gen_dac_certificate(chip_cert, device_name, vendor_id, product_id, pai_cert, pai_key, dac_cert, dac_key, pai_issue_date, pai_expire_date):
@@ -214,7 +215,7 @@ def gen_valid_times(issue_date, expire_date):
214215
"--valid-from", valid_from,
215216
"--lifetime", str(lifetime),
216217
]
217-
log.info("Generate DAC: {}".format(" ".join(cmd)))
218+
log.info("Generate DAC: {}".format(shlex.join(cmd)))
218219
subprocess.run(cmd)
219220

220221
def convert_pem_to_der(chip_cert, action, pem):
@@ -254,7 +255,7 @@ def gen_cd(chip_cert, dac_vendor_id, dac_product_id, vendor_id, product_id, cd_c
254255
"--dac-origin-product-id", hex(dac_product_id),
255256
]
256257

257-
log.info("Generate CD: {}".format(" ".join(cmd)))
258+
log.info("Generate CD: {}".format(shlex.join(cmd)))
258259
subprocess.run(cmd)
259260

260261
pai_vendor_id, pai_product_id, pai_issue_date, pai_expire_date = parse_cert_file(pai_cert)

scripts/tools/zap_regen_all.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import multiprocessing
2121
import os
2222
import os.path
23+
import shlex
2324
import shutil
2425
import subprocess
2526
import sys
@@ -209,7 +210,7 @@ def generate(self) -> TargetRunStats:
209210
"""Runs a ZAP generate command on the configured zap/template/outputs.
210211
"""
211212
cmd = self.build_cmd()
212-
logging.info("Generating target: %s" % " ".join(cmd))
213+
logging.info("Generating target: %s" % shlex.join(cmd))
213214

214215
generate_start = time.time()
215216
subprocess.check_call(cmd)

third_party/tizen/tizen_dev_certificate.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import argparse
1818
import logging
1919
import os
20+
import shlex
2021
import subprocess
2122
import sys
2223

@@ -28,20 +29,33 @@
2829
logging.basicConfig(level=logging.DEBUG)
2930

3031

32+
def run(cmd):
33+
logging.debug("Run: %s", shlex.join(cmd))
34+
proc = subprocess.Popen(cmd, errors='replace',
35+
stdout=subprocess.PIPE,
36+
stderr=subprocess.PIPE)
37+
proc.wait()
38+
for line in proc.stderr.readlines():
39+
logging.error("%s", line.rstrip())
40+
return proc
41+
42+
3143
def create_author_certificate(alias: str, password: str,
3244
name: str = "", email: str = ""):
3345
cmd = [tizen_cli, "certificate", "--alias", alias, "--password", password]
3446
if name:
3547
cmd.extend(["--name", name])
3648
if email:
3749
cmd.extend(["--email", email])
38-
logging.debug("Execute: %s", " ".join(cmd))
39-
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
50+
wd = None
51+
with run(cmd) as proc:
4052
for line in proc.stdout.readlines():
41-
line = line.decode().rstrip()
53+
line = line.rstrip()
4254
if line.startswith("Working path:"):
4355
wd = line[len("Working path:"):].strip()
4456
print(line)
57+
if not wd:
58+
return None
4559
return os.path.join(wd, "author.p12")
4660

4761

@@ -69,21 +83,19 @@ def check_security_profile(profile):
6983
f.write('<profiles/>')
7084

7185
cmd = [tizen_cli, "security-profiles", "list", "--name", profile]
72-
logging.debug("Execute: %s", " ".join(cmd))
73-
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
86+
with run(cmd) as proc:
7487
for line in proc.stdout.readlines():
75-
line = line.decode().rstrip()
88+
line = line.rstrip()
7689
print(line)
7790
return proc.wait() == 0
7891

7992

8093
def add_security_profile(profile: str, certificate: str, password: str):
8194
cmd = [tizen_cli, "security-profiles", "add", "--active",
8295
"--name", profile, "--author", certificate, "--password", password]
83-
logging.debug("Execute: %s", " ".join(cmd))
84-
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
96+
with run(cmd) as proc:
8597
for line in proc.stdout.readlines():
86-
line = line.decode().rstrip()
98+
line = line.rstrip()
8799
print(line)
88100
return proc.wait() == 0
89101

0 commit comments

Comments
 (0)