-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathSDAHelper.py
More file actions
40 lines (31 loc) · 1.63 KB
/
SDAHelper.py
File metadata and controls
40 lines (31 loc) · 1.63 KB
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
import os
import uuid
from pathlib import Path
from . import storage
storage_client = storage.storage.get_instance()
SHP_SUFFIX = [".shp", ".shx", ".dbf", ".prj"]
def download_file(benchmark_bucket, path_in_bucket, dest_dir):
path = Path(dest_dir) / Path(path_in_bucket).name
storage_client.download(benchmark_bucket, path_in_bucket, path)
return path
def download_file_bucket(benchmark_bucket, bucket, basename, dest_dir):
return download_file(benchmark_bucket, bucket + '/' + basename, dest_dir)
def download_shp_file(benchmark_bucket, bucket ,shp_file, dest_dir):
files = [Path(shp_file).with_suffix(suffix) for suffix in filter(lambda x: x is not ".shp",SHP_SUFFIX)]
for f in files:
download_file_bucket(benchmark_bucket, bucket, f.name, dest_dir)
return download_file_bucket(benchmark_bucket, bucket, shp_file, dest_dir)
def load_config(event,directory):
return download_file_bucket(event["benchmark_bucket"], event["input_bucket"], event["config_file"], directory)
def upload_shp_file(benchmark_bucket, bucket, shp_basename):
shp_dir = Path(shp_basename).parent
for f in shp_dir.iterdir():
if Path(shp_basename).stem == Path(f).stem and any(f.name.endswith(suffix) for suffix in SHP_SUFFIX):
full_path = shp_dir / f.name
storage_client.upload(benchmark_bucket, bucket + '/' + f.name, full_path,False)
def download_directory(benchmark_bucket, bucket, dest_dir):
storage_client.download_directory(benchmark_bucket, bucket, dest_dir)
def create_tmp_dir():
tmp_dir = os.path.join("/tmp",str(uuid.uuid4()))
os.makedirs(tmp_dir, exist_ok=True)
return tmp_dir