-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.py
executable file
·61 lines (49 loc) · 1.91 KB
/
archive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
"""Create tgz archives for the given folders, possibly limiting data to that of
only one or more stages.
"""
import os
import sys
import click
ALLOWED_STAGE_VALUES = ['1', '2', '3', '4', '4_1freq', 'prop', 'prop_1freq',
'prop_rho', 'prop_rho_larger']
def validate_stage(ctx, param, values):
stage_names = []
for value in values:
if value not in ALLOWED_STAGE_VALUES:
raise click.BadParameter('Allowed values are: %s'
% str(ALLOWED_STAGE_VALUES))
if value.startswith('prop'):
stage_names.append('stage_'+value)
else:
stage_names.append('stage'+value)
return stage_names
@click.command(help=__doc__)
@click.help_option('--help', '-h')
@click.option('--stage', help="Include data for the given stage in the "
"output. May be given multiple times. If not given at all, include "
"all data. Allowed values are %s"%str(ALLOWED_STAGE_VALUES),
metavar='STAGE', multiple=True, callback=validate_stage)
@click.option('--dry-run', '-n', is_flag=True, help="Perform a dry run")
@click.argument('folders', nargs=-1, type=click.Path(exists=True))
def archive(folders, stage, dry_run):
if len(stage) == 0:
exclude = set([])
else:
exclude = set(['stage1', 'stage2', 'stage3', 'stage4', 'stage4_1freq',
'stage_prop', 'stage_prop_1freq', 'stage_prop_rho',
'stage_prop_rho_larger'])
for stage_name in stage:
exclude.remove(stage_name)
for folder in folders:
outfile = folder
for s in stage:
outfile += '_%s' % s
outfile += '.tgz'
cmd = ('tar '+' '.join("--exclude=%s"%s for s in list(exclude))
+ " -c " + folder + " | gzip > " + outfile)
click.echo(cmd)
if not dry_run:
os.system(cmd)
if __name__ == "__main__":
sys.exit(archive())