-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws.py
More file actions
98 lines (87 loc) · 3.32 KB
/
aws.py
File metadata and controls
98 lines (87 loc) · 3.32 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
#
# Library: buzzbackend
#
# Copyright 2013 Siramix Labs
#
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 ( the "License" );
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###############################################################################
from boto.s3.key import Key
from boto.s3.connection import S3Connection
import json
# S3 bucket we're using
BUCKET_NAME = 'siramix.buzzwords'
PACKDATA_DIR = 'bw-packdata-test'
def get_packs_key():
"""Get the json index from aws.
"""
conn = S3Connection()
bucket = conn.get_bucket(BUCKET_NAME)
return bucket.get_key('%s/packs.json' % PACKDATA_DIR)
def upload_file(path, contents):
"""Upload a file to S3 given the name and contents.
"""
conn = S3Connection()
bucket = conn.get_bucket(BUCKET_NAME)
file_key = Key(bucket)
file_key.key = path
file_key.set_contents_from_string(contents)
return file_key
def upload_pack(name, filename, contents):
"""Upload the pack and update the index.
"""
packs_key = get_packs_key()
packs_contents = packs_key.get_contents_as_string()
pack_found = False
for line in packs_contents.split('\n'):
if (line.strip() != ''):
cur_pack = json.loads(line)
if cur_pack['path'] == 'packs/%s.json' % filename:
pack_found = True
print "Pack already exists. Make sure version and " \
"other meta data is updated if making an update."
if not pack_found:
print "Pack does not exist. Adding new pack to packs.json."
# EDIT THIS SECTION HERE FOR EACH NEW PACK!
new_pack = {"_id": 150,
"name": name,
"path": "packs/" + filename + ".json",
"icon_path": "packs/icons/packicon_christmas.png",
"description": "A wintry mix of words that your friends and family can enjoy during the holidays.",
"size": 150,
"purchase_type": 1,
"version": 1,
"action_string": "BUY"}
packs_contents += '\n' + json.dumps(new_pack)
print "Pack index added: %s" % json.dumps(new_pack)
packs_path = '%s/packs.json' % (PACKDATA_DIR)
packs_key = upload_file(packs_path, packs_contents)
packs_key.set_acl('public-read')
print "Pack index file pushed to %s." % packs_path
carddata_path = '%s/packs/%s.json' % (PACKDATA_DIR, filename)
carddata_key = upload_file(carddata_path, contents)
carddata_key.set_acl('public-read')
print "Pack file pushed to %s." % (carddata_path)
def delete_logs():
"""Delete log files from S3.
"""
conn = S3Connection()
bucket = conn.get_bucket(BUCKET_NAME)
for key in bucket.list():
if 'bw' not in key.name:
key.delete()