-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathinit.py
executable file
·66 lines (48 loc) · 1.52 KB
/
init.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
62
63
64
65
66
#!/usr/bin/env python3
'''
create a new directory structure and template for given city
'''
import argparse
import os
import sys
from shutil import copyfile
from utils import chdir_to_opp_root, make_dir
def init(args):
chdir_to_opp_root()
state = args.state.lower()
city = '_'.join([x.lower().replace(' ', '_') for x in args.city])
make_data_dirs(state, city)
make_lib_dirs(state)
copy_template(args.template, state, city)
return
def make_data_dirs(state, city):
parent_dir = os.path.join('data', 'states', state, city)
sub_dirs = [
'raw',
'raw_csv',
'clean',
'calculated_features',
'shapefiles'
]
for sub_dir in sub_dirs:
make_dir(os.path.join(parent_dir, sub_dir))
return
def make_lib_dirs(state):
make_dir(os.path.join('lib', 'states', state))
return
def copy_template(template_path, state, city):
dst = os.path.join('lib', 'states', state, city + '.R')
if not os.path.exists(dst):
copyfile(template_path, dst)
return
def parse_args(argv):
desc = 'initializes the data and lib directories for a new city'
default_template = 'lib/template.R'
parser = argparse.ArgumentParser(prog=argv[0], description=desc)
parser.add_argument('state')
parser.add_argument('city', nargs='+')
parser.add_argument('-template', default=default_template,
help='default: ' + default_template)
return parser.parse_args(argv[1:])
if __name__ == '__main__':
init(parse_args(sys.argv))