Debian Codegraph @

infra/bots/assets/patch_linux_amd64/create.py

raw
1 #!/usr/bin/env python3
2 #
3 # Copyright 2024 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Create the asset."""
10
11
12 import argparse
13 import os
14 import subprocess
15 import tempfile
16
17
18 URL='https://ftp.debian.org/debian/pool/main/p/patch/patch_2.7.6-7_amd64.deb'
19 SHA256 = '8c6d49b771530dbe26d7bd060582dc7d2b4eeb603a20789debc1ef4bbbc4ef67'
20
21
22 def create_asset(target_dir):
23 """Create the asset."""
24 tmp = tempfile.mkdtemp()
25 target_file = os.path.join(tmp, 'patch.deb')
26 subprocess.call(['wget', '--quiet', '--output-document', target_file, URL])
27 output = subprocess.check_output(['sha256sum', target_file], encoding='utf-8')
28 actual_hash = output.split(' ')[0]
29 if actual_hash != SHA256:
30 raise Exception('SHA256 does not match (%s != %s)' % (actual_hash, SHA256))
31 subprocess.check_call(['dpkg-deb', '-x', target_file, tmp])
32 subprocess.check_call(['cp', tmp + '/usr/bin/patch', target_dir])
33 subprocess.check_call(['rm', '-rf', tmp])
34
35
36 def main():
37 parser = argparse.ArgumentParser()
38 parser.add_argument('--target_dir', '-t', required=True)
39 args = parser.parse_args()
40 create_asset(args.target_dir)
41
42
43 if __name__ == '__main__':
44 main()
45