blob: 3dafb48caf0458b50f97a32e98a38d881dc983fe [file] [log] [blame]
Austin Schuh085eab92020-11-26 13:54:51 -08001#!/usr/bin/python3
Parker Schuh5dbce222017-03-22 20:52:16 -07002
3# This file is run by shell scripts generated by the aos_vision_downloader Skylark
4# macro. Everything before the first -- is a hard-coded list of files to
5# download.
6
7from __future__ import print_function
8
9import sys
10import subprocess
11import re
12import os
13import os.path
14
15def RunAndSplitShas(shcmd):
16 out = subprocess.check_output(shcmd)
17 return [line.split(' ')[0] for line in filter(lambda x: x, out.split('\n'))]
18
19def GetChecksums(fnames):
20 return RunAndSplitShas(["sha256sum"] + fnames)
21
22def GetJetsonChecksums(ssh_target, fnames):
23 target_files = ["/root/%s" % fname for fname in fnames]
24 subprocess.check_call(["ssh", ssh_target, "touch " + " ".join(target_files)])
25 cmds = ["ssh", ssh_target, "sha256sum " + " ".join(target_files)]
26 return RunAndSplitShas(cmds)
27
28def ToJetsonFname(fname):
29 if (fname[-9:] == ".stripped"):
30 fname = fname[:-9]
31 return os.path.basename(fname)
32
33def VerifyCheckSumsAndUpload(fnames, ssh_target):
34 jetson_fnames = [ToJetsonFname(fname) for fname in fnames]
35 checksums = GetChecksums(fnames)
36 jetson_checksums = GetJetsonChecksums(ssh_target, jetson_fnames)
Austin Schuh5ea48472021-02-02 20:46:41 -080037 for i in range(len(fnames)):
Parker Schuh5dbce222017-03-22 20:52:16 -070038 if (checksums[i] != jetson_checksums[i]):
39 # if empty, unlink
40 subprocess.check_call(["ssh", ssh_target, "unlink " + jetson_fnames[i]])
41 subprocess.check_call(["scp", fnames[i], ssh_target + ":" + jetson_fnames[i]])
42
43def main(argv):
44 args = argv[argv.index('--') + 1:]
45 files = argv[1:argv.index('--')]
46
47 VerifyCheckSumsAndUpload(files, args[-1])
48
49if __name__ == '__main__':
50 main(sys.argv)