diff options
| author | Gavin Mak <gavinmak@google.com> | 2023-03-11 06:46:20 +0000 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-22 17:46:28 +0000 |
| commit | ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch) | |
| tree | dc33ba0e56825b3e007d0589891756724725a465 /release/util.py | |
| parent | 1604cf255f8c1786a23388db6d5277ac7949a24a (diff) | |
| download | git-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz | |
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught
by flake8. Also check black formatting in run_tests (and CQ).
Bug: b/267675342
Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'release/util.py')
| -rw-r--r-- | release/util.py | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/release/util.py b/release/util.py index 9d0eb1dc..df7a5638 100644 --- a/release/util.py +++ b/release/util.py | |||
| @@ -20,54 +20,60 @@ import subprocess | |||
| 20 | import sys | 20 | import sys |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' | 23 | assert sys.version_info >= (3, 6), "This module requires Python 3.6+" |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | TOPDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 26 | TOPDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 27 | HOMEDIR = os.path.expanduser('~') | 27 | HOMEDIR = os.path.expanduser("~") |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | # These are the release keys we sign with. | 30 | # These are the release keys we sign with. |
| 31 | KEYID_DSA = '8BB9AD793E8E6153AF0F9A4416530D5E920F5C65' | 31 | KEYID_DSA = "8BB9AD793E8E6153AF0F9A4416530D5E920F5C65" |
| 32 | KEYID_RSA = 'A34A13BE8E76BFF46A0C022DA2E75A824AAB9624' | 32 | KEYID_RSA = "A34A13BE8E76BFF46A0C022DA2E75A824AAB9624" |
| 33 | KEYID_ECC = 'E1F9040D7A3F6DAFAC897CD3D3B95DA243E48A39' | 33 | KEYID_ECC = "E1F9040D7A3F6DAFAC897CD3D3B95DA243E48A39" |
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | def cmdstr(cmd): | 36 | def cmdstr(cmd): |
| 37 | """Get a nicely quoted shell command.""" | 37 | """Get a nicely quoted shell command.""" |
| 38 | ret = [] | 38 | ret = [] |
| 39 | for arg in cmd: | 39 | for arg in cmd: |
| 40 | if not re.match(r'^[a-zA-Z0-9/_.=-]+$', arg): | 40 | if not re.match(r"^[a-zA-Z0-9/_.=-]+$", arg): |
| 41 | arg = f'"{arg}"' | 41 | arg = f'"{arg}"' |
| 42 | ret.append(arg) | 42 | ret.append(arg) |
| 43 | return ' '.join(ret) | 43 | return " ".join(ret) |
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | def run(opts, cmd, check=True, **kwargs): | 46 | def run(opts, cmd, check=True, **kwargs): |
| 47 | """Helper around subprocess.run to include logging.""" | 47 | """Helper around subprocess.run to include logging.""" |
| 48 | print('+', cmdstr(cmd)) | 48 | print("+", cmdstr(cmd)) |
| 49 | if opts.dryrun: | 49 | if opts.dryrun: |
| 50 | cmd = ['true', '--'] + cmd | 50 | cmd = ["true", "--"] + cmd |
| 51 | try: | 51 | try: |
| 52 | return subprocess.run(cmd, check=check, **kwargs) | 52 | return subprocess.run(cmd, check=check, **kwargs) |
| 53 | except subprocess.CalledProcessError as e: | 53 | except subprocess.CalledProcessError as e: |
| 54 | print(f'aborting: {e}', file=sys.stderr) | 54 | print(f"aborting: {e}", file=sys.stderr) |
| 55 | sys.exit(1) | 55 | sys.exit(1) |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | def import_release_key(opts): | 58 | def import_release_key(opts): |
| 59 | """Import the public key of the official release repo signing key.""" | 59 | """Import the public key of the official release repo signing key.""" |
| 60 | # Extract the key from our repo launcher. | 60 | # Extract the key from our repo launcher. |
| 61 | launcher = getattr(opts, 'launcher', os.path.join(TOPDIR, 'repo')) | 61 | launcher = getattr(opts, "launcher", os.path.join(TOPDIR, "repo")) |
| 62 | print(f'Importing keys from "{launcher}" launcher script') | 62 | print(f'Importing keys from "{launcher}" launcher script') |
| 63 | with open(launcher, encoding='utf-8') as fp: | 63 | with open(launcher, encoding="utf-8") as fp: |
| 64 | data = fp.read() | 64 | data = fp.read() |
| 65 | 65 | ||
| 66 | keys = re.findall( | 66 | keys = re.findall( |
| 67 | r'\n-----BEGIN PGP PUBLIC KEY BLOCK-----\n[^-]*' | 67 | r"\n-----BEGIN PGP PUBLIC KEY BLOCK-----\n[^-]*" |
| 68 | r'\n-----END PGP PUBLIC KEY BLOCK-----\n', data, flags=re.M) | 68 | r"\n-----END PGP PUBLIC KEY BLOCK-----\n", |
| 69 | run(opts, ['gpg', '--import'], input='\n'.join(keys).encode('utf-8')) | 69 | data, |
| 70 | 70 | flags=re.M, | |
| 71 | print('Marking keys as fully trusted') | 71 | ) |
| 72 | run(opts, ['gpg', '--import-ownertrust'], | 72 | run(opts, ["gpg", "--import"], input="\n".join(keys).encode("utf-8")) |
| 73 | input=f'{KEYID_DSA}:6:\n'.encode('utf-8')) | 73 | |
| 74 | print("Marking keys as fully trusted") | ||
| 75 | run( | ||
| 76 | opts, | ||
| 77 | ["gpg", "--import-ownertrust"], | ||
| 78 | input=f"{KEYID_DSA}:6:\n".encode("utf-8"), | ||
| 79 | ) | ||
