Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 1 | # This file is run by shell scripts generated by the aos_downloader Skylark |
| 2 | # macro. Everything before the first -- is a hard-coded list of files to |
| 3 | # download. |
| 4 | |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 5 | from __future__ import print_function |
| 6 | |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 7 | import sys |
| 8 | import subprocess |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 9 | import re |
| 10 | import os |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 11 | |
| 12 | def main(argv): |
Austin Schuh | 46ecbf7 | 2015-10-15 00:02:40 -0700 | [diff] [blame] | 13 | srcs = argv[1:argv.index('--')] |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 14 | args = argv[argv.index('--') + 1:] |
| 15 | |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 16 | ROBORIO_TARGET_DIR = '/home/admin/robot_code' |
| 17 | ROBORIO_USER = 'admin' |
| 18 | |
| 19 | target_dir = ROBORIO_TARGET_DIR |
| 20 | user = ROBORIO_USER |
| 21 | destination = args[-1] |
| 22 | |
| 23 | result = re.match('(?:([^:@]+)@)?([^:@]+)(?::([^:@]+))?', destination) |
| 24 | if not result: |
| 25 | print('Not sure how to parse destination "%s"!' % destination, |
| 26 | file=sys.stderr) |
| 27 | return 1 |
| 28 | if result.group(1): |
| 29 | user = result.group(1) |
| 30 | hostname = result.group(2) |
| 31 | if result.group(3): |
| 32 | target_dir = result.group(3) |
| 33 | |
| 34 | ssh_target = '%s@%s' % (user, hostname) |
| 35 | |
| 36 | subprocess.check_call( |
Austin Schuh | 1e4eea2 | 2015-11-08 12:50:05 -0800 | [diff] [blame] | 37 | ['rsync', '-c', '-v', '-z', '--copy-links'] + srcs + |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 38 | ['%s:%s' % (ssh_target, target_dir)]) |
| 39 | subprocess.check_call( |
| 40 | ('ssh', ssh_target, '&&'.join([ |
| 41 | 'chmod u+s %s/starter_exe' % target_dir, |
| 42 | 'echo \'Done moving new executables into place\'', |
| 43 | 'bash -c \'sync && sync && sync\'', |
| 44 | ]))) |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 45 | |
| 46 | if __name__ == '__main__': |
| 47 | main(sys.argv) |