forked from migurski/Extractotron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-files.sh
executable file
·31 lines (23 loc) · 960 Bytes
/
upload-files.sh
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
#!/bin/sh -ex
# EC2 will tell us our own instance ID, use that to turn ourselves off.
python <<SEND
from os import stat
from glob import glob
from sys import stderr
from os.path import basename
from boto.s3.connection import S3Connection
from boto.s3.bucket import Bucket
types = dict(bz2='application/x-bzip2', pbf='application/octet-stream', zip='application/zip')
bucket = Bucket(S3Connection('$KEY', '$SECRET'), '$BUCKET')
log = open('log.txt', 'a')
for file in sorted(glob('ex/*.osm.???') + glob('ex/*.zip')) + sorted(glob('ex/*.tar.bz2')):
name = basename(file)
type = types[name[-3:]]
key = bucket.new_key(name)
key.set_contents_from_file(open(file), policy='public-read', headers={'Content-Type': type})
print >> stderr, file
print >> log, name, stat(file).st_size
log.close()
key = bucket.new_key('log.txt')
key.set_contents_from_file(open('log.txt'), policy='public-read', headers={'Content-Type': 'text/plain'})
SEND