Skip to content

Commit

Permalink
[Tizen] Forward stderr from Tizen Studio CLI tool (#36976)
Browse files Browse the repository at this point in the history
* [Tizen] Forward stderr from Tizen Studio CLI tool

* Fix process management

* Use shlex for joining command arguments
  • Loading branch information
arkq authored Jan 10, 2025
1 parent 3f62505 commit e7082e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
7 changes: 4 additions & 3 deletions scripts/tools/bouffalolab/generate_factory_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import random
import secrets
import shlex
import subprocess
import sys
from datetime import datetime, timedelta
Expand Down Expand Up @@ -185,7 +186,7 @@ def verify_certificates(chip_cert, paa_cert, pai_cert, dac_cert):
"--pai", pai_cert,
"--paa", paa_cert,
]
log.info("Verify Certificate Chain: {}".format(" ".join(cmd)))
log.info("Verify Certificate Chain: {}".format(shlex.join(cmd)))
subprocess.run(cmd)

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):
Expand Down Expand Up @@ -214,7 +215,7 @@ def gen_valid_times(issue_date, expire_date):
"--valid-from", valid_from,
"--lifetime", str(lifetime),
]
log.info("Generate DAC: {}".format(" ".join(cmd)))
log.info("Generate DAC: {}".format(shlex.join(cmd)))
subprocess.run(cmd)

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

log.info("Generate CD: {}".format(" ".join(cmd)))
log.info("Generate CD: {}".format(shlex.join(cmd)))
subprocess.run(cmd)

pai_vendor_id, pai_product_id, pai_issue_date, pai_expire_date = parse_cert_file(pai_cert)
Expand Down
3 changes: 2 additions & 1 deletion scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import multiprocessing
import os
import os.path
import shlex
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -209,7 +210,7 @@ def generate(self) -> TargetRunStats:
"""Runs a ZAP generate command on the configured zap/template/outputs.
"""
cmd = self.build_cmd()
logging.info("Generating target: %s" % " ".join(cmd))
logging.info("Generating target: %s" % shlex.join(cmd))

generate_start = time.time()
subprocess.check_call(cmd)
Expand Down
30 changes: 21 additions & 9 deletions third_party/tizen/tizen_dev_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import argparse
import logging
import os
import shlex
import subprocess
import sys

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


def run(cmd):
logging.debug("Run: %s", shlex.join(cmd))
proc = subprocess.Popen(cmd, errors='replace',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.wait()
for line in proc.stderr.readlines():
logging.error("%s", line.rstrip())
return proc


def create_author_certificate(alias: str, password: str,
name: str = "", email: str = ""):
cmd = [tizen_cli, "certificate", "--alias", alias, "--password", password]
if name:
cmd.extend(["--name", name])
if email:
cmd.extend(["--email", email])
logging.debug("Execute: %s", " ".join(cmd))
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
wd = None
with run(cmd) as proc:
for line in proc.stdout.readlines():
line = line.decode().rstrip()
line = line.rstrip()
if line.startswith("Working path:"):
wd = line[len("Working path:"):].strip()
print(line)
if not wd:
return None
return os.path.join(wd, "author.p12")


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

cmd = [tizen_cli, "security-profiles", "list", "--name", profile]
logging.debug("Execute: %s", " ".join(cmd))
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
with run(cmd) as proc:
for line in proc.stdout.readlines():
line = line.decode().rstrip()
line = line.rstrip()
print(line)
return proc.wait() == 0


def add_security_profile(profile: str, certificate: str, password: str):
cmd = [tizen_cli, "security-profiles", "add", "--active",
"--name", profile, "--author", certificate, "--password", password]
logging.debug("Execute: %s", " ".join(cmd))
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
with run(cmd) as proc:
for line in proc.stdout.readlines():
line = line.decode().rstrip()
line = line.rstrip()
print(line)
return proc.wait() == 0

Expand Down

0 comments on commit e7082e2

Please sign in to comment.