-
Notifications
You must be signed in to change notification settings - Fork 23
/
admin.py
60 lines (48 loc) · 2 KB
/
admin.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
# Global Forest Watch API
# Copyright (C) 2013 World Resource Institute
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import time
import webapp2
from gfw import common
import cloudstorage as gcs
DEV_BUCKET = '/gfw-apis-country'
my_default_retry_params = gcs.RetryParams(initial_delay=0.2,
max_delay=5.0,
backoff_factor=2,
max_retry_period=15)
gcs.set_default_retry_params(my_default_retry_params)
class BootstrapGcs(webapp2.RequestHandler):
def get(self):
"""Bootstraps local GCS with test data dwc files in dwc."""
for filename in os.listdir('gcs'):
content_type = common.CONTENT_TYPES[filename.split('.')[1]]
path = os.path.abspath('gcs/%s' % filename)
gcs_path = '%s/%s' % (DEV_BUCKET, filename)
data = open(path, 'r').read()
gcs_file = gcs.open(
gcs_path,
'w',
content_type=content_type,
options={})
gcs_file.write(data)
gcs_file.close()
time.sleep(5)
self.redirect('http://localhost:8000/blobstore')
routes = [
webapp2.Route(r'/admin/bootstrap-gcs', handler='admin.BootstrapGcs:get'),
]
handlers = webapp2.WSGIApplication(routes, debug=True)