Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 66 lines (50 sloc) 1.789 kb
d0ceec2 Added script to update list of available states with data on S3.
cgroskopf authored
1 #!/usr/bin/env python
2
3 import json
4 import sys
5
6 from boto.exception import S3ResponseError
7 from boto.s3.connection import S3Connection
8 from boto.s3.key import Key
9
10 import config
b2f39a7 Factor gzipping code.
cgroskopf authored
11 import utils
d0ceec2 Added script to update list of available states with data on S3.
cgroskopf authored
12
7095948 @JoeGermuska add 'remove'
JoeGermuska authored
13 def update_state_list(environment, state, clear=False, remove=False):
d85fab2 Updated batch scripts so state is marked available when it is made pu…
cgroskopf authored
14 c = S3Connection()
15 bucket = c.get_bucket(config.S3_BUCKETS[environment])
16
17 k = Key(bucket)
18 k.key = 'states.jsonp'
19
20 try:
21 data = k.get_contents_as_string()
22
23 # No existing file
24 if not data:
25 raise S3ResponseError()
26
27 # Strip off jsonp wrapper
28 contents = utils.gunzip_data(data)
29 data = contents[7:-1]
30
31 states = json.loads(data)
32 except S3ResponseError:
33 states = []
7095948 @JoeGermuska add 'remove'
JoeGermuska authored
34 if remove:
35 states.remove(state)
36 print 'Removed %s from list of available states' % state
a3843e5 @JoeGermuska whoops, elif not else
JoeGermuska authored
37 elif clear:
d85fab2 Updated batch scripts so state is marked available when it is made pu…
cgroskopf authored
38 states = [state]
7095948 @JoeGermuska add 'remove'
JoeGermuska authored
39 print 'Reset list of available states and added %s' % state
d85fab2 Updated batch scripts so state is marked available when it is made pu…
cgroskopf authored
40 else:
41 if state not in states:
42 states.append(state)
43
44 print '%s added to available state list' % state
45 else:
46 print '%s is already available' % state
7095948 @JoeGermuska add 'remove'
JoeGermuska authored
47
48 states.sort()
d85fab2 Updated batch scripts so state is marked available when it is made pu…
cgroskopf authored
49 jsonp = 'states(%s)' % json.dumps(states)
50 compressed = utils.gzip_data(jsonp)
51
52 k.set_contents_from_string(compressed, headers={ 'Content-encoding': 'gzip', 'Content-Type': 'application/json' }, policy='public-read')
53
54 if __name__ == '__main__':
55 if len(sys.argv) < 3:
56 sys.exit('You must specify either "staging" or "production" and a state as arguments to this script.')
57
58 ENVIRONMENT = sys.argv[1]
59 STATE = sys.argv[2]
60 try:
7095948 @JoeGermuska add 'remove'
JoeGermuska authored
61 OPERATION = sys.argv[3]
d85fab2 Updated batch scripts so state is marked available when it is made pu…
cgroskopf authored
62 except:
7095948 @JoeGermuska add 'remove'
JoeGermuska authored
63 OPERATION = None
d85fab2 Updated batch scripts so state is marked available when it is made pu…
cgroskopf authored
64
7095948 @JoeGermuska add 'remove'
JoeGermuska authored
65 update_state_list(ENVIRONMENT, STATE, (OPERATION == 'CLEAR'), (OPERATION == 'REMOVE'))
Something went wrong with that request. Please try again.