Factor perform_sync() back into sync command code.
Chris Pressey
2 years ago
11 | 11 | if not dirname.endswith('/'): |
12 | 12 | dirname += '/' |
13 | 13 | return dirname |
14 | ||
15 | ||
16 | def perform_sync(from_dir, to_dir, dry_run=True, checksum=False): | |
17 | for d in (from_dir, to_dir): | |
18 | if not os.path.isdir(d): | |
19 | raise ValueError("Directory '{}' is not present".format(d)) | |
20 | dry_run_option = '--dry-run ' if dry_run else '' | |
21 | checksum_option = '--checksum ' if checksum else '' | |
22 | cmd = 'rsync {}{}--archive --verbose --delete "{}" "{}"'.format(dry_run_option, checksum_option, from_dir, to_dir) | |
23 | run_command(cmd) | |
24 | if not dry_run: | |
25 | run_command('sync') | |
26 | 14 | |
27 | 15 | |
28 | 16 | def run_command(cmd): |
68 | 56 | from_dir = clean_dir(from_dir) |
69 | 57 | to_dir = clean_dir(to_dir) |
70 | 58 | |
71 | perform_sync(from_dir, to_dir, dry_run=(not options.apply), checksum=(options.thorough)) | |
59 | for d in (from_dir, to_dir): | |
60 | if not os.path.isdir(d): | |
61 | raise ValueError("Directory '{}' is not present".format(d)) | |
62 | ||
63 | dry_run = not options.apply | |
64 | dry_run_option = '--dry-run ' if dry_run else '' | |
65 | checksum_option = '--checksum ' if options.thorough else '' | |
66 | cmd = 'rsync {}{}--archive --verbose --delete "{}" "{}"'.format(dry_run_option, checksum_option, from_dir, to_dir) | |
67 | run_command(cmd) | |
68 | if not dry_run: | |
69 | run_command('sync') | |
72 | 70 | |
73 | 71 | |
74 | 72 | def rename(router, options): |