|
17 | 17 | import argparse
|
18 | 18 | import logging
|
19 | 19 | import os
|
| 20 | +import shlex |
20 | 21 | import subprocess
|
21 | 22 | import sys
|
22 | 23 |
|
|
28 | 29 | logging.basicConfig(level=logging.DEBUG)
|
29 | 30 |
|
30 | 31 |
|
| 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 | + |
31 | 43 | def create_author_certificate(alias: str, password: str,
|
32 | 44 | name: str = "", email: str = ""):
|
33 | 45 | cmd = [tizen_cli, "certificate", "--alias", alias, "--password", password]
|
34 | 46 | if name:
|
35 | 47 | cmd.extend(["--name", name])
|
36 | 48 | if email:
|
37 | 49 | 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: |
40 | 52 | for line in proc.stdout.readlines():
|
41 |
| - line = line.decode().rstrip() |
| 53 | + line = line.rstrip() |
42 | 54 | if line.startswith("Working path:"):
|
43 | 55 | wd = line[len("Working path:"):].strip()
|
44 | 56 | print(line)
|
| 57 | + if not wd: |
| 58 | + return None |
45 | 59 | return os.path.join(wd, "author.p12")
|
46 | 60 |
|
47 | 61 |
|
@@ -69,21 +83,19 @@ def check_security_profile(profile):
|
69 | 83 | f.write('<profiles/>')
|
70 | 84 |
|
71 | 85 | 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: |
74 | 87 | for line in proc.stdout.readlines():
|
75 |
| - line = line.decode().rstrip() |
| 88 | + line = line.rstrip() |
76 | 89 | print(line)
|
77 | 90 | return proc.wait() == 0
|
78 | 91 |
|
79 | 92 |
|
80 | 93 | def add_security_profile(profile: str, certificate: str, password: str):
|
81 | 94 | cmd = [tizen_cli, "security-profiles", "add", "--active",
|
82 | 95 | "--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: |
85 | 97 | for line in proc.stdout.readlines():
|
86 |
| - line = line.decode().rstrip() |
| 98 | + line = line.rstrip() |
87 | 99 | print(line)
|
88 | 100 | return proc.wait() == 0
|
89 | 101 |
|
|
0 commit comments