-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_cli.py
61 lines (49 loc) · 1.87 KB
/
_cli.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
import os
import json
import subprocess
import click
from lambda_db.db import Database
from analyze import choose_res
@click.group()
def lambda_db():
pass
@lambda_db.command(name="build")
@click.argument('feature_collection', type=click.File('r'))
@click.option('--include-geometry/--no-geometry', default=False)
def build(feature_collection, include_geometry):
data = json.load(feature_collection)
# Move geometry to data
if include_geometry:
for feat in data['features']:
feat['properties'].update({'geometry': feat['geometry']})
with Database.load() as db:
db.load_features(data)
@lambda_db.command(name="deploy")
@click.option('tag', '-t', type=str)
@click.option('--public/--not-public', default=False)
@click.option('--dry-run/--wet-run', default=False)
def deploy(tag, public, dry_run):
# Build lambda layer with docker
os.chdir(os.path.dirname(__file__))
print("Building docker image")
subprocess.call('docker build . -t {}'.format(tag), shell=True)
print("Building lambda layer deployment package")
subprocess.call('docker run --rm -v $PWD:/home/spatial-db -it {} package.sh'.format(tag), shell=True)
if not dry_run:
with Database.load() as db:
# Publish lambda layer
print("Publishing lambda layer to AWS")
db.publish_lambda_layer(public=public)
print(json.dumps(db.info(), indent=2))
else:
print("dry-run flag is enabled, layer has not been published to AWS")
@lambda_db.command(name="analyze")
@click.argument('feature_collection', type=click.File('r'))
@click.option('--optimize', '-o', default='size', type=str)
def analyze(feature_collection, optimize):
data = json.load(feature_collection)
choose_res(data, optimize)
@lambda_db.command(name="info")
def info():
with Database.load() as db:
print(json.dumps(db.info(), indent=2))